﻿$(document).ready(function () {

    //var heightmiddleb = $('#middle').height();

    //$('#locklist').css('height', heightmiddleb - 200 + "px");

    $('.btn-slide').click(function () {
        $('#panel').slideToggle('slow');
        $(this).toggleClass('active'); return false;
    });

    $('.ar').click(function () {
        var img = $(this).find('img');
        var ul = $(this).nextAll('ul');

        ul.slideToggle('fast');

        if (img.attr('src') == '/content/img/arrow_menu_r.gif') {
            img.attr('src', '/content/img/arrow_menu_b.gif');
        } else {
            img.attr('src', '/content/img/arrow_menu_r.gif');
        }

    });

    $('.automodel').click(function () {
        $(this).next().slideToggle('fast');

        var img = $(this).find('img');
        if (img.attr('src') == '/content/img/arrow_menu_r.gif') {
            img.attr('src', '/content/img/arrow_menu_b.gif');
        } else {
            img.attr('src', '/content/img/arrow_menu_r.gif');
        }
    });

    var classAr = [".typemenu td.consul", ".typemenu td.bastion", ".typemenu td.block", ".typemenu td.ip-ign", ".typemenu td.moto", ".typemenu td.rezerv"];

    $('#complfilter').change(function () {

        if (this.value != "") {
            document.location.href = document.location.pathname + '?m=' + this.value;
        } else {
            document.location.href = document.location.pathname;
        }
    });


    $(".checkbox input:checkbox").click(function () {
        var checkbox = $(this);
        var currentCheckId = checkbox.attr("id").replace(/_[^\s]+/gi, "");
        var count = "";
        $('.checkbox input:checkbox').each(function (index) {
            var proId = $(this).attr("id").replace(/_[^\s]+/gi, "");
            if (proId == currentCheckId && checkbox.attr("checked")) {
                $(this).attr("checked", true);
                count = 1;
            }
            if (proId == currentCheckId && !checkbox.attr("checked")) {
                $(this).attr("checked", false);
                count = 0;
            }
        });
        $("#basket").load("/addbasket/" + currentCheckId + "?count=" + count);
        //console.log(currentCheckId); 
    });

    $(".orcheckbox input:checkbox").click(function () {
        var count = "";
        if ($(this).attr("checked")) {
            count = 1;
        }
        else {
            count = 0;
        }
        $("#basket").load("/addbasket/" + $(this).attr("id") + "?count=" + count);
    });

    $('.corder input').click(function () {
        var order_id = $(this).parent('div').attr('id');
        $('#texta textarea').attr('value', '');
        $('#texta').dialog({
            resizable: false,
            height: 250,
            width: 400,
            modal: true,
            buttons: {
                "Сохранить": function () {
                    $.post("/order/mnenie", { id: order_id, text: $('#texta textarea').val() });
                    $(this).dialog("close");
                }
            }
        });

    });


    $('.banners div').css('opacity', 0.6);
    $('.banners div').hover(
        function () { $(this).animate({ opacity: 1 }); },
        function () { $(this).animate({ opacity: 0.6 }); }
    );

    $('.autolink td').css('opacity', 0.7);
    $('.autolink td').hover(
        function () { $(this).animate({ opacity: 1 }); },
        function () { $(this).animate({ opacity: 0.7 }); }
    );

    $('#shoploc').click(function () {

        $("#shoplochtml").dialog({
            width: 400,
            height: 500,
            modal: true
        });
        return false;
    });

    $(".lbox").yoxview({
        lang: "ru"
    });

    $('#interview').click(function () {

        var divPoll = $('<div title="Экспресс опрос">Загрузка...</div>');
        divPoll.dialog({
            width: 600,
            modal: true,
            open: function (event, ui) { divPoll.load('/anketa/'); },
            buttons: {
                "Отправить": function () {
                    $.post("/anketa/vot/", divPoll.find('form').serialize());
                    divPoll.html('<p><b>Ваша анкета принята, спасибо за участие.</b></p>');
                    setTimeout(function() { divPoll.dialog( "close" ); }, 2000);
                }
            }
        });

        return false;

    });

});

jQuery.fn.idle = function(time){  
    var i = $(this);  
    i.queue(function(){  
        setTimeout(function(){  
           i.dequeue();  
        }, time);  
    });  
};  

function displayElm(id){
	var curEl=document.getElementById("child_"+id);
	var curEl2=document.getElementById("parent_"+id);
	var curImg=document.getElementById("child_im_"+id);
	if(!curEl) return false;
	if(curEl.style.display=="none"|curEl.style.display==""){
		curEl.style.display="block";
		if(curImg){curImg.src=imgOpened.src;}
	}	
	else {
		curEl.style.display="none";
		if(curImg){curImg.src=imgClosed.src;}
	}	
	if(curEl2) {
		if(curEl2.style.display=="none"|curEl2.style.display==""){
		curEl2.style.display="block";
	}	
	else {
		curEl2.style.display="none";}
	}
	return true;
}

