$(window).bind("ajaxSend", function() {
  $('#komentarze').stop(true,true).show().fadeIn(333);
});

$(window).bind("ajaxError", function() {
  $('#komentarze').stop(true,true).fadeOut(333);
});

$(window).bind("ajaxSuccess", function() {
  $('#komentarze').stop(true,true).fadeOut(333);
  //dla IE6
  if (document.recalc) document.recalc();
  //console.log('recalc');
});

		
/* funkcja generuje nowy adres z hashem - # */
function link(adres) {	
	/*var wzorzec= /\#[a-z]{0,}/i;*/
	var wzorzec= /\#[\S]{0,}/i;
	document.location.href = document.location.href.replace(wzorzec,"") + adres;
}

/* ================================= */
/* PO ZAŁADOWANIU DOM                */
/* ================================= */

$(function() {
/* KATEGORIE MENU */

	var sub = $('#menu-3 li ul').before('<span><img src="'+sciezka+'icons/more.png"></span>');

	$('#menu-3 li span').click(

	function() {

		$(this).next().slideToggle('normal');

		var x = $(this).html();
		var y;

		if (x == '<IMG src="'+sciezka+'icons/more.png">' || x == '<img src="'+sciezka+'icons/more.png">')
		{y = '<IMG src="'+sciezka+'icons/less.png">';}

		if (x == '<IMG src="'+sciezka+'icons/less.png">' || x == '<img src="'+sciezka+'icons/less.png">')
		{y = '<IMG src="'+sciezka+'icons/more.png">';}

		$(this).html(y);

	});
	
/* PRODUKT-SZCZEGÓŁY TABS */

	//When page loads...
	$(".produkt-szczegoly-tab").hide(0); //Hide all content
	
	$("ul.produkt-szczegoly-tabs li:first").addClass("active").show(0); //Activate first tab
	$(".produkt-szczegoly-tab:first").show(0); //Show first tab content

	//On Click Event
	$("ul.produkt-szczegoly-tabs li").click(function() {

		$("ul.produkt-szczegoly-tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".produkt-szczegoly-tab").hide(0); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content

		// jak link zaczyna sie od # przechodzi do diva, jak nie -> normalny link
		if (activeTab.charAt(0) == "#") {
			$(activeTab).fadeIn(0); //Fade in the active ID content
			return false;
		}

	});
	
/* PANEL-KLIENTA TABS */

	//When page loads...
	//$(".klient-tab").hide(0); //Hide all content
	//$("ul.panel-klienta-tabs li:first").addClass("active").show(0); //Activate first tab
	//$(".klient-tab:first").show(0); //Show first tab content
	/*
	//On Click Event
	$("ul.panel-klienta-tabs li").click(function() {

		$("ul.panel-klienta-tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".klient-tab").hide(0); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content

		// jak link zaczyna sie od # przechodzi do diva, jak nie -> normalny link
		if (activeTab.charAt(0) == "#") {
			$(activeTab).fadeIn(0); //Fade in the active ID content
			return false;
		}

	});
	*/

/* WYSZUKIWARKA */

	//$('#wyszukiwanie-zaawansowane').css('display','none');
		var x;
		var y;
		var z;
		x = $('#wyszukiwanie-zaawansowane').css('display');
		if ( x == 'block')  {z = 'url('+sciezka+'icons/less.png)'}
		if ( x == 'none') {z = 'url('+sciezka+'icons/more.png)'}
		$('#wyszukiwanie-toogle').css('background-image', z);
	
	$('#wyszukiwanie-toogle').click(
	function() {
		var x;
		var y;
		var z;
		x = $('#wyszukiwanie-zaawansowane').css('display');
		if ( x == 'none')  {y = 'block'; z = 'url('+sciezka+'icons/less.png)'}
		if ( x == 'block') {y = 'none'; z = 'url('+sciezka+'icons/more.png)'}
		$('#wyszukiwanie-zaawansowane').css('display', y);
		$('#wyszukiwanie-toogle').css('background-image', z);
	});

/* PRZYPOMNIENIE HASŁA */

	$('#przypomnienie-form').css('display','none');
	$('#przypomnienie-toogle').css('background-image','url('+sciezka+'icons/more.png)');
	$('#przypomnienie-toogle').click(
	function() {
		var x;
		var y;
		var z;
		x = $('#przypomnienie-form').css('display');
		if ( x == 'none')  {y = 'block'; z = 'url('+sciezka+'icons/less.png)'}
		if ( x == 'block') {y = 'none'; z = 'url('+sciezka+'icons/more.png)'}
		$('#przypomnienie-form').css('display', y);
		$('#przypomnienie-toogle').css('background-image', z);
	});

/* FORM INPUT WATERMARK HINT TEXT INIT */

	$('#top-strip form').hint({attr:'title'});
	$('#box-logowanie form').hint({attr:'title'});
	$('#przypomnienie-form form').hint({attr:'title'});
	$('#box-wyszukiwanie form').hint({attr:'title'});

/* BIGGER LINK FIX */

	$('#box-ostatnio-ogladane ul li').biggerlink({otherstriggermaster:false});
	$('#box-nowosci ul li').biggerlink({otherstriggermaster:false});
	$('#box-promocje ul li').biggerlink({otherstriggermaster:false});
	$('#box-bestsellery ul li').biggerlink({otherstriggermaster:false});
	$('#box-news ul li').biggerlink({otherstriggermaster:false});
	$('#lista-produktow-boxy .produkt-box').biggerlink({otherstriggermaster:false});
	$('#lista-produktow .produkt-row').biggerlink({otherstriggermaster:false});

/* ==================================================== */
/* POZOSTAWIA OTWARTE KATEGORIE PO PRZELADOWANIU STRONY */
/* ==================================================== */

	$(document).ready( function() {
		if (id_kat > 0) {
			var parents = $("a[href*='k_"+id_kat+".html']").parents();
			for(var i = 0; i < parents.length; i++){
			
			  $(parents[i]).css('display','block');
			  obrazek = $(parents[i]).children(':first').next().html();
			  
			  if (obrazek=='<img src="'+sciezka+'icons/more.png">' || 
			  obrazek=='<IMG src="'+sciezka+'icons/more.png">') 
				$(parents[i]).children(':first').next().html('<IMG src="'+sciezka+'icons/less.png">');		 
				
			}
			$("a[href*='k_"+id_kat+"']").parents(":first").children(":last").css('display','block')
		}
	});	
	
});

/* ================================= */
/* PO ZAŁADOWANIU DOM+OBRAZKI        */
/* ================================= */

$(window).load(function(){
});


