	
	function AddFavourite() { 
		var tytul = 'Lotari - zasłanianie w dobrym stylu'; 
		var adres = 'http://e-lotari.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;
			var RebateProductsPrice = document.getElementById('RebateProductsPrice').value;
		} else {
			var ProductsPrice = 0;
			var DeliveryPrice = 0;
			var PackagingPrice = 0;
			var ProductsRebate = 0;
			var CodeRebateValue = 0;
			var RebateProductsPrice = 0;
		}
		
		var Price = parseFloat(ProductsPrice) + parseFloat(DeliveryPrice) + parseFloat(PackagingPrice) - parseFloat(ProductsRebate);

		CodeRebateValue = (RebateProductsPrice * 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';
		}
		
		if ( parseFloat(Math.round((CodeRebateValue)*100)/100) <= 0 && parseFloat(document.getElementById('CodeRebateValue').innerHTML) > 0 ) {
			$('#CodeRebateValue').next().html(' % (nie dotyczy)');
		} else {
			$('#CodeRebateValue').next().html(' %');
		}
		
		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 nokaut_track_transaction(shop_id, transactionValue, transactionComment) {
		var name = "nokaut=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(name) == 0) {
				v = c.substring(name.length,c.length);
				v = v.split(",");
				if(v[0].indexOf("nokaut.pl") != -1)
					document.write("<img src=\"http://www.nokaut.pl/NewConversion/-/" + shop_id + "/" + v[1] + "/" + transactionValue  + "/" + transactionComment + "\" width=\"0\" height=\"0\" />");
			}
		}
		return null;
	}

	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(){
	
		$('.fancybox').fancybox({
			'titlePosition'	: 'inside',
			'width'				: '75%',
			'height'			: '75%',
		});
	
		$('#popup').click();
		
		$(".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"
			}
		});
		
		$('.special_offer > .box > .product').bind('mouseover', function() {
			$(this).css('background-image', 'url(template/img/produkt_box_bg.gif)');
		});
		
		$('.special_offer > .box > .product').bind('mouseout', function() {
			$(this).css('background-image', 'url(template/img/produkt_box_bg_off.gif)');
		});
		
		$('.productBox, .productOutletBox').bind('mouseover', function() {
			$(this).css('background-image', 'url(template/img/produkt_box_bg.gif)');
		});
		
		$('.productBox, .productOutletBox').bind('mouseout', function() {
			$(this).css('background-image', 'url(template/img/produkt_box_bg_off.gif)');
		});
		
		
		/* BEGIN MENU */
		$('li', '#menu > ul > li').bind('mouseover', function() {
			if ( $(this).hasClass('smartroll') == false ) {
				$(this).css('background', 'url(template/img/menu_item_arr.gif) no-repeat left #d3336f');
			} else {
				$(this).css('background', 'url(template/img/smartroll_menu_over.gif)');
			}
		});
		
		$('li', '#menu > ul > li').bind('mouseout', function() {
			if ( $(this).hasClass('smartroll') == false ) {
				$(this).css('background', '#c50260');
			} else {
				$(this).css('background', 'url(template/img/smartroll_menu.gif)');
			}
		});
		
		$('.show_categories').bind('click', function() {
			var parent_li =  $(this).parent();
			if ( $('ul', parent_li).css('display') == 'none' ) {
				parent_li.css('background', 'url("template/img/menu_item_bg_on.gif") repeat-x ').attr('rel', 'active');
				$('a', parent_li).css('color', '#fff');
				$('ul', parent_li).slideDown('fast');
			} else {
				$('ul', parent_li).slideUp('fast', function () {
					parent_li.css('background', 'url("template/img/menu_item_bg.gif") repeat-x ').removeAttr('rel');
					$('a', parent_li).css('color', '#666');
				});
			}
			
			return false;
		});
		
		$('#menu > ul > li').bind('mouseover', function() {
			if ( $(this).attr('rel') != 'active' ) {
				if ( $(this).hasClass('smartroll') == false ) {
					$(this).css('background', 'url("template/img/menu_item_bg_on.gif") repeat-x ');
					$('a', $(this)).css('color', '#fff');
				} else {
					$(this).css('background', 'url(template/img/smartroll_menu_over.gif)');
				}
			}
		});
		
		$('#menu > ul > li').bind('mouseout', function() {
			if ( $(this).attr('rel') != 'active' ) {
				if ( $(this).hasClass('smartroll') == false ) {
					$(this).css('background', 'url("template/img/menu_item_bg.gif") repeat-x ');
					$('a', $(this)).css('color', '#666');
				} else {
					$(this).css('background', 'url(template/img/smartroll_menu.gif)');
				}
			}
		});
		
		if ( parseInt(Config.pidkat) != 0 ) {
			var pidkat = '#' + parseInt(Config.pidkat);
			$(".#menu > ul > li > a").each(function (i) {
				if ( $(this).attr('href') == pidkat ) {
					$(this).click();
				} else if ( $(this).attr('rel') == pidkat ) {
					if ( parseInt(Config.pidkat) == 38 ) {
						$(this).parent().css('background', 'url(template/img/smartroll_menu_over.gif)').attr('rel', 'active');
					} else {
						$(this).parent().css('background', 'url("template/img/menu_item_bg_on.gif") repeat-x ').attr('rel', 'active');
						$(this).css('color', '#fff');
					}
				}
			});
		}
		/* END MENU */
		
		$('.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();

		var carouselGallery = $('#carouselGallery');
		var imageCompetition = $('#imageCompetition');

		//
		// Galeria
		//
		if (carouselGallery.length == 1) {
			carouselGallery.find('.galleryThumbs').jCarouselLite({
				btnNext: '#carouselGallery .galleryBottom .btnGalleryNext',
				btnPrev: '#carouselGallery .galleryBottom .btnGalleryPrev',
				auto: 3000,
				speed: 1000,
				visible: 5
			});

			var imgGallery = carouselGallery.find('.galleryThumbs li:first');

			// Powiększenie
			carouselGallery.find('.galleryThumbs img').click(function() {
				var img = $(this);
				var bigImage = carouselGallery.find('.bigImage');

				imgGallery = img.parents('li');

				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;
			});

			imgGallery.find('img').click();

			// Następne / poprzednie powiększenie
			carouselGallery.find('h2 .btnGalleryPrev').click(function(){
				var li = imgGallery.prev();

				if (li.length == 1) {
					li.find('img').click();
					imgGallery = li;
				}

				return false;
			});

			carouselGallery.find('h2 .btnGalleryNext').click(function(){
				var li = imgGallery.next();

				if (li.length == 1) {
					li.find('img').click();
					imgGallery = li;
				}

				return false;
			});

			// Pokaż opis
			carouselGallery.find('.bigImage').mouseenter(function(){
				carouselGallery.find('.info').fadeIn('slow');
			}).mouseleave(function(){
				carouselGallery.find('.info').fadeOut('slow');
			});

			// Pokaż ramkę
			carouselGallery.find('.galleryThumbs img').mouseenter(function(){
				$(this).addClass('hover');
			}).mouseleave(function(){
				$(this).removeClass('hover');
			});
		}
		//
		// Konkurs
		//
//		else if (imageCompetition.length == 1) {
//			if (openPhoto) {
//				imageCompetition.find('.zglosZdjecie').click();
//			}
//		}
		
		//
		// Czat
		//
		if ($('#chat.index').length == 1) {
			Chat.index();
		}
		else if ($('#chat.admin_index').length == 1) {
			Chat.admin_index();
		}
	});
