$(document).ready(function() {
    $("#about_company_link").click(function () {
        if($("#about_company_text").hasClass("visible")) {
            $("#about_company_text").hide("slow").removeClass("visible");
        } else {
            $("#about_company_text").show("slow").addClass("visible");
        }
        return false;
    });

    $("#product_images_additional a").click(function(){
        $("#product_images_additional a").removeClass("selected");
        $(this).addClass("selected");
        $("#product_image_main").attr("src", $(this).attr("rel"));
        return false;
    });
        
    $("#show_full").fancybox({
		'hideOnContentClick': true,
		'scrolling' : 'no',
		'autoScale' : false,
		'overlayShow' : true,
        'overlayOpacity' : 0.8,
        'overlayColor' : '#fff',
        'enableEscapeButton' : true,
        'showCloseButton' : false,
        'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic'
	});


    $("#characteristics_link").fancybox({
        'hideOnOverlayClick' : true,
        'scrolling' : 'no',
		'autoScale' : false,
        'overlayShow' : true,
        'overlayOpacity' : 0.8,
        'overlayColor' : '#fff',
        'showCloseButton' : false,
        'enableEscapeButton' : true,
        'transitionIn'	: 'elastic',
	'transitionOut'	: 'elastic'
    });

    $("#order_table td.count input").keyup(function () {
        var count = parseInt($(this).val());
        var price = parseInt($(this).parent().parent().find("td.price span.amount").text());
        if(!isNaN(count) && !isNaN(price)) {
            $(this).parent().parent().find("td.sum span.amount").text(count*price+" руб.");
        }

        var all_sum = 0;

        $("#order_table tr td.count").each(function () {
            var this_count = parseInt($(this).find("input").val());
            var this_price = parseInt($(this).parent().find("td.price span.amount").text());
            if(!isNaN(this_count) && !isNaN(this_price)) {
                all_sum += this_count*this_price;
            }            
        });
        $("#id_price").val(all_sum);
        $("#all_sum span.amount").text(all_sum);
    });
    $(".cart_content .input_count").keydown(function(event)
    {
       if (event.keyCode == '13') {
           event.preventDefault();
         }
       
    })
    $(".cart_content form").submit(function(){
        if ( !/[^\s]/.test($("#id_name").val()) || !/[^\s]/.test($("#id_email").val()) ) 
        {
            if (!$(".order_form p:first").hasClass("cart_error"))
            {
            $(".order_form").prepend("<p class='cart_error'>Вы не заполнили все необходимые поля.</p>")
            }
            return false;
        }
        
    })
    
    $(".hide_text").toggle(function () {
                var wr=$(this).closest("div.static_container");
                 $("div.text",wr).show("slow");
                return false;
            },function (){
            var wr=$(this).closest("div.static_container");
               $("div.text",wr).hide("slow");
                return false;
            }
        );
    
});

