
$(document).ready(function(){
	$('#mainmenu li ul li a').click(function(){
		if($(this).next('ul').css('display') == "none")
		{
			$(this).next('ul').show();
			return false;
		}else if($(this).next('ul').css('display') == "block")
		{
			$(this).next('ul').hide();
			return false;
		}	
	});
	
	$('.product-brief-description-head').click(function(){
		$('.product-description').hide();
		$('.product-brief-description').show();
		$('.product-brief-description-head').css('background', '#341819');
		$('.product-brief-description-head').css('color', '#ffffff');
		$('.product-brief-description-head').css('cursor', 'text');
		$('.product-description-head').css('background', '#ffffff');
		$('.product-description-head').css('color', '#000000');
		$('.product-description-head').css('cursor', 'pointer');
	});
	
	$('.product-description-head').click(function(){
		$('.product-brief-description').hide();
		$('.product-description').show();
		$('.product-description-head').css('background', '#341819');
		$('.product-description-head').css('color', '#ffffff');
		$('.product-description-head').css('cursor', 'text');
		$('.product-brief-description-head').css('background', '#ffffff');
		$('.product-brief-description-head').css('color', '#000000');
		$('.product-brief-description-head').css('cursor', 'pointer');
	});
	
	$('#tree_check').click(function(){
		$('#tree input[type=checkbox]').attr('checked', true);
		return false;
	});
	
	$('#tree_uncheck').click(function(){
		$('#tree input[type=checkbox]').attr('checked', false);
		return false;
	});

    $("#aCallOpen").click(function() {
        $("#divCallMePlease").fadeIn();
        return false;
    });

    $("#aCallOpen").hover(
        function() {
            $("#aAddCallMe").show();
            $("#divCallNote").fadeIn(300);
        },
        function() {
            $("#divCallNote").hide();
        }
    );

    $("*[class*=popup-close]").click(function() {
        $("*[class*=popup-position]").fadeOut();
    })

    $("#divCallMePlease #tbPhone").unbind("keyup").keyup(function() {
        $(this).val($(this).val().replace(/[^0-9+\-() ]/g, ""));
    });


    $("#aAddCallMe").click(function() {

        $(this).hide();
        var name = HtmlEncode($("#divCallMePlease #tbName").val());
        var phone = $("#divCallMePlease #tbPhone").val();
        var comment = HtmlEncode($("#divCallMePlease #tbComment").val());
        if (name != '' && phone != '') {
            $.ajax({
                type: "POST",
                url: "index.php",
                data: {"ajax": true, "name": name, "phone": phone, "comment":  comment},
				contentType: "application/x-www-form-urlencoded; charset=utf-8",
                dataType: "json",
                success: function(response) { $('#divCallMePlease').fadeOut();  $.notifier("Ваш номер добавлен.", "success"); },
                error: function() { $('#divCallMePlease').fadeOut(); $.notifier("Ошибка. Попробуйте еще раз.", "error"); }
            });
        }
        else {
            $(this).show();
            $.notifier("Ошибка. Поля заполнены неверно", "error");
        }
    });
    //$(document).noConflict();
    $('.a_add_btn').click(function(){
    	var hidd = $(this).next('input').val();
        $.ajax({
            type: "POST",
            url: "/add_to_cmp.php",
            data: {"ajax": true, "do": "recount", "productID": hidd},
    		contentType: "application/x-www-form-urlencoded; charset=utf-8",
            dataType: "html",
            success: function(data){
            	$('.compare_cart .body').html(data);
            	/*$.ajax({
                    type: "POST",
                    url: "index.php",
                    data: {"ajax2": true, "compare_cart": "reset"},
                    contentType: "application/x-www-form-urlencoded; charset=windows-1251",
                    //cache: false,
                    //dataType: "html",
                    success: function(data){
                    	$('.compare_cart .body').html(data)
                    	},
                    //error: function(){}
                });*/
            },
            error: ''
        });
        
        $(this).css('display', 'none');
        $(this).next('input').next('div').css('display', 'block');
        
        
    });
    
    $.notifier = function(message, type) { notify(message, type); }

    function notify(message, type) {
        var instance = $(document.getElementById('divNoticeContainer'));
        var html = $.notifier.settings.noticeTemplate;
        html = html.replace('%Message%', message);

        if (type == "success")
            html = html.replace('%CssClass%', 'b-notif-success');
        else if (type == "error")
            html = html.replace('%CssClass%', 'b-notif-error');

        var notice = $(html).hide().fadeIn($.notifier.settings.noticeFadeTimeout);

        $.notifier.settings.noticeDisplay(notice);
        instance.append(notice);

        if ($.notifier.settings.displayTimeout > 0) {
            setTimeout(function() {
                $.notifier.settings.noticeRemove(notice, function() {
                    notice.remove();
                });
            }, $.notifier.settings.displayTimeout);
        }
    };

    $.notifier.settings = {
        noticeTemplate: '<div class="%CssClass%">%Message%</div>',
        noticeDisplay: function(notice) {
            notice.fadeIn($.notifier.settings.noticeFadeTimeout);
        },
        noticeRemove: function(notice, callback) {
            notice.animate({ opacity: '0', height: '0px' }, { duration: $.notifier.settings.noticeFadeTimeout, complete: callback });
        },
        noticeFadeTimeout: 'slow',
        displayTimeout: 5000
    };
});



		
	
