$(document).ready(function() 
{   
    $("a.helper").fancybox({
        'overlayShow'            : false,
        'zoomSpeedIn'            : 600,
        'zoomSpeedOut'           : 500,
        'easingIn'               : 'easeOutBack',
        'easingOut'              : 'easeInBack'
    });

    $("a.fancy").fancybox({
        'zoomOpacity'            : true,
        'overlayShow'            : true,
        'zoomSpeedIn'            : 600,
        'zoomSpeedOut'           : 500,
        'easingIn'               : 'easeOutBack',
        'easingOut'              : 'easeInBack'
    });

    if($.cookie("cameFrom")==null)
    {
        $.cookie("cameFrom",$(document)[0].referrer,{ expires: 30 });
    }
    
    $('input[name="jentryUrl"]').val($.cookie("cameFrom"));
    
    $('#container').tabs({ fxSlide: true });
    
    $.ajax({
            type: 'POST',
            url: '../ax/refreshTotalPrice.php',
            data: $('#cechy').serialize(),
            success: function(response){
            $('#productTotalPrice').html(response);
            }
            });
    $('a#addOrderInfo').click(function(){
    	if($('#additionalData').css("display") == 'none') {
    		$('#additionalData').show('slow');
    		$(this).html('- Zwiń dodatkowe pola');
    	} else {
    		$('#additionalData').hide('slow');
    		$(this).html('+ Rozwiń dodatkowe pola');
    	}
    });
    
    $('b#basketOrderValue').text((parseFloat($('input[checked="checked"]').attr('alt'))+parseFloat($('input[name="orderHiddenValue"]').val())).toFixed(2));
    $('input[name="order_subsum"]').val((parseFloat($('input[checked="checked"]').attr('alt'))+parseFloat($('input[name="orderHiddenValue"]').val())).toFixed(2));
    $('#transport_cost').text($('input[name="delivery"]').attr('alt')+' zł');
    
    $('input[name="delivery"]').change(function(){
    	$orderCost = $('input[name="orderHiddenValue"]').val();
    	$transportCost = $(this).attr('alt');
    	$totalCost=(parseFloat($orderCost)+parseFloat($transportCost)).toFixed(2);
    	$('b#basketOrderValue').text($totalCost);
    	$('b#basketOrderValue').fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100);
    	$('input[name="order_subsum"]').val($totalCost);
    	$('#transport_cost').text($transportCost+' zł');
    });
    
    $('a.getDetails').click(function(e){
    	e.preventDefault();
    	if($($(this).attr('href')).css('display') == 'none') {
    		$($(this).attr('href')).show(100);
    		$(this).text('zwiń szczegóły');
    		$(this).addClass('down');
    	} else {
    		$($(this).attr('href')).hide(100);
    		$(this).text('rozwiń szczegóły');
    		$(this).removeClass('down');
    	}
    });
    
    $('#przelicz-koszyk').css('display','none');
    
    $('input[class="inputo"]').keyup(function(e){
    	if(e.keyCode>47&&e.keyCode<58 || e.keyCode>96&&e.keyCode<107) {
    		$(this).parent().find('.recount').show(200);
    		$.doTimeout(1000, function(){
    			$('#koszyk').submit();
			});
    	} else {
    		$(this).parent().find('.recount_err').show(200);
    	}
    });
});

