$(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;
            }            
        });
        
        $("#all_sum span.amount").text(all_sum);
    });
});
