$(document).ready(function(){

//==Lightbox===============================================
    function change_href(){
        var a_num = $(".photolist .itemlist").find("a").length;
        for(i=0;i<a_num;i++)
        {
            var url = $(".photolist .itemlist a:eq("+i+") span").attr("style");
            var start = url.indexOf("http");
            var end = url.indexOf("s.jpg");
            var src = url.substring(start,end)+"b.jpg";
            $(".photolist .itemlist a:eq("+i+")").attr("href",src);
        }
    }

    $(".photolist .itemlist a span").click(function(){
        change_href();
    });
    $(".photolist .itemlist a").lightBox();
    //=================================================

    if ($('#content2replace').length && $('#description').length){
        $('#content2replace').html($('#description').html());
        $('#description').remove();
    }

    //Банер картки лояльності
    var width = document.body.clientWidth;
    var height = document.body.clientHeight;
    if ($.browser.msie && $.browser.version > 6) {
        var leftside = 750;
        var topsize = 343;
    }

    else if ($.browser.opera) {
        var leftside = 750;
        var topsize = 345;
    }
    else if ($.browser.mozilla) {
        var leftside = 750;
        var topsize = 345;
    }
    else {
        var leftside = 750;
        var topsize = 345;
    }

    $("#baner").animate({
        width: "200px",
        height: "230px",
        left: leftside ,
        top: topsize
    },0);
    $("#close_btn").click(function(){
        $("#baner").remove();
    });
    //Кінець банеру
    //
    //ліве меню

    var current_pos_id = 1;
    var horlinks = $("#left_menu .horlinks");
    var cars_num = $("#left_menu div.horlinks a").length-3;
    function only_one_visible(id){
        $("#left_menu div.horlinks a:not(:eq("+id+"))").animate({
            'height':'83px'
        },"slow");
        $("#left_menu div.horlinks a:not(:eq("+id+")) img").animate({
            'height':'90%',
            'width':'50%'
        },"slow");
        $("#left_menu div.horlinks a:eq("+id+")").animate({
            'height':'145px'
        },"slow");
        $("#left_menu div.horlinks a:eq("+id+") img").animate({
            'height':'100%',
            'width':'200px'
        },"slow");
    }
    only_one_visible(current_pos_id);

    $("a.next").click(function(){
        $("#left_menu div.horlinks a:first").animate({
            'height':'0px'
        },"slow",function(){
            $("#left_menu div.horlinks a:first").clone().insertAfter("#left_menu div.horlinks a:last");
            $("#left_menu div.horlinks a img").css('border','none');
            $("#left_menu div.horlinks a:first").remove();
        });
        current_pos_id =2;
        only_one_visible(current_pos_id);
    });

    $("a.prev").click(function(){
        $("#left_menu div.horlinks a:last").clone().insertBefore("#left_menu div.horlinks a:first");
        $("#left_menu div.horlinks a img").css('border','none');
        $("#left_menu div.horlinks a:first").css({
            'height':'0px'
        });
        $("#left_menu div.horlinks a:first").animate({
            'height':'83px'
        },"slow");
        $("#left_menu div.horlinks a:last").remove();
        current_pos_id =1;
        only_one_visible(current_pos_id);
    });
});
