function getTopPhone(id, position) {

    $('.sel').removeClass('sel');
    $('.sel_position').addClass('position');
    $('.sel_position').removeClass('sel_position');
    
    $('#topthmb_'+id).addClass('sel');
    $('#topthmb_'+id+' > span').removeClass('position');
    $('#topthmb_'+id+' > span').addClass('sel_position');
    
    $("#firsttopphone").fadeOut('slow', function(){
        //showAjaxLoading("#firsttopphone");
    });
    
    (new TopPhones_ActionHandler).getTopPhone(
        {   id : id,
            pos: position
         },
        function(result) {
            //hideAjaxLoading();
            $("#firsttopphone").html(result);
            jsdiv = document.getElementById('jsscripttag');
            if (jsdiv) {
                eval(jsdiv.innerHTML);
            }
            $("#firsttopphone").fadeIn('slow');
        }
    );
}

function getOtherTopPhones(id, old_id, dir) {
    
    if (dir != -1 && dir != 1) dir = 1; 
    
    //$("#otherphones").fadeOut('slow', function(){
    //    showAjaxLoading("#otherphones");
    //});
    if (dir == -1) {
        $("#otherphones").SlideOutLeft(500, function () {
         //showAjaxLoading("#otherphones");
        });
    } else {
        $("#otherphones").SlideOutRight(500, function () {
         //showAjaxLoading("#otherphones");
        });
    }

    (new TopPhones_ActionHandler).getOtherTopPhones(
        {   id : id,
            old_id : old_id, 
            dir : dir
         },
        function(result) {
            //hideAjaxLoading();
            $("#otherphones").hide();
            $("#otherphones").html(result);
            jsdiv = document.getElementById('jsscripttag');
            if (jsdiv) {
                eval(jsdiv.innerHTML);
            }
            //$("#otherphones").fadeIn('slow');
            if (dir == -1) {
                $("#otherphones").SlideInRight(500);
            } else {
                $("#otherphones").SlideInLeft(500);
            }
        }
    );    
}


function getManufacturerPhone(id, position) {

    $('.sel').removeClass('sel');
    $('.sel_position').addClass('position');
    $('.sel_position').removeClass('sel_position');
    
    $('#topthmb_'+id).addClass('sel');
    $('#topthmb_'+id+' > span').removeClass('position');
    $('#topthmb_'+id+' > span').addClass('sel_position');
    
    $("#firsttopphone").fadeOut('slow', function(){
        //showAjaxLoading("#firsttopphone");
    });
        
    (new Manufacturers_ActionHandler).getTopPhone(
        {   id : id,
            pos: position
         },
        function(result) {
            //hideAjaxLoading();
            $("#firsttopphone").html(result);
            jsdiv = document.getElementById('jsscripttag');
            if (jsdiv) {
                eval(jsdiv.innerHTML);
            }            
            $("#firsttopphone").fadeIn('slow');
        }
    );
}

function getManufacturerOtherPhones(id, cat_id, old_id, dir) {
    
    if (dir != -1 && dir != 1) dir = 1; 
    
    if (dir == -1) {
        $("#otherphones").SlideOutLeft(500, function () {
         //showAjaxLoading("#otherphones");
        });
    } else {
        $("#otherphones").SlideOutRight(500, function () {
         //showAjaxLoading("#otherphones");
        });
    }
    
    (new Manufacturers_ActionHandler).getOtherPhones(
        {   id : id,
            cat_id: cat_id,
            old_id: old_id,
            dir : dir
         },
        function(result) {
            //hideAjaxLoading();
            $("#otherphones").hide();
            $("#otherphones").html(result);
            jsdiv = document.getElementById('jsscripttag');
            if (jsdiv) {
                eval(jsdiv.innerHTML);
            }
            if (dir == -1) {
                $("#otherphones").SlideInRight(500);
            } else {
                $("#otherphones").SlideInLeft(500);
            }
        }
    );    
}

function getProviderPhone(provider, id, position) {

    $('.sel').removeClass('sel');
    $('.sel_position').addClass('position');
    $('.sel_position').removeClass('sel_position');
    
    $('#topthmb_'+id).addClass('sel');
    $('#topthmb_'+id+' > span').removeClass('position');
    $('#topthmb_'+id+' > span').addClass('sel_position');
    
    $("#firsttopphone").fadeOut('slow', function(){
        //showAjaxLoading("#firsttopphone");
    });
    
    (new Providers_ActionHandler).getTopPhone(
        {   id : id,
            provider_id : provider,
            pos: position
         },
        function(result) {
            //hideAjaxLoading();
            $("#firsttopphone").html(result);
            jsdiv = document.getElementById('jsscripttag');
            if (jsdiv) {
                eval(jsdiv.innerHTML);
            }
            $("#firsttopphone").fadeIn('slow');
        }
    );
}

function getProviderOtherPhones(id, cat_id, old_id, dir) {
    
    if (dir != -1 && dir != 1) dir = 1; 
    
    if (dir == -1) {
        $("#otherphones").SlideOutLeft(500, function () {
         //showAjaxLoading("#otherphones");
        });
    } else {
        $("#otherphones").SlideOutRight(500, function () {
         //showAjaxLoading("#otherphones");
        });
    }

    (new Providers_ActionHandler).getOtherPhones(
        {   id : id,
            cat_id: cat_id,
            old_id: old_id,
            dir : dir
         },
        function(result) {
            //hideAjaxLoading();
            $("#otherphones").hide();
            $("#otherphones").html(result);
            jsdiv = document.getElementById('jsscripttag');
            if (jsdiv) {
                eval(jsdiv.innerHTML);
            }
            if (dir == -1) {
                $("#otherphones").SlideInRight(500);
            } else {
                $("#otherphones").SlideInLeft(500);
            }
        }
    );
}

function showAjaxLoading(id) {    
    var img_node = $.create("img", { "src" : "http://s1.phonearena.com/img/ajax_loading2.gif", 'style':'display:none; padding-left:20px;', 'id' : 'ajax-loading' }, []);
    $(id).before(img_node);
    $("#ajax-loading").show();
}

function hideAjaxLoading() {
    $('#ajax-loading').remove();
}