$(document).ready(function() {
    $('input[name=remall]').click(function(){
        if($("input[name=remall]").is(":checked"))
            $('input[type=checkbox]').attr("checked", "checked");
        else
            $('input[type=checkbox]').removeAttr("checked");
    });


    $('.text-editor').ckeditor({
//        filebrowserBrowseUrl : '/browser/',
        filebrowserUploadUrl : '/upload/'
    });

    $(".login_box").focus(function(){
        $(this).attr('value', '');
    });

    $("#search_hint .inner_link").click(function(){
        $("#searchbox").attr('value', $(this).html());
    });

$("a[rel='splash']").colorbox({
        onOpen:function(){
            $("object").css('visibility', 'hidden');
        },
        onLoad:function(){
            $('#cboxPrevious').remove();
            $('#cboxNext').remove();
            $('#cboxCurrent').remove();
            $('#cboxLoadedContent').remove();
            $('#cboxTitle').remove();
        },
        onClosed:function(){
            $("object").css('visibility', 'visible');
        },
        transition:"elastic",
        width:"900px",
        height:"90%",
        scrolling: "true",
        close: 'Закрыть',
        opacity: 0.6,
        speed: 10,
        iframe:"true"
    });

$('a[rel="imageSplash"]').colorbox({
        onOpen:function(){
            $("object").css('visibility', 'hidden');
        },
        onClosed:function(){
            $("object").css('visibility', 'visible');
        },
            photo: true,
            scrolling: true,
            scalePhotos: true,
            maxWidth: '90%',
            maxHeight: '90%',
            preloading: true,
            close: "Закрыть",
            previous: "Назад",
            next: "Далее",
            current: "Фото {current} из {total}"
});

$(".subTabFilterAll").change(function(){
        if($(this).attr("checked"))
            $(".subTabFilter").attr("checked", true);
        else
            $(".subTabFilter").attr("checked", false);
});

$('select[name="subtreeSelect"]').hide();
$('select[name="subsubtreeSelect"]').hide();

$('select[name="treeSelect"]').change(function()
{
        $('input[name="tree"]').attr('value', $('select[name="treeSelect"] :selected').val());
        var treeSelectSelect = $('select[name="subtreeSelect"]');
        $('select[name="subsubtreeSelect"]').hide();
     $.get("/select/tree/", {treeSelect:$(this).val()}, function(treeSelectList)
        {
            treeSelectSelect.html('');
                treeSelectSelect.hide();
                if(treeSelectList != '')
                {
               treeSelectSelect.append('<option value="0" selected="selected" disabled="disabled">Вы можете уточнить свой выбор</option>');
                     treeSelectSelect.append(treeSelectList);
                     treeSelectSelect.show();

                }
        });
});

$('select[name="subtreeSelect"]').change(function()
{
        $('input[name="tree"]').attr('value', $('select[name="subtreeSelect"] :selected').val());

        var treeSelectSelect = $('select[name="subsubtreeSelect"]');
     $.get("/select/tree/", {treeSelect:$(this).val()}, function(treeSelectList)
        {
            treeSelectSelect.html('');
                treeSelectSelect.hide();
                if(treeSelectList != '')
                {

                treeSelectSelect.append('<option value="0" selected="selected" disabled="disabled">Вы можете уточнить свой выбор</option>');
                treeSelectSelect.append(treeSelectList);
                treeSelectSelect.show();
                }
        });
});

$('select[name="subsubtreeSelect"]').change(function()
{
        $('input[name="tree"]').attr('value', $('select[name="subsubtreeSelect"] :selected').val());
});



$('select[name="subregionsSelect"]').hide();
$('select[name="subsubregionsSelect"]').hide();
$('input[name="addCategory"]').hide();

$('select[name="regionsSelect"]').change(function()
{
        $('input[name="selected"]').attr('value', $('select[name="regionsSelect"] :selected').val());
        $('input[name="selectedName"]').attr('value', $('select[name="regionsSelect"] :selected').text());
        var regionsSelectSelect = $('select[name="subregionsSelect"]');
        $('select[name="subsubregionsSelect"]').hide();
        $.get("/select/regions/", {regionsSelect:$(this).val()}, function(regionsSelectList)
        {
            regionsSelectSelect.html('');
                regionsSelectSelect.hide();
                if(regionsSelectList != '')
                {
                    regionsSelectSelect.append('<option value="0" selected="selected" disabled="disabled">Вы можете уточнить свой выбор</option>');
                    regionsSelectSelect.append(regionsSelectList);
                    regionsSelectSelect.show();
                }
                $('input[name="addCategory"]').show();
        });

});

$('select[name="subregionsSelect"]').change(function()
{
        $('input[name="selected"]').attr('value', $('select[name="subregionsSelect"] :selected').val());
        $('input[name="selectedName"]').attr('value', $('select[name="subregionsSelect"] :selected').text());

        var regionsSelectSelect = $('select[name="subsubregionsSelect"]');
     $.get("/select/regions/", {regionsSelect:$(this).val()}, function(regionsSelectList)
        {
            regionsSelectSelect.html('');
                regionsSelectSelect.hide();
                if(regionsSelectList != '')
                {

                regionsSelectSelect.append('<option value="0" selected="selected" disabled="disabled">Вы можете уточнить свой выбор</option>');
                regionsSelectSelect.append(regionsSelectList);
                regionsSelectSelect.show();
                }
                $('input[name="addCategory"]').show();
        });
});

$('select[name="subsubregionsSelect"]').change(function()
{
        $('input[name="selected"]').attr('value', $('select[name="subsubregionsSelect"] :selected').val());
        $('input[name="selectedName"]').attr('value', $('select[name="subsubregionsSelect"] :selected').text());
        $('input[name="addCategory"]').show();
});


$('input[name="addCategory"]').click(function()
{
        $('#result').html($('#result').html() + '<br />' + '<input type="checkbox" name="regions[]" value="' + $('input[name="selected"]').val() + '" class="validate[minCheckbox[1]]" id="regions' + $('input[name="selected"]').val() + '" CHECKED /> <label for="regions' + $('input[name="selected"]').val() + '">' + $('input[name="selectedName"]').val()) + '</label>';
        $('select[name="regionsSelect"]').val($('select[name="regionsSelect"] :first').val());
        $('select[name="subregionsSelect"]').hide();
        $('select[name="subsubregionsSelect"]').hide();
        $('select[name="subregionsSelect"]').html('');
        $('select[name="subsubregionsSelect"]').html('');
        $('input[name="addCategory"]').hide();
		$('#regions1').parent().remove();
});

$('.productPageDescription tr:odd').css('background', '#f1f1f1');

$("#formID").validationEngine();


$('input.login-box-input').click(function(){
    if($(this).val() == 'Логин') 
        $(this).val('');
    if($(this).val() == 'Пароль')
        $(this).val('');
});

$("input[type='hidden']").css('border', '1px solid red');

$('.formhelper input[type=text], .formhelper textarea, .formhelper select').focus(function(){
  $('.formComment').css('display', 'none');
  $('.formComment').css('background', 'none');
    $(this).prev('.formComment').css('display', 'block');
    $(this).parent().css('background', '#f9f9f9');
});


$("#firstpane span.opened").next("div.menu_body").slideToggle(300).siblings("div.menu_body").slideUp("slow");
$("#firstpane span.opened").parents("div.menu_body").slideToggle(300).siblings("div.menu_body").slideUp("slow");

$("#firstpane span.menu_head").click(function()
{
    $(this).next("div.menu_body").slideToggle(300).siblings("div.menu_body").slideUp("slow");
});

$(function() {
    $(".date-pick").datepicker();


$('.oddTable tr:odd').css({background:'#ddd'});

       $("ul.sf-menu").supersubs({ 
            minWidth:    12,
            maxWidth:    17,
            extraWidth:  1  
                            
        }).superfish({
            animation: {height:'show'},
            delay: 120
        });

       $("#menu-top").superfish({      
           autoArrows:  false,                           // отключает стрелку подменю
         dropShadows: false                            // отключает тень
     });

});

        
        
$('.showMore').click(function(){
if($(this).html() == "Читать далее")
    $(this).html("Свернуть");
else
    $(this).html('Читать далее');
if($(this).prev().css('display') == 'none')
    $(this).prev().slideDown('500');
else
    $(this).prev().slideUp('500');
});


$('.showMoreLink').click(function(){
if($('.info_' + $(this).attr('rel')).next().html() == 'Читать далее')
    $('.info_' + $(this).attr('rel')).next().html('Свернуть');
else
    $('.info_' + $(this).attr('rel')).next().html('Читать далее');
    
$('.info_' + $(this).attr('rel')).css('display', 'block');

jQuery.scrollTo($(this).attr('rel'), 500);
});


$('.message').css('display', 'none')
$('.message').before('<div class="question" style="position: absolute; margin-left: ' + ($('.content').width() - 40) + 'px; margin-top: -15px;"><img src="/images/question.png" width="40" height="40" /></div>');
$('.message').prev().css('cursor', 'pointer')
$('.message').prev().click(function(){
    $(this).next().slideToggle();
});



$('#filters input, #filters select').change(function(){
     qwe = $(this).parent().serialize();
     window.location = '?' + qwe + '&' + $('.string').serialize();
});



});

