function calculate(){
    var cont_background = parseInt($("#cont_background").css("width"));
    var cont_wrapper = viewportwidth;
    $("#cont_background").css("left", ((cont_wrapper-cont_background)/2)+"px");
}

function floatinit(plus){
  //  alert (plus);
            if (plus == null){var plus = 0;}else{var plus = parseInt(plus);}
    		var wyscategories = parseInt($('#left').css("height"));
            var wysokosc_category_prod_preview = parseInt($("#right").css("height"))+plus;
            //alert (wysokosc_category_prod_preview);
            //alert (wyscategories);
            if (wyscategories >= wysokosc_category_prod_preview){
                $('#right').css('height', wyscategories+'px');
            } else {
                $('#right').css('height', wysokosc_category_prod_preview+'px');
            }
      if ($("#kontakt").length != 0){
		$("#kontakt").stickyfloat( {
			duration : 400
		});
      }
        // setTimeout("floatinit(null)", 1000);

}

    function formularz_refresh(){
        $("#formularz_mask").css("display", "none");
        $("#formularz_zapytan_tresc").css("display", "block");
        $("#formularz_msg").css("display", "none");
    };
    
$(document).ready(function() {
    
   	$(window).resize(function() {
   	    floatinit(null);
		calculate();
	});
    
    floatinit(null);
    calculate();
    
    $('#prodGallery').cycle({
        fx:     'fade',
        timeout: 3000,
        speed:  1000,
        next:   '#next2',
        prev:   '#prev2'
    });
    
   	$("a.lightbox").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	true
	});
    
    $(".datepicker").datepicker({dateFormat: 'yy-mm-dd', firstDay: 1});
    
    $("#formularz_wyslij").click(function(){
        $("#formularz_mask").css("display", "block");
        $("#formularz_zapytan_tresc").css("display", "none");
        var form = $(this).parent("form").serialize();
       // alert (form);
                $.ajax({
                        type: 'POST',
                        url: URL+"ajaxLoad/sendFormularz.php",
                        data: { ajaxDataLoad: "haslo", form: form },
                        success: function(xml) {
                            $("#formularz_mask").css("display", "none");
                            $("#formularz_zapytan_tresc").css("display", "none");
                            $("#formularz_msg").css("display", "block");
                            $("#formularz_msg").html(xml);
                            },
                        error: function(xhr, type, exception) {
                            $("#formularz_mask").css("display", "none");
                            $("#formularz_zapytan_tresc").css("display", "none");
                            $("#formularz_msg").css("display", "block");
                            $("#formularz_msg").html("Wystąpił błąd prosimy spróbować później.");
                        }
                    }) 
    });
    
    $("#formularz_zapytan_handle").toggle(function(){
       $("#formularz_zapytan_wrapper").animate({top: "0px"}, 500);  
    }, function(){
       $("#formularz_zapytan_wrapper").animate({top: "-275px"}, 500);  
    }); 
    
    $('#nasza_oferta_ul').jcarousel({
        scroll: 1,
        auto: 3,
        wrap: 'circular',
        itemFirstInCallback: super_font
      //  wrap: 'circular'
   //     initCallback: mycarousel_initCallback
    });
    
    $('#uznanie_ul').jcarousel({
        scroll: 1,
        auto: 5,
        wrap: 'circular'
    });
    
//    $(".product_mini").click(function(){
//      var src = $(this).attr("rel");
//      $("#product_big").attr("src", src); 
//    });
    
//    $(".over_label").click(function(){
//			var detailsId = '#'+$(this).attr('rel');
//			if($(detailsId).css('display') == 'none')
//			{
//			$(this).text('ukryj »');
//			$(detailsId).show();
//			}
//			else
//			{
//				$(this).text('pokaż »');
//				$(detailsId).hide();
//			}
//			return false;
//    });
    
//    $("#zastosoawnie_option_click").livequery('change', function(){
//       var link = $(this).children("option:selected").attr("value");
//       if (link != "") location.href = link; 
//    });
    
//    $("#see_all_products_box_div").masonry();
//    $("#see_all_products_box_div").css("display", "none");
    
    // FACELIFT czyli super czcionki
    
    // FLIR.init( { path: URL+"jss/facelift-1.2.2/" });
    super_font();
    
    
//    $(".aktualnosci_lista_tytul_div").toggle(function(){
//       $(".aktualnosci_lista_tekst_div").hide();
//       rel = $(this).attr("rel"); 
//       $("#aktualnosci_lista_tekst_div_"+rel).show();
//    }, function(){
//       $(".aktualnosci_lista_tekst_div").hide();  
//    });
    
         
    // $("#myTable").tablesorter( {sortList: [[1,0]]} );  
     
    $('#footer_site_map').jScrollPane({showArrows:true, scrollbarWidth: 8, scrollbarMargin: 5, maintainPosition: false});
    
    

        
