$(document).ready(
	function()
	{	
	
		$('#select-category').hover(function()
			{ 
				$(this).children("#select-category-btn").click(function() 
				{
					$('.categories').fadeIn(150);
					return false;
				});
			}, 
		function()
			{ $('.categories').fadeOut(150); });
			
		$('#typ-select #typ-select-cont').hover(function()
			{ 
				$(this).children("a#wybierz-typ").click(function() 
				{
					$('.typy').fadeIn(150);
					return false;
				});
			}, 
		function()
			{ $('.typy').fadeOut(150); });

		
		$("#main-menu li h2").children("a").mouseover( 
		function() 
		{ 
		 $("#main-menu li h2").next("ul").hide();
		 $(this).parent("h2").next("ul").show();
		});
		
		$(".box-best ul li").children("em").hover( 
		function() 
		{ 
			$(this).prev("div.call-attr").children("div.call-img").show();
		}, function() {
			$(this).prev("div.call-attr").children("div.call-img").hide();
		  }
		);
		
		$("ul.breadcrumbs").children("li:last").addClass("last");
		
		$(".product-tabs").children(".tab-content:first").show();
		$(".product-tabs ul.tabs").children("li:first").children("a").addClass("active");
		$(".product-tabs ul.tabs").children("li").click(function()
			{
				var karta = $(this).attr("id");
				$(".product-tabs").children("div."+karta).show();
				$(".product-tabs").children(".tab-content").not("."+karta).hide();
				$(this).children("a").addClass("active");
				$(".product-tabs ul.tabs").children("li").not(this).children("a").removeClass("active");
				return false;
			}
			);

		$('.box-content .termin .call-attr-info').hover(function(){ 
			var $dymek = $(this).next('.attr-info').children('.attr-desc');
			$dymek.css({ display: 'block'});
		}, 
		function(){
			var $dymek = $(this).next('.attr-info').children('.attr-desc');
			$dymek.css({ display: 'none'});
			return false;
		});

		$("#polecamy-kupic #polecamy-kupic-content .product:nth-child(3n)").addClass("product-last").after("<div class='clear-line'></div>");

		$("#promotion #promotion-content .product:nth-child(3n)").addClass("product-last").after("<div class='clear-line'></div>");
		for(i = 0; i < $("#promotion #promotion-content .product").size(); i++) {
			$("#promotion #promotion-content .product").eq(i).addClass("prod" + i);
		}
		$("#promotion #promotion-content div.prod2").nextAll().not(".clearer").addClass("schowane").hide();
		
		if($('#promotion #promotion-content div').is('.prod3') == true){
			$("#promotion").children(".header").append("<span>Pokaż wszytkie</span><span class='nieaktywne'>Zwiń</span>");
		}
		
		$("#promotion").children(".header").children("span").click( 
			function(){ 
				$("#promotion #promotion-content").children("div.schowane").toggle();
				$(this).hide();
				$("#promotion").children(".header").children("span").not(this).show();
		}
		);
		
		$("#safe").find("div.product:nth-child(3n)").addClass("product-last");		
		
		$(".probki-lista li:nth-child(4n)").after("<li class='clear-line'></li>");
		
		$(".aranzacje .box:nth-child(2n)").addClass("box-right");

		$(".product-left .product-image").children('#zdjecie_href').wrap('<table><tr><td></td></tr></table>');
		$(".product-left .gallery li").children('a').wrap('<table><tr><td></td></tr></table>');
		$(".product-left .gallery li:nth-child(2n)").addClass("odd");
		
		$("span[class*='GR_']").hide();

		
		for(i = 0; i < $("#polecane-produkty .product").size(); i++) {
			$("#polecane-produkty .product").eq(i).addClass("prod" + i);
		}
		
		$("#polecane-produkty div.prod2").nextAll().not(".clearer").addClass("schowane").hide();
		if($('#polecane-produkty div').is('.prod3') == true){
			$("#polecane-produkty").children(".header").append("<span>Pokaż wszytkie</span><span class='nieaktywne'>Zwiń</span>");
		}
		
		$("#polecane-produkty").children(".header").children("span").click( 
			function(){ 
				$("#polecane-produkty").children("div.schowane").toggle();
				$(this).hide();
				$("#polecane-produkty").children(".header").children("span").not(this).show();
		}
		);
		
		$("#polecane-produkty .product-last").after("<div class='clear-line'></div>");
		
		$("#register-bottom").children("a.register-btn").click(function()
			{
				$("#register-bottom").next("#register-form").show();
				return false;
			}
			);
			
		$('.btn-kontynuuj, .history-back, .back-btn').click(function(e){
			e.preventDefault();
			window.history.back();
		});
		
		$("#products-filter ul ul li:nth-child(4n)").after("<li class='clear-line'></li>");
		
		$("#galeria ul#lista-foto li:nth-child(6n)").addClass("last").after("<li class='clear-line'></li>");

		$('ul.gal-mala li a').click(function(e){ e.preventDefault(); });
		$("ul.gal-mala").children("li").children("a").hover(function()
			{
				var classname = $(this).attr("class");
				$(this).parent("li").parent("ul.gal-mala").prev("ul.gal-duza").find("."+classname).show("");
				$(this).parent("li").parent("ul.gal-mala").prev("ul.gal-duza").find("li").not("."+classname).hide("");
			}, function() {  }
			);
		
		$("#koszyk ul.lista:odd").addClass("odd");
		
		/* Slidery */
		$("#promocje-start").slider({slideAnimate:true,slideHide: 1750,slideShow: 500});

		$(".film").append("<script type='text/javascript'>flowplayer('a.myPlayer', '../flowplayer/flowplayer-3.1.5.swf');</script>");
	}
	);
	
