// Placeholder Plugin
jQuery.fn.extend({
    placeHolder : function() {
        elem = this;
        elem.focus(function(){
            if (jQuery(elem).attr("value") == jQuery(elem).attr("title")){
                jQuery(elem).attr("value", "")
            }
        });
        elem.blur(function(){
            if (jQuery(elem).attr("value") == ""){
                jQuery(elem).attr("value", jQuery(elem).attr("title"))
            }
        });
        elem.parents('form').submit(function(){
            if (jQuery(elem).attr("value") == jQuery(elem).attr("title")){
                jQuery(elem).attr("value", "")
            }
        });
    }
});


$(document).ready(function() {


    //
    
    
    //форма заявки на обучение
    $("#applicat").validity(function(){
        $("#region").require("Заполните поле 'Регион, адрес'");
        $("#capcha").require("Заполните поле кода");
    });
    
    /*форма логина*/
    $("#login_form").validity(function(){
        $("#login").require("Заполните поле 'Логин'");
        $("#password").require("Заполните поле 'Пароль'");
    });
    
    /*форма рассылки*/
    $("#mailing_form").validity(function(){
        $("#mail").require("Укажите Ваш электронный адрес").match("email", "Некорректный электронный адрес");
    });
    
    /*форма регистрации физ. лиц*/
    $("#reg_form").validity(function(){
        $("#login").require("Заполните поле 'Логин'");
        $("#password").require("Заполните поле 'Пароль'");
        $("#password_repeat").require("Заполните поле 'Пароль (повтор)'");
        $("#name").require("Заполните поле 'Ваше имя'");
        $("#phone").require("Заполните поле 'Телефон'");
        $("#mail").require("Заполните поле 'Электронный адрес'").match("email", "Некорректный электронный адрес");
        $("#capcha").require("Заполните поле кода");
    });
    
    /*форма юр. лиц*/
    $("#reg_form_2").validity(function(){
        
         $("#login").require("Заполните поле 'Логин'");
         $("#password").require("Заполните поле 'Пароль'");
         $("#password_repeat").require("Повторите ввод пароля");
        
        $("#mail").require("Заполните поле 'Электронный адрес'").match("email", "Некорректный электронный адрес");
        $("#name").require("Заполните поле 'Ваше имя'");
        $("#phone").require("Заполните поле 'Телефон'");
        $("#company").require("Заполните поле 'Название компании'");
        $("#work_position").require("Заполните поле 'Должность'");
        $("#work_desc").require("Заполните поле 'Описание деятельности'");
        $("#city").require("Заполните поле 'Регион/город'");
        $("#capcha").require("Заполните поле кода");
    });
    
    /*форма изменения данных физ. лиц*/
    $("#data_change").validity(function(){
        $("#capcha").require("Заполните поле кода");
    });
    
    /*форма изменения данных юр. лиц*/
    $("#data_change_2").validity(function(){
        $("#capcha").require("Заполните поле кода");
    });
    
    /*форма напоминания пароля*/
    $("#reminder_form").validity(function(){
        $("#mail").require("Заполните поле 'Электронный адрес'").match("email", "Некорректный электронный адрес");
    });
    
    /*форма обратной связи*/
    $("#feedback_form").validity(function(){
        $("#mail").require("Заполните поле 'E-mail'").match("email", "Некорректный электронный адрес");
        $("#name").require("Заполните поле 'Ваше имя'");
        if($("#select").val() == ''){                
            $("#select").require("Выберите отдел");
        }
        $("#phone").require("Заполните поле 'Телефон'");
        $("#message").require("Заполните поле 'Интересующий Вас вопрос'");
        $("#city").require("Заполните поле 'Регион/город'");
        $("#capcha").require("Заполните поле кода");
    });
    
    /*форма заказа звонка*/
    $("#feedback_form_2").validity(function(){
        $("#mail").require("Заполните поле 'E-mail'").match("email", "Некорректный электронный адрес");
        $("#name").require("Заполните поле 'Ваше имя'");
        $("#phone").require("Заполните поле 'Телефон'");
        $("#message").require("Заполните поле 'Интересующий Вас вопрос'");
        $("#city").require("Заполните поле 'Регион/город'");
        $("#capcha").require("Заполните поле кода");
    });
    
    /*форма добавления магазина*/
    $("#add_store").validity(function(){
        $("#name").require("Заполните поле 'Название магазина'");
        $("#phone").require("Заполните поле 'Телефон'");
        $("#addres").require("Заполните поле 'Адрес'");
        $("#capcha").require("Заполните поле кода");
    });
    
    /*форма заказа банера*/
    $("#baner_order").validity(function(){
/*$("input:radio").require("Выберите вид банера");
        $("#size").require("Заполните поле 'Размер банера'");
        $("#period").require("Заполните поле 'Срок размещения'");
        $("#site").require("Заполните поле 'Адрес сайта'");
$("#mail").require("Заполните поле 'E-mail'").match("email", "Некорректный электронный адрес");*/
        $("#capcha").require("Заполните поле кода");
    });
    
    /*форма добавления комментария*/
    $("#comment_form").validity(function(){
        $("#mail").require("Заполните поле 'E-mail'").match("email", "Некорректный электронный адрес");
        $("#author").require("Заполните поле 'Автор'");
        $("#comment").require("Заполните поле 'Текст комментария'");
        $("#capcha").require("Заполните поле кода");
    });
    
    
    /*форма заказа*/
    
    $(".ord_btn").click(function(){
        $("#ord_form").validity(function(){
            $("#mail").require("Заполните поле 'E-mail'").match("email", "Некорректный электронный адрес");
            $("#name").require("Заполните поле 'Ваше имя'");
            $("#phone").require("Заполните поле 'Телефон'");
            if($("#oplata").val() == ''){
                $("#oplata").require("Выберите способ оплаты");
            }            
            $("#capcha").require("Заполните поле кода");
        });
        //return false;
    });
    
    //заказ запасных частей
    $("#order_complekt").validity(function(){
        $("#artikul").require("Заполните поле 'Артикул'");
        $("#number").require("Заполните поле характеристик'");
        $("#count").require("Заполните поле 'Количество'");
        $("#name").require("Заполните поле 'Ваше имя'");
        $("#company").require("Заполните поле 'Название компании'");
        $("#city").require("Заполните поле 'Регион/город'");
        $("#mail").require("Заполните поле 'E-mail'").match("email", "Некорректный электронный адрес");
        $("#capcha").require("Заполните поле кода");
    });
    
    

//повтор заказа
function showResponse(responseText, statusText)  {
    window.location.href = '/vip_club/store_advertising/basket.php';
} 

$("#repeat-form").submit(function(){
    $("#repeat-basket").before('Пожалуйста, подождите...').remove();
    $.get('/cms/admin/basket.php?pl_plugin_order[2_27]=del_orders', function(data) {

        jQuery.ajaxSetup({beforeSend: function(request) {request.setRequestHeader( 'Cookie', document.cookie );},
            type: "POST",
            cache: false,
            url: "/cms/admin/basket.php",
            success: showResponse
        });

        $.ajax({data: $("#repeat-form").serializeArray()});
    });

return false;
});

    
    jQuery.fn.extend({
        disableSelection : function() {
            this.each(function() {
                            // Safari/Chrome/Konqueror/Opera/Mozilla/ie
                this.onselectstart = function() { return false; };
                this.unselectable = "on";
                jQuery(this).css('-moz-user-select', 'none');
                jQuery(this).css('-webkit-user-select', 'none');
                jQuery(this).css('-khtml-user-select', 'none');
            });
        }
    });
    $('#main-carousel').disableSelection();
    
    $('#similar-carousel').disableSelection();
    
    
    $("input#p_f_1_title-extra").placeHolder();
    $("input#p_f_1_title-extra").css({'color':'#828081','font-size':'11px'});
    if ($("input#p_f_1_title-extra").val() == ''){
        $("input#p_f_1_title-extra").val($("input#p_f_1_title-extra").attr("title"));
    }

if($(".lev").length == 0){$(".ban_left").remove();}

$("input#p_f_1_title").focus(function(){
if ($(this).attr("value") == $(this).attr("title")){
      $(this).attr("value", "");
$(this).css({'color':'#000','font-size':'12px'});
}
  });

  $("input#p_f_1_title").blur(function(){
if ($(this).attr("value") == ""){
      $(this).attr("value", $(this).attr("title"));
$(this).css({'color':'#828081','font-size':'11px'});
}
  });




$("input#art").focus(function(){
if ($(this).attr("value") == $(this).attr("title")){
      $(this).attr("value", "");
}
  });

  $("input#art").blur(function(){
if ($(this).attr("value") == ""){
      $(this).attr("value", $(this).attr("title"));
}
  });



//

$(".send-close").click(function(){
    $(".send-banner-wrap").remove();
    $.cookie('banner', 'false', { expires: 1 });
    return false;
});

if($.cookie('banner') == 'false'){
    $(".send-banner-wrap").remove();
}




$(".otkr, .otkr img").click(function(){
    $(".otkr").remove();
    $.cookie('otkr', 'false', { expires: 1 });
    return false;
});

if($.cookie('otkr') != 'false'){
    $(".otkr").show();
}

//$.cookie('banner', '', { expires: -1 }); // удалить cookie
    
    /*music*/
    
    
    //jQuery.cookie('status', $(".sound").attr('rel'));
    //alert(jQuery.cookie('status'));
    
    if(!jQuery.cookie('status') || jQuery.cookie('status') && jQuery.cookie('status') == '0'){
        if($(".sound").length){
            var sound = $(".sound").attr("href");
            $(".sound").removeClass('nosound');
            $(".sound").attr('rel', '0');
            flowplayer("player", "http://www.mw-light.ru/js/flowplayer-3.2.7.swf", {
                plugins:{
                    audio:{url: 'http://www.mw-light.ru/js/flowplayer.audio-3.2.2.swf'}
                },
                clip: {
                    url:sound,
                    autoPlay:true, 
                    autobuffering:true,
                    loop:true
                }
            });
        }
        
    }
    
    if(jQuery.cookie('status') && jQuery.cookie('status') == '1'){
        if($(".sound").length){
            var sound = $(".sound").attr("href");
            $(".sound").addClass('nosound');
            $(".sound").attr('rel', '1');
            flowplayer("player", "http://www.mw-light.ru/js/flowplayer-3.2.7.swf", {
                plugins:{
                    audio:{url: 'http://www.mw-light.ru/js/flowplayer.audio-3.2.2.swf'}
                },
                clip: {
                    url:sound,
                    autoPlay:false, 
                    autobuffering:false,
                    loop:true
                }
            });
        }
    }
    
    
    //экскурсия по шоу руму
    
    if($("#player_main").length){
            flowplayer("player_main", "http://www.mw-light.ru/js/flowplayer-3.2.7.swf", {
                plugins: {
                    controls: {
                        url: 'http://www.mw-light.ru/js/flowplayer.controls-3.2.5.swf',
                        time: true
                    }
                },
                clip: {
                    autoPlay:false, 
                    autobuffering:true
                }
            });
        }
   
    
    $(".sound").click(function(){
        //jQuery.cookie('status', $(".sound").attr('rel'));
        var status = $(this).attr('rel');
        
        if(status == '0'){
                $(this).attr('rel', '1');
                jQuery.cookie('status', '1', {path: "/"});
                $(this).addClass('nosound');
                $f(0).pause();
                //alert(jQuery.cookie('status'));
        }
        
        if(status == '1'){
                $(this).attr('rel', '0');
                jQuery.cookie('status', '0', {path: "/"});
                $(this).removeClass('nosound');
                $f(0).play();
                //alert(jQuery.cookie('status'));
        }
        return false;
    });
    
  

$(".filterCateg").change(function(){

newUrl = '/catalogue/' + $('#chpu').val() + '?p_f_1_temp_id=8&p_f_1_58=' + $('#p_f_1_58').val() + '&p_f_1_11=' + $('#p_f_1_11').val();

window.location.href = newUrl;
});

$(".filterBrand").change(function(){

newUrl = '/catalogue/' + $('#action').val();

window.location.href = newUrl;
});

    //var main_url = window.location.href;
        /*if(main_url == "http://www.mw-light.dev.binn.ru/catalogue/news.php"){
            $(".left-menu .firstH").remove();
        }*/
        
        var url = window.location.pathname;
        //alert(url);
        
    if(url == "/catalogue/mw-light/"){
        $(".filterCateg option[value='mw-light']").attr("selected","selected");
    }

    if(url == "/catalogue/chiaro/"){
        $(".filterCateg option[value='chiaro']").attr("selected","selected");
    }
    
    
    $(".recalc_btn").click(function(){
        //$("#ord_form").unbind();
    });
   
    $(".up").click(function(){
        var idx = $(this).attr("rel");
        var number = $(this).parent().find("#pl_plugin_order_" + idx).val();
        if(number == 1){
            $(this).parent().find(".down").attr("disabled",true);
            number++;
            $(this).parent().find("#elem_" + idx).text(number);
            $(this).parent().find("#pl_plugin_order_" + idx).val(number);
        }
        else
        {
            $(this).parent().find(".down").attr("disabled",false);
            number++;
            $(this).parent().find("#elem_" + idx).text(number);
            $(this).parent().find("#pl_plugin_order_" + idx).val(number);
        }
        //return false;
    });
    
    $(".down").click(function(){
        var idx = $(this).attr("rel");
        var number = $(this).parent().find("#pl_plugin_order_" + idx).val();
        if(number == 1){
            $(this).attr("disabled",true);
        }
        else{
            --number;
        $(this).parent().find("#elem_" +idx).text(number);
        $(this).parent().find("#pl_plugin_order_" +idx).val(number);
        }
        //return false;
    });
    
    if($(".number").text() == 1){
            $(".down").attr("disabled",true);
        }
        else{
            $(".down").attr("disabled",false);
        }


    // Language selection
    $("#language .dropdown dt a").click(function() {
        $(".dropdown dd ul").toggle();
    });
                
    $("#language .dropdown dd ul li a").click(function() {
        var text = $(this).html();
        $("#language .dropdown dt a span").html(text);
        $("#language .dropdown dd ul").hide();
    });
                
    function getSelectedValue(id) {
        return $("#" + id).find("dt a span.value").html();
    }

    $(document).bind('click', function(e) {
        var $clicked = $(e.target);
        if (! $clicked.parents().hasClass("dropdown"))
            $("#language .dropdown dd ul").hide();
    });


    // Main Menu
    $("div.mainnav-dw").hide();
    $("#mainnav ul.menu li.parent").mouseover(function() {
        $(this).find("div.mainnav-dw").show();
        $(this).addClass("active");
    });
    $("#mainnav ul.menu li.parent").mouseleave(function() {
        $(this).find("div.mainnav-dw").hide();
        $(this).removeClass("active");
    });

    // Main Slider
    //$("#main-slider").tabs();
    
    // Main Accordion
    $("#main-accordion").accordion({
        autoHeight: false,
        collapsible: true,
        active: false
    });
    
    // Main Carousel
    totalSize = $("#main-carousel ul li").size(); //кол-во элементов в списке
    elemWidth = 240; //ширина одного элемента
    totalWidth = totalSize * elemWidth - 4 * elemWidth; //макс. левая позиция

    $("#main-carousel").jcarousel({//инициализируем слайдер
        buttonPrevEvent: 'keypress', 
        buttonNextEvent: 'keypress'
    });
    
    function aTime(timeToSlide, zn){ //функция для расчета времени анимации
        
        if(zn == 'plus'){
            timeToAnimate = timeToSlide * (totalWidth - Math.abs(parseInt($("#main-carousel ul").css('left')))) / totalWidth;
        } else {
            timeToAnimate = timeToSlide * (Math.abs(parseInt($("#main-carousel ul").css('left')))) / totalWidth;
        }
        
        timeToAnimate = Math.round(timeToAnimate);
        return timeToAnimate;
    }
    
    $("#main-carousel .jcarousel-next").unbind('mouseover');
    $("#main-carousel .jcarousel-next").mouseover(function(){
        //анимация вперед, по окончании анимации дизаблим стрелку вперед
        $("#main-carousel ul").animate({left:"-" + totalWidth + "px"}, aTime(15000, 'plus'), function(){
            $("#main-carousel .jcarousel-next").addClass('jcarousel-next-disabled-horizontal');
        });
        //убираем дизабл у стрелки назад
        $("#main-carousel .jcarousel-prev").removeClass('jcarousel-prev-disabled-horizontal');
    });
    $("#main-carousel .jcarousel-next").mouseout(function(){
        //иногда читаем документацию, оказывается это полезно )
        $("#main-carousel ul:animated").stop(true, false);
        //дизаблим стрелку назад в крайнем левом положении
        if(parseInt($("#main-carousel ul").css('left')) < (-totalWidth + 10)){
            $("#main-carousel .jcarousel-next").addClass('jcarousel-next-disabled-horizontal');
        }
    });

    $("#main-carousel .jcarousel-prev").unbind('mouseover').mouseover(function(){
        //анимация назад, в конце дизаблим стрелку назад
        $("#main-carousel ul").animate({left:"0px"}, aTime(15000, 'minus'), function(){
            $("#main-carousel .jcarousel-prev").addClass('jcarousel-prev-disabled-horizontal');
        });
        //убираем дизабл у стрелки вперед
        $("#main-carousel .jcarousel-next").removeClass('jcarousel-next-disabled-horizontal');
    });
    $("#main-carousel .jcarousel-prev").mouseout(function(){
        $("#main-carousel ul:animated").stop(true, false);
        if(parseInt($("#main-carousel ul").css('left')) > -10){
            $("#main-carousel .jcarousel-prev").addClass('jcarousel-prev-disabled-horizontal');
        }
    });
    
    
    
    

    // Similar Carousel
    totalSize2 = $("#similar-carousel ul li").size(); //кол-во элементов в списке
    elemWidth2 = 188; //ширина одного элемента
    totalWidth2 = totalSize2 * elemWidth2 - 4 * elemWidth2; //макс. левая позиция
    
    $("#similar-carousel").jcarousel({
        buttonPrevEvent: 'keypress', 
        buttonNextEvent: 'keypress'
    });
    
    function aTime2(timeToSlide, zn){ //функция для расчета времени анимации
        timeToSlide *= 1000;
        timeToSlide -= 4000;
        if(zn == 'plus'){
            timeToAnimate = timeToSlide * (totalWidth2 - Math.abs(parseInt($("#similar-carousel ul").css('left')))) / totalWidth2;
        } else {
            timeToAnimate = timeToSlide * (Math.abs(parseInt($("#similar-carousel ul").css('left')))) / totalWidth2;
        }
        timeToAnimate = Math.round(timeToAnimate);
        return timeToAnimate;
    }
    
    $("#similar-carousel .jcarousel-next").unbind('mouseover').mouseover(function(){
    if(totalSize2 > 4){
        //анимация вперед, по окончании анимации дизаблим стрелку вперед
        $("#similar-carousel ul").animate({left:"-" + totalWidth2 + "px"}, aTime2(totalSize2, 'plus'), function(){
            $("#similar-carousel .jcarousel-next").addClass('jcarousel-next-disabled-horizontal');
        });
        //убираем дизабл у стрелки назад
        $("#similar-carousel .jcarousel-prev").removeClass('jcarousel-prev-disabled-horizontal');
    }    
    });
    $("#similar-carousel .jcarousel-next").mouseout(function(){
        //иногда читаем документацию, оказывается это полезно )
        $("#similar-carousel ul:animated").stop(true, false);
        //дизаблим стрелку назад в крайнем левом положении
        if(parseInt($("#similar-carousel ul").css('left')) < (-totalWidth2 + 10)){
            $("#similar-carousel .jcarousel-next").addClass('jcarousel-next-disabled-horizontal');
        }
    });

    $("#similar-carousel .jcarousel-prev").unbind('mouseover').mouseover(function(){
    if(totalSize2 > 4){
        //анимация назад, в конце дизаблим стрелку назад
        $("#similar-carousel ul").animate({left:"0px"}, aTime2(totalSize2, 'minus'), function(){
            $("#similar-carousel .jcarousel-prev").addClass('jcarousel-prev-disabled-horizontal');
        });
        //убираем дизабл у стрелки вперед
        $("#similar-carousel .jcarousel-next").removeClass('jcarousel-next-disabled-horizontal');
    }
    });
    $("#similar-carousel .jcarousel-prev").mouseout(function(){
        $("#similar-carousel ul:animated").stop(true, false);
        if(parseInt($("#similar-carousel ul").css('left')) > -10){
            $("#similar-carousel .jcarousel-prev").addClass('jcarousel-prev-disabled-horizontal');
        }
    });
    

    // Similar Carousel 2
    totalSize3 = $("#similar-carousel_2 ul li").size(); //кол-во элементов в списке
    elemWidth3 = 188; //ширина одного элемента
    totalWidth3 = totalSize3 * elemWidth3 - 4 * elemWidth3; //макс. левая позиция
    
    $("#similar-carousel_2").jcarousel({
        buttonPrevEvent: 'keypress', 
        buttonNextEvent: 'keypress'
    });
    
    function aTime3(timeToSlide, zn){ //функция для расчета времени анимации

        if(zn == 'plus'){
            timeToAnimate = timeToSlide * (totalWidth3 - Math.abs(parseInt($("#similar-carousel_2 ul").css('left')))) / totalWidth3;
        } else {
            timeToAnimate = timeToSlide * (Math.abs(parseInt($("#similar-carousel_2 ul").css('left')))) / totalWidth3;
        }
        timeToAnimate = Math.round(timeToAnimate);
        return timeToAnimate;
    }
    
    $("#similar-carousel_2 .jcarousel-next").unbind('mouseover').mouseover(function(){
    if(totalSize3 > 4){
        //анимация вперед, по окончании анимации дизаблим стрелку вперед
        $("#similar-carousel_2 ul").animate({left:"-" + totalWidth3 + "px"}, aTime3(5000, 'plus'), function(){
            $("#similar-carousel_2 .jcarousel-next").addClass('jcarousel-next-disabled-horizontal');
        });
        //убираем дизабл у стрелки назад
        $("#similar-carousel_2 .jcarousel-prev").removeClass('jcarousel-prev-disabled-horizontal');
    }    
    });
    $("#similar-carousel_2 .jcarousel-next").mouseout(function(){
        //иногда читаем документацию, оказывается это полезно )
        $("#similar-carousel_2 ul:animated").stop(true, false);
        //дизаблим стрелку назад в крайнем левом положении
        if(parseInt($("#similar-carousel_2 ul").css('left')) < (-totalWidth3 + 10)){
            $("#similar-carousel_2 .jcarousel-next").addClass('jcarousel-next-disabled-horizontal');
        }
    });

    $("#similar-carousel_2 .jcarousel-prev").unbind('mouseover').mouseover(function(){
    if(totalSize3 > 4){
        //анимация назад, в конце дизаблим стрелку назад
        $("#similar-carousel_2 ul").animate({left:"0px"}, aTime3(5000, 'minus'), function(){
            $("#similar-carousel_2 .jcarousel-prev").addClass('jcarousel-prev-disabled-horizontal');
        });
        //убираем дизабл у стрелки вперед
        $("#similar-carousel_2 .jcarousel-next").removeClass('jcarousel-next-disabled-horizontal');
    }
    });
    $("#similar-carousel_2 .jcarousel-prev").mouseout(function(){
        $("#similar-carousel_2 ul:animated").stop(true, false);
        if(parseInt($("#similar-carousel_2 ul").css('left')) > -10){
            $("#similar-carousel_2 .jcarousel-prev").addClass('jcarousel-prev-disabled-horizontal');
        }
    });


    
    
    // Catalog Item Overlay
    /*$("div.catalog-item-overlay").hide();
    $("div.catalog-item").hover(function() {
        $(this).find("div.catalog-item-overlay").toggle();
    });*/
        
        
        var count_link = $(".pagination a").length;
            width = count_link * 32.7;
        
        $(".pagination").css("width", width);
        
        if($(".ban_elem img").length != 0){
            $(".ban_elem").cycle({
                fx:'fade',
                speed:4000,
                timeout:4000
            });
        }
        
        if($(".ban_left img").length != 0){
            $(".ban_left").cycle({
                fx:'fade',
                speed:4000,
                timeout:4000
            });
        }

$(".autlet-ban").each(function(){    
    if($(".autlet-ban").html() == ""){
            $(this).remove();
        }
});
        
        
        if($("#main-slider .main-slide-item").length != 0){
            $("#main-slider .main-slider-body").cycle({
                fx:'fade',
                speed:1500,
                timeout:0,
                pager: '#main-slider .main-slider-nav',
                pagerAnchorBuilder: function(idx, slide){ 
                    return '#main-slider .main-slider-nav li a:eq(' + idx + ')'; 
                }
            });
        }
        
        
        if($(".full_small_img_inn a").length == 1){
            $(".full_small_img_inn a").click(function(){
                return false;
            })
        }
        if($(".full_main_img img").length > 0){
                $(".full_main_img").cycle({
                    fx:'fade',
                    speed:1500,
                    timeout:0,
                    pager: '.full_small_img_inn',
                    pagerAnchorBuilder: function(idx, slide) { 
                        return '.full_small_img_inn a:eq(' + idx + ')'; 
                    }
                });
        }
        
        if($(".full_small_img img").length > 6){
            $(".full_small_img").scrollable({
                horizontal:true,
                items:".full_small_img_inn",
                size:6,
                speed:1000
            });
        }
        else
        {
            $(".full_small_img .next").hide();
            $(".full_small_img .prev").hide();
        }
        
        
    if($(".shifr").length > 0){
        $(".shifr a[rel^='prettyPhoto']").prettyPhoto({
            animation_speed: 'fast',
            slideshow: false,
            autoplay_slideshow: false,
            opacity: 0.80,
            show_title: false,
            allow_resize: false,
            counter_separator_label: false,
            theme: 'facebook',
            hideflash: false,
            wmode: 'opaque',
            autoplay: false,
            modal: false,
            overlay_gallery: false,
            keyboard_shortcuts: false
        });
    }
    
    if($(".full_main_img img").length > 0){
        $(".full_main_img a[rel^='prettyPhoto[galery]']").prettyPhoto({
            cycle_nav: false,
            animation_speed: 'fast',
            slideshow: false,
            autoplay_slideshow: false,
            opacity: 0.80,
            show_title: false,
            allow_resize: false,
            counter_separator_label: ' / ',
            theme: 'facebook',
            hideflash: false,
            wmode: 'opaque',
            autoplay: false,
            modal: false,
            overlay_gallery: false,
            keyboard_shortcuts: false
        });
    }

    if($(".full_main_img_extra img").length == 1){
        $(".full_main_img_extra a[rel^='prettyPhoto']").prettyPhoto({
            cycle_nav: false,
            animation_speed: 'fast',
            slideshow: false,
            autoplay_slideshow: false,
            opacity: 0.80,
            show_title: false,
            allow_resize: false,
            counter_separator_label: ' / ',
            theme: 'facebook',
            hideflash: false,
            wmode: 'opaque',
            autoplay: false,
            modal: false,
            overlay_gallery: false,
            keyboard_shortcuts: false
        });
    }
    
    if($(".gal_elem").length > 0){
        $(".gal_elem[rel^='prettyPhoto']").prettyPhoto({
            animation_speed: 'fast',
            slideshow: false,
            autoplay_slideshow: false,
            opacity: 0.80,
            show_title: false,
            allow_resize: false,
            counter_separator_label: ' / ',
            theme: 'facebook',
            hideflash: false,
            wmode: 'opaque',
            autoplay: false,
            modal: false,
            overlay_gallery: false,
            keyboard_shortcuts: false
        });
    }
    
    if($("#mybook").length > 0){
        
        $("#zoom-b").click(function(){
            
            $(".wrap:visible").toggleClass('zooming');
            $(".wrap:visible").removeClass('zooming-active');
            
            /*$(".wrap img").anythingZoomer({
                expansionSize: 30,
                speedMultiplier: 1.4,
                smallArea: "#small",
                largeArea: "#large",
                zoomPort: "#overlay",
                mover: "#mover"
            });*/
            return false;
        });
        function initZoom(){
            
            /*$("span.wrap:visible").unbind().click(function(){
                elem = $(this).index();
                alert(elem);
            });*/
            
            //$("#mybook").booklet("next");
            //$("#mybook").booklet("prev");
        $("span.wrap:visible").each(function(e){
        
            $(this).unbind('click').click(function(){
                if($(this).hasClass('zooming') && !$(this).hasClass('zooming-active')){
                    elToZoom = $(this).attr('rel');
                    $(this).addClass('zooming-active');
                    
                    $(this).find('a').CloudZoom({
                        position: 'elemPos-' + elToZoom
                    });
                }
                
                return false;
            });
            $(this).mouseover(function(){
                elToZoom = $(this).attr('rel');
                if($(this).hasClass('zooming') && $(this).hasClass('zooming-active')){
                    $('#elemPos-' + elToZoom).show();
                } else {
                    $('#elemPos-' + elToZoom).hide();
                }
            });
            $(this).mousemove(function(e){
                if($(this).hasClass('zooming') && $(this).hasClass('zooming-active')){
                    elToZoom = $(this).attr('rel');
                    pageXCoords = e.pageX - $(this).offset().left*1;
                    pageYCoords = e.pageY - $(this).offset().top*1;
                    
                    if(pageYCoords < 250 && pageXCoords > 250){
                        $('#elemPos-' + elToZoom).css('right', 'auto').css('left', '-10px');
                    } else {
                        $('#elemPos-' + elToZoom).css('left', 'auto').css('right', '0px');
                        
                        //$('.coors').remove();
                        //$('#elemPos-' + elToZoom).before('<div class="coors">' + pageXCoords + '||' + pageYCoords + '</div>');
                    }
                    
                    
                    
                }
                
                
                
            });
            
            $(this).unbind('dblclick').dblclick(function(){
                if($(this).hasClass('zooming') || $(this).hasClass('zooming-active')){
                    elToZoom = $(this).attr('rel');
                    $(this).removeClass('zooming');
                    $(this).removeClass('zooming-active');
                    
                    $(this).find('a').unbind();
                    
                }
            });
        });
        $("span a").click(function(){
            return false;
        });
        }
        
        flowplayer("catalogue_sound", "http://www.mw-light.ru/js/flowplayer-3.2.7.swf", {
            plugins:{
                audio:{url: 'http://www.mw-light.ru/js/flowplayer.audio-3.2.2.swf'}
                },
                clip: {
                    url:'http://www.mw-light.ru/music/sound_e72de27.mp3',
                    autoPlay:false, 
                    autobuffering:true,
                    loop:false
                }
            });
    
    $('#mybook').disableSelection();
    
    $("#mybook").booklet({
        width:836,
        height:593,
        speed:1000,
        pagePadding:0,
        shadows:true,
        shadowTopFwdWidth:166,
        shadowTopBackWidth:166,
        shadowBtmWidth:50,
        closed:true,
        covers:true,
        autoCenter:true,
        menu:'.cur-pages-b',
        pageSelector:true,
        pageNumbers:false,
        manual: true,
        overlays: true,
        hovers:   true,
        next: '.page-count .next',                
        prev: '.page-count .prev',
        startingPage:0,
        before:function(){

            $f(0).play();
            if($(".b-current").text() != ''){
                $(".slash").css("display","block");
            }
            else{
                $(".slash").css("display","none");
            }
        },
        after:function(){
            initZoom();
            if($(".b-current").text() != ''){
                $(".slash").css("display","block");
            }
            else{
                $(".slash").css("display","none");
            }
        }
    });
    
    
    
    $("#razdel").load("/catalogue_book/cat.php", function(){
        var url = window.location.href;
        //alert(url);
        
        $("#razdel option").each(function(){
            var rel = $(this).attr("rel");
            if(rel == url){
                $(this).attr("selected","selected");
            }
        });
    });
    
    
    
    $("#razdel").change(function(){
        var url = $(this).find("option:selected").attr("rel");
        window.location.replace(url);
    });

    }
    
    
    $("#razdel").load("/catalogue_book/cat.php", function(){
        var url = window.location.href;
        //alert(url);
        
        $("#razdel option").each(function(){
            var rel = $(this).attr("rel");
            if(rel == url){
                $(this).attr("selected","selected");
            }
        });
    });
    
    
    
    $("#razdel").change(function(){
        var url = $(this).find("option:selected").attr("rel");
        window.location.replace(url);
    });
    
    $(".catalog-item").mouseover(function(){
        $(".catalog-item-overlay, .item-heading, .add-basket, .compare").hide();
        $(this).find(".catalog-item-overlay, .item-heading, .add-basket, .compare").toggle();
    });
    
    $(".catalog-item").mouseout(function(){
        $(this).find(".catalog-item-overlay, .item-heading, .add-basket, .compare").hide();
    });
     
    if($(".mainnav-right ul.menu li:last-child a").length > 0){
           var href = $(".mainnav-right ul.menu li:last-child a").attr("href");
           $(".order-link").attr("href",href);
    }
    //проверка доп услуг
    /*
    var total_sum = $("#total-sum").val();
        var sum = 0;
        $("#final-sum span").text(total_sum);
        
        $(".dop-uslugi input[type='checkbox']").click(function(){
            if($(this).attr("checked")){
                var sum = $(this).attr("rel");
                if(total_sum >= 30000){
                    total_sum = parseInt(total_sum);
                }else{
                    total_sum = parseInt(total_sum) + parseInt(sum);
                }
                $("#total-sum").val(total_sum);*/
    
            $("#final-sum span").text($("#total-sum").val());
            
            /*
            if($(this).attr("id") == '1287'){
                            $(".adres-dostavki").show();
                            $("#addres").val("");
                            $("#time").val("");
                            $("#wish").val("");
                        }
                    }
                    else
                    {
                        var sum = $(this).attr("rel");
                        if(total_sum >= 30000){
                            total_sum = parseInt(total_sum);
                        }else{
                            total_sum = parseInt(total_sum) - parseInt(sum);
                        }
                        //total_sum = parseInt(total_sum) - parseInt(sum);
                        $("#total-sum").val(total_sum);
                        $("#final-sum span").text(total_sum);
                                                  if($(this).attr("id") == '1287'){
                            $(".adres-dostavki").hide();
                            $("#addres").val("");
                            $("#time").val("");
                            $("#wish").val("");
                        }
                    }
                });
                                  $(".dop-uslugi input[type='checkbox']").each(function(){
                    if($(this).attr("checked")){
                        var sum = $(this).attr("rel");
                        if(total_sum >= 30000){
                            total_sum = parseInt(total_sum);
                        }else{
                            total_sum = parseInt(total_sum) + parseInt(sum);
                        }
                        //total_sum = parseInt(total_sum) + parseInt(sum);
                        $("#total-sum").val(total_sum);
                        $("#final-sum span").text(total_sum);
                                                  if($(this).attr("id") == '1287'){
                            $(".adres-dostavki").show();
                            $("#addres").val("");
                            $("#time").val("");
                            $("#wish").val("");
                        }
                    }
                });*/
            
    
    //проверка юр лица
    $("#oplata input[type='radio']").click(function(){
        if($(this).attr("checked")){
            var idx = $(this).attr("id");
        }
        
        if(idx == 'opt_1281'){
            $(".yur-lico").show();
            $(".yur-lico input[type='checkbox']").each(function(){
                if($(this).attr("checked")){
                    $(".yur-block").show();
                }
                else{
                    $(".yur-block").hide();
                    $(".yur-block input, .yur-block textarea").val("");
                }
            });
            $(".yur-lico input[type='checkbox']").click(function(){
                if($(this).attr("checked")){
                    $(".yur-block").show();
                }
                else{
                    $(".yur-block").hide();
                    $(".yur-block input, .yur-block textarea").val("");
                }
            });
        }else{
            $(".yur-lico").hide();
            $(".yur-lico input[type='checkbox']").attr("checked",false);
            $(".yur-block").hide();
            $(".yur-block input, .yur-block textarea").val("");
        }
        $(".ord_btn").show();
    });
    
    $("#oplata input[type='radio']").each(function(){
        if($(this).attr("checked")){
            var idx = $(this).attr("id");
            if(idx){
                $(".ord_btn-extra").show();
            }
        
        if(idx == 'opt_1281'){
            $(".yur-lico").show();
            $(".yur-lico input[type='checkbox']").each(function(){
                if($(this).attr("checked")){
                    $(".yur-block").show();
                }
                else{
                    $(".yur-block").hide();
                    $(".yur-block input, .yur-block textarea").val("");
                }
            });
            $(".yur-lico input[type='checkbox']").click(function(){
                if($(this).attr("checked")){
                    $(".yur-block").show();
                }
                else{
                    $(".yur-block").hide();
                    $(".yur-block input, .yur-block textarea").val("");
                }
            });
        }else{
            $(".yur-lico").hide();
            $(".yur-lico input[type='checkbox']").attr("checked",false);
            $(".yur-block").hide();
            $(".yur-block input, .yur-block textarea").val("");
        }
        
            $(".yur-lico input[type='checkbox']").click(function(){
                if($(this).attr("checked")){
                    $(".yur-block").show();
                }
                else{
                    $(".yur-block").hide();
                    $(".yur-block input, .yur-block textarea").val("");
                }
            });
        }
            
        });
        
        
            
        
        //colorbox
        // if($("#order-out").length > 0){
            // $("#order-out").colorbox({
                // iframe:true,
                // width:700,
                // height:750
                /*scrolling:false,
                onComplete:function(){
                    $.colorbox.resize(
                        {
                            innerHeight:$('iframe').height() + 100
                        }
                    );
                }*/
            // });
        // }
    


    //
    /*function showResponse(responseText, statusText)  {
        $('.load-block').html(responseText);
        commentInit();
    } 
    
    function commentInit(){
        $('.up, .down').click(function(){
            
            jQuery.ajaxSetup({
                
            });
            
                $.ajax({
                    beforeSend: function(request) {
                        request.setRequestHeader( 'Cookie', document.cookie );
                    },
                    type: "POST",
                    cache: false,
                    url: window.location.href.split('index').join('ajax'),
                    success: showResponse, 
                    data: $("#ord_form").serializeArray()
                });
                return false;
            
        })
    }
    if($('#ord_form').length > 0){
        commentInit();
    }*/
       
});