//    $(".ibox .subs").hover(function(){
//       if( !$("div").is(":animated") ) { 
//           $(this).children("div").children("ul.ibox_content").animate({opacity: 1}, 500, function(){});
//           $(this).siblings(".ibox_hover").css("display", "block").animate({opacity: 1}, 500, function(){});
//           $(this).children("div").animate({height: 195}, 500, function(){
//                $('.jscroll').jScrollPane({showArrows:true, scrollbarWidth: 7, scrollbarMargin: 5, maintainPosition: false});
//                $(this).children("div .jScrollPaneTrack").css("display", "block");
//           });
//       } 
//    }, function(){
//            $(this).siblings(".ibox_hover").stop(true,true);
//            $(this).children("div").stop(true,true);
//            $(this).children("div").children("ul.ibox_content").stop(true,true);
//            $(this).children("div").children("ul.ibox_content").css("opacity", "0").css("filter", "alpha(opacity=0)");
//            $(this).siblings(".ibox_hover").css("display", "none").css("opacity", "0").css("filter", "alpha(opacity=0)");
//            $(this).children("div").css("height", "140px");
//            $(this).children().children(".jScrollPaneTrack").css("display", "none");
//        
//    });

    
    
    
    // $("img[title]").tooltip();
    
    /**
    *  Obsluga newslettera na stronie
    **/
//    $("#footer_newsletter_submit").click(function(){
//        var email = $("#footer_newsletter input").attr("value");
//        $.post(URL+"ajaxLoad/footer_add_to_newsletter.php", { ajaxDataLoad: "haslo", email: email },
//    				function(ajaxDataLoad){
//    								jAlert(ajaxDataLoad, global.shop_name);
//
//        });
//    });
    /**
    *  KONIEC
    **/
    
    
//    $("#mini_pokaz_rzeczy").toggle(function(){
//        $("#shopcart_mini_details_content").show();
//        $("#mini_pokaz_rzeczy img").attr("src", URL+"images/mini_zawartosc_arrow_hide.png");
//        $("#mini_pokaz_rzeczy img").css("vertical-align", "bottom");
//    }, function(){
//        $("#shopcart_mini_details_content").hide();
//        $("#mini_pokaz_rzeczy img").attr("src", URL+"images/mini_zawartosc_arrow.png");        
//        $("#mini_pokaz_rzeczy img").css("vertical-align", "top");
//    })
    
    
//    $(".block_big_picture_product").click(function(){
//        $(".category_image_no_display").hide(); //ukrywam zdjecie ktore widac
//        rel = $(this).attr("rel");
//        $(".image_"+rel).css("display","block");
//    });

    
//    	$('#mycarousel').jcarousel({
//        horizontal: true,
//        scroll: 1
//        });
				
		$(".to_corner").corner();
        
          $(".menu_lvl1").mouseenter(function() {
                $(this).addClass("menu_lvl1_hover");
                $(this).removeClass("menu_lvl1");
                super_font();
          }).mouseleave(function() {
                $(this).removeClass("menu_lvl1_hover");
                $(this).addClass("menu_lvl1");
                super_font();
          });

				
        window.setInterval(function() {
            $(".mouse_off").each(function(){
                    $(this).css('display', 'none');
                    $(this).prev('.menu_lvl1').css('display', 'block');
            });
        }, 300);

				

		$(".see_all_products_slider").toggle(function(){
			$("#see_all_products_box_div").slideDown("slow");
		}, function(){
			$("#see_all_products_box_div").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: 
			//location.href = 'shopcart_paymentok.html&payment_type=przelew';
			
			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 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');}

$(document).ready(function() {
	$("#f").autocomplete(URL+"ajaxLoad/search_auto_complete.php", {
			minChars: 3,
			matchContains: false,
			autoFill: false,
			mustMatch: false,
			max : 200
			});

    $(".ac_over").livequery(function(){
        $(this).click(function(){
        var wpisany_tekst = $(this).children("div").children("div .autocomplete_name_pages").text();
		$("#minisearch").attr("action", URL+"-"+wpisany_tekst);
		$("#minisearch").submit();
       // $("#f").attr("value", wpisany_tekst);
        });
    });		
			
	$("#search_button").click(function(){
		var wpisany_tekst = $("#f").attr("value");
		$("#minisearch").attr("action", URL+"-"+wpisany_tekst);
		$("#minisearch").submit();
	});
});


function super_font(){
    Cufon.replace('.super_font');
}









 var viewportwidth;
 var viewportheight;
 
 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
 
 if (typeof window.innerWidth != 'undefined')
 {
      viewportwidth = window.innerWidth,
      viewportheight = window.innerHeight
 }
 
// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

 else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0)
 {
       viewportwidth = document.documentElement.clientWidth,
       viewportheight = document.documentElement.clientHeight
 }
 
 // older versions of IE
 
 else
 {
       viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
       viewportheight = document.getElementsByTagName('body')[0].clientHeight
 }