jQuery.fn.slider = function(option) {
	option = jQuery.extend({
		slideAnimate: false,
		slideInterval: 6000,
		slideHide: 1750,
		slideShow: 1000
	}, option);	
	
	return this.each(function(i){	

		a = $(this);
		b = a.find('.nav');
		c = b.find('a');
		d = c.size();
		
		e = a.find('.prevPage');
		e.attr('href',d-1);
		f = a.find('.nextPage');
		f.attr('href',1);
		
		g = a.find('#promocje-contents');
		h = g.find('.promocje-content');
		
		/*
		*/
		h.hide();
		h.eq(0).show().addClass('visible');
		
		i=0;
		/*
		h.eq(0).attr('id','act');
		element = document.getElementById('act');
		
		element.style.opacity = '.1';
		*/
		
		
		c.click(function(e){
			e.preventDefault();
			i = $(this).attr('href');
			animSlider(i);
		});
		
		e.click(function(e){
			e.preventDefault();
			i = $(this).attr('href');
			animSlider(i);
		});
		
		f.click(function(e){
			e.preventDefault();
			i = $(this).attr('href');
			animSlider(i);
		});
		
		function setAnimation(){
			i = f.attr('href');
			animSlider(i);		
		}
				
				
		function animSlider(i){

			i = parseInt(i);

			if(i == d){
				i=0;
				iPrv = d-1;
				iNxt = i+1;
			}
			if(i == 0){
				iPrv = d-1;
				iNxt = 1;
			}
			else{
				iPrv = i-1;
				iNxt = i+1;
			}		
			
			c.removeClass('active');
			c.eq(i).addClass('active');
			
	
			g.find('.visible').fadeOut(option.slideSpeed, function(){
				$(this).removeClass('visible');
				h.eq(i).fadeIn(option.slideSpeed, function(){
					$(this).addClass('visible');
				});	
			});

			e.attr('href',iPrv);
			f.attr('href',iNxt);		
			
		} // function
		
		if(option.slideAnimate){
			si = setInterval(setAnimation, option.slideInterval);
		} // if(option.slideAnimate)
		
		if(si){
			a.mouseover(function(){
				clearInterval(si);
			});
			
			a.mouseout(function(){
				si = setInterval(setAnimation, option.slideInterval);
			});
		}// if(si)
	}); // each
}

	

