	
	function AddFavourite() { 
		var tytul = 'Lotari - zasłanianie w dobrym stylu'; 
		var adres = 'http://lotari.unito.pl';
		
		//FireFox 
		if (window.sidebar) {
			window.sidebar.addPanel(tytul, adres, ""); 
		
		//IE 
		} else if (window.external) {
			window.external.AddFavorite(adres, tytul); 

		//Opera 
		} else if (window.opera && window.print) { 
			var a = document.createElement('a'); 
			a.setAttribute('href', adres); 
			a.setAttribute('title', tytul); 
			a.setAttribute('rel','sidebar'); 
			a.click(); 
		} 
	} 
	
	function SendNewsletter(value) {
		if (value == 0) document.getElementById('opcjanews').value='off';
		else document.getElementById('opcjanews').value='on';
		
		document.formNewsletter.submit();
	}

	function changePriceDelivery( id ) {
		document.getElementById('DeliveryPrice').innerHTML = document.getElementById('Delivery_'+id).value;
		
		changePrice();
	}
	
	function changePricePackaging( id ) {
		document.getElementById('PackagingPrice').innerHTML = document.getElementById('Packaging_'+id).value;
		
		changePrice();
	}
	
	function changePrice() {
		if ( document.getElementById('ProductsPrice') ) {
			var ProductsPrice = document.getElementById('ProductsPrice').innerHTML;
			var DeliveryPrice = document.getElementById('DeliveryPrice').innerHTML;
			var PackagingPrice = document.getElementById('PackagingPrice').innerHTML;
			var ProductsRebate = document.getElementById('ProductsRebate').innerHTML;
			var CodeRebateValue = document.getElementById('CodeRebateValue').innerHTML;
		} else {
			var ProductsPrice = 0;
			var DeliveryPrice = 0;
			var PackagingPrice = 0;
			var ProductsRebate = 0;
			var CodeRebateValue = 0;
		}
		
		var Price = parseFloat(ProductsPrice) + parseFloat(DeliveryPrice) + parseFloat(PackagingPrice) - parseFloat(ProductsRebate);

		CodeRebateValue = (Price * CodeRebateValue / 100);
		
		document.getElementById('PriceNoCodeRebate').innerHTML = Math.round((Price)*100)/100;
		document.getElementById('PriceCodeRebate').innerHTML = Math.round((CodeRebateValue)*100)/100;
		
		if ( CodeRebateValue > 0 ) {
			document.getElementById('PriceNoCodeRebateTR').style.display = '';
			document.getElementById('PriceCodeRebateTR').style.display = '';
		} else {
			document.getElementById('PriceNoCodeRebateTR').style.display = 'none';
			document.getElementById('PriceCodeRebateTR').style.display = 'none';
		}
		
		document.getElementById('LastPrice').innerHTML = Math.round((Price-CodeRebateValue)*100)/100;
		
	}
	
	function show_hidden(id, idd) {
		if ( document.getElementById(id).checked == true ) {
			document.getElementById(idd).style.display = 'block';
		} else {
			document.getElementById(idd).style.display = 'none';
		}
	}
	
	function show_hidden_value(value, idd) {
		if ( value == 1 ) {
			document.getElementById(idd).style.display = 'block';
		} else {
			document.getElementById(idd).style.display = 'none';
		}
	}
	
	function przepiszDane() {
		document.getElementById('firma_telefon').value = document.getElementById('telefon').value;
		document.getElementById('firma_ulica').value = document.getElementById('ulica').value;
		document.getElementById('firma_miejscowosc').value = document.getElementById('miejscowosc').value;
		document.getElementById('firma_kod').value = document.getElementById('kod').value;
	}

	function openWindow(href) {
		window.open(href, 'okienko', 'menubar=no, toolbar=no, location=no, scrollbars=yes, resizable=no, status=no,width=650, height=650');
	}
	
	
	function findCookie(searchName){
		var cookies = document.cookie.split(";");

		for (var i = 0; i < cookies.length; i++) {
			var cookieCrumbs = cookies[i].split("=");
			var cookieName = cookieCrumbs[0].replace(" ","");
			var cookieValue = cookieCrumbs[1];

			if(cookieName == searchName) return cookieValue;
		}

		return false;
	}

	$(function(){
	
		$(".productBox").hover(
			function () {
				$(this).addClass("productBoxHover");
			},
		
			function () {
				$(this).removeClass("productBoxHover");
			}
		);	
		
		$('#cart').bgiframe();
		
		$("#cartLink").hover(
			function () {
				$("#cart").slideDown("fast");
			},
		
			function () {
				$("#cart").slideUp("fast");
			}
		);	
		
		$(".order").click(
			function () {
				var divID = $(this).attr("rel");
				var status = $(this).attr("alt");
				
				$("#"+divID).slideToggle("fast");
				$("#"+divID).fadeTo("fast", 1);
				
				if ( status == '1' ) {
					$(this).attr("alt","2");
					
					$("#"+divID+"_img").attr("src","template/img/btn_zamowienia_on.gif");
					
					$(this).css("background","#eeedeb");
					$(this).css("border-color","#eeedeb");
				} else {
					$(this).attr("alt","1");
					
					$("#"+divID+"_img").attr("src","template/img/btn_zamowienia_off.gif");
					
					$(this).css("background","#fff");
					$(this).css("border-color","#e1ddda");
				}
			}
		);
		
		$(".annexProducts").hover(
			function () {
				$(this).addClass("annexProductsHover");
			},
		
			function () {
				$(this).removeClass("annexProductsHover");
			}
		);
		
		$(".details").wTooltip({
			style: {
				border: "1px solid #9e9e9c",
				background: "white",
				color: "#1c1c1c",
				fontWeight: "normal",
				fontSize: "10px",
				maxWidth: "200px"
			}
		});
		
		$('.hoverImgReplace').hover( 
			function(){	
				$(this).attr('rel', $(this).attr('src'));
				$(this).attr('src', $(this).attr('alt'));							
			},
			function(){
				$(this).attr('src', $(this).attr('rel'));
			}
		);

		$('#fCodeRebate').bind("click change", function(){
			var kod_rabatowy = $('#fCodeRebate').val();
			if ( kod_rabatowy == '' ) {
				kod_rabatowy = 'null';
			}
			
			$.ajax({
				type: "GET",
				url: "page,kody_rabatowe,kod_rabatowy," + kod_rabatowy + ".html",
				data: "",
				success: function(msg){
					$('#CodeRebateValue').html(msg);
					changePrice();
				},
				error : function(msg) {
					alert("Wystąpił błąd podczas odczytu.");
				}
			});
		});
		
		$('#fCodeRebate').click();

		// Galeria
		$('.gallery .galleryThumbs').jCarouselLite({
			btnNext: '.gallery .btnGalleryNext',
			btnPrev: '.gallery .btnGalleryPrev',
			auto: 2000,
			speed: 1000,
			visible: 5
		});

		$('.gallery .galleryThumbs img').click(function() {
			var img = $(this);
			var bigImage = $('.gallery .bigImage');

			bigImage.fadeOut('fast', function(){
				var image = new Image(720, 405);
				image.src = img.attr('src').replace('min/', '');

				bigImage.css('background-image', 'url(' + img.attr('src').replace('min/', '') + ')');
				bigImage.find('.name').text(img.attr('alt'));
				bigImage.find('.description').text(img.attr('title'));

				bigImage.fadeIn('fast');
			});

			return false;
		});
	});
