

$(document).ready(function() {
    
    	$('#mycarousel').jcarousel({
        horizontal: true,
        scroll: 1
        });
				
		
				
		$("#menu li.menu-list").hover(function(){
			var rel = $(this).attr('rel');
			$('.submenu-tool-'+rel).show();
		}, function(){
			var rel = $(this).attr('rel');
			$('.submenu-tool-'+rel).hide();
		}
			);	
				

		$("#map_btn").toggle(function(){
			$("#footer_text").slideDown("slow");
		}, function(){
			$("#footer_text").slideUp("slow");
		}
		);
			
		$(".addborder4").parent().css("border", "1px solid #c1c1c1");
		$(".addborder5").parent().css("border", "1px solid #c1c1c1");
		
		$(".link").hover(
          function() {	
				w = $(this).attr('rel');
				$(".menu-"+w).show();
				$(this).children().css("color", "#fff");
				$(this).addClass("highlight");
				$(".link1").css("background", "#fff");
		  },
					function() {
				w = $(this).attr('rel');
				$(this).children().css("color", "");
				$(".link1").css("background", "");
				$(this).removeClass("highlight");
				$(".menu-"+w).hide("fast");
			}
		);
		
		// nano ela obsluga topu-logo
		$(".top_link").hover(
          function() {	
				$(this).css("border", "1px solid #f02108");
		  },
					function() {
				$(this).css("border", "0px");
			}
		);
        
        
		$('#prod_description').tabs({ fxAutoHeight: true });
		$('#intro_tabs').tabs(2);
		$('#foto_img').click(function() {
		$('#panning').fadeIn();
			});
		$('#panning').click(function() {
		$('#panning').fadeOut();
		});



   	//koszyk sklepowy
	shopcartInit();
    
	$('#order_final').live('click', function() {
		if($('input[name=permit]').is(":checked") == false)
		{
			jAlert('musisz zaakceptować regulamin', global.shop_name);
		return false;
		}
		var paymentType = $("#paymentOptions input:radio:checked").val();
		switch(parseInt(paymentType))
		{
		case 1:
			location.href = 'shopcart_paymentok.html&payment_type=przelew';
			break;
		case 2:
			location.href = 'shopcart_paymentok.html&payment_type=przy_odbiorze';
			break;
		case 3: 
			document.payform.submit();
			break;
		default:
			location.href = 'shopcart_details.html';
			break;
		}
	});

	$(document).click(function(){
		var ile_w_koszyku = $("#total_products").html();
		if (ile_w_koszyku != "0"){
			$("#product_idz_do_kasy").css("display", "block");
		}
	});

	
	//wybor platnosci
	$("input[name='paymentType']").livequery('click', function(){
		var platnosci_pl = $('#platnosci_pl');
		var platnosc_przelewem = $('#platnosc_przelewem');
	    if ($(this).val() == 3)
	    {
	    	platnosci_pl.css('display', 'block');
				platnosc_przelewem.css('display', 'none');
	    }
	    else if ($(this).val() == 1)
	    {
	    	platnosc_przelewem.css('display', 'block');
				platnosci_pl.css('display', 'none');
	    } else
	    {
	    	platnosci_pl.css('display', 'none');
				platnosc_przelewem.css('display', 'none');
	    }
	});
	
	$('img[id^=pay-]').live('click', function() {
		var payType = $(this).attr('id').substring(4);
		$('#pay_type').val(payType);
		$('img.paymentChoice').removeAttr('class');
		$(this).attr('class', 'paymentChoice');
	});

	//rozwijane stany magazynowe
	$('tr.product').click(function() {
		var cl = $(this).attr('id').substring(5);
		$('tr.color_'+cl).toggle();
		$('#prod_'+cl+' img.im').toggle();
	});
	
	
	//lightbox
	$(".lightbox").lightbox();
	
	
	
//	$().keypress(function(e) {
//		
//		
//			
//			code = e.keyCode ? e.keyCode : e.which;
//				if(code.toString() == 13) {
//			
//				search_form();
//
//				}
//			});

		$('#panning_background').click(function(){
		hidePanning();
		});
	
	
});

function search_form(){

	var search = $('#search_val').val();
	var url =  $('#search_url').val();
	var new_url = url+'-'+search;
	location.href= new_url.toLowerCase();

}




function showPanning(adres)
{
    //alert (adres);

}

function change_foto(new_img,url)
{
		
	$('#panning_background').show();	
	$('#panning').fadeIn();
	
	var flashvars = {'linkFoto': url+new_img+'&w=404&h=447'};
	var params = {'wmode': 'transparent'};
	var attributes = {'id':'panning_window', 'name':'panning_window'};
	swfobject.embedSWF(url+"swf/panning.swf", "panning_window", "737", "100%", "9.0.0",url+"swf/panning.swf", flashvars, params, attributes);

	
	
	}
function hidePanning(){$('#panning').fadeOut(); $('#panning_background').css('display','none');}
