jQuery(document).ready(function(){
	
	
	var dostawa_div = $("#dostawa div");
	dostawa_div.click(function(){
		var sel_div = $(this).children('span');
		
		if (sel_div.attr('class') == '17')
			$("#box_adres").hide();
		else
			$("#box_adres").show();
	});
	

	
	
	//radio w koszyku (wybor opcji faktury/adresu)
	$("input:radio[name=faktura]").change(function() {
		var wartosc = $(this).val();
		//alert(wartosc);
            if(wartosc == 2) {
				$("#dane_powyzej").show();
			}
			else {
				$("#dane_powyzej").hide();
			}
			
});
	
	
	$("#search_header .select").mouseover(function(){
		$(this).addClass("select_hover");
	}).mouseout(function(){
		$(this).removeClass("select_hover");
	});
	
	$("#search_header .phrase").focus(function(){
		$(this).addClass("phrase_hover");
	});
	
	if($.trim($("#search_header .phrase").val())!="") {
		$("#search_header .phrase").addClass("phrase_hover");
	}
	
	/*.blur(function(){
		$(this).removeClass("phrase_hover").val("");
	});*/
	
	
	
	$("#submenu .item").mouseover(function(){
		$(this).addClass("item_hover");
		var curr = $(this);
		curr.prev(".sep_items").addClass("sep_items_hover");
		curr.next(".sep_items").addClass("sep_items_hover");
		$("#submenu .item .overlay").hide();
		$(this).children(".overlay").show();
	}).mouseout(function(){
		//$(this).removeClass("item_hover");
		//var curr = $(this);
		//curr.prev(".sep_items").removeClass("sep_items_hover");
		//curr.next(".sep_items").removeClass("sep_items_hover");
	});
	
	$("#submenu .item").mouseleave(function(){
		$(this).children('.overlay').hide();
		$(this).removeClass("item_hover");
		var curr = $(this);
		curr.prev(".sep_items").removeClass("sep_items_hover");
		curr.next(".sep_items").removeClass("sep_items_hover");
	});
	
	
	
		zIndexWorkaround();
	
	

	
	$(".offer_item .button, .standard_button").each(function(i,e){
		divWidth = parseInt( $(this).children("div").css("width"));
		$(this).css("width", divWidth+30); /*14 orginal a 2 ponzej linie do kasacji */
		$(this).children().css("width", divWidth+16);
		$(this).children().css("text-align", 'center');
	});
	
	/* biuletyn */
	$(".radio_button").click(function(){
		if(!$(this).hasClass("radio_button_on")) {
			$(this).siblings(".radio_button").removeClass("radio_button_on");
			$(this).addClass("radio_button_on");
			/* akcja zmiany wartosci jakiegos inputa */
		}
	});
	
	
	if(!isIE()){
	
	$("#bottom #newsletter .mail").focus(function(){
		$(this).addClass("mail_hover");
	});
  
	
	 if($("#bottom #newsletter .mail").val()!="") {
		$("#bottom #newsletter .mail").addClass("mail_hover");
	} 
	
	}
	
	
	
	
	
	/* select_box */
	$(".select_box .select").click(function(){
		$(this).siblings(".sub").show();
	});
	
	$(".select_box .select_open").click(function(){
		$(this).parent().hide();
	});
	
	$(".select_box .items div").mouseover(function(){
	
		$(this).siblings().removeClass("hover");
		$(this).parent().siblings(".footer").removeClass("hover");
		$(this).addClass("hover");
		
		if($(this).hasClass("last")) {
			$(this).parent().siblings(".footer").addClass("hover");
		}
	}).click(function(){
		$(this).parent().parent().hide();
	});
	
	
	
	$(".select_box").each(function(i,e){
		var w = parseInt($(this).css("width")); // szerokosc select_boxa
		var wa = parseInt($(this).children(".select").children(".arrow").css("width"));
		w = w-wa;
		
		var value = $(this).children(".select").children(".value");
		var sub = $(this).children(".sub"); 
		var items = sub.children(".items");
		var div = items.children("div");
		
		// szerokosc etykiety
		var a = w-parseInt(value.css("padding-left"))-parseInt(value.css("padding-right"));
		value.css("width", a);
		value.children("input").css("width",a);
		value.children("input").keydown(function(event) {
			　if (event.keyCode != '13' && event.keyCode != '9') {
			　　 event.preventDefault();
			　 }}
		);
		sub.children(".select_open").children(".value").css("width",a);
		
		// szerokosc listy elementow		
		items.css("width", w);
		
		// szerokosc elementu listy elementow
		var b = w-parseInt(div.css("padding-left"));
		div.css("width",b);
		
		// szerokosc ostatniego elementu listy elementow
		sub.children(".footer").children(".center").css("width",b-1);
	});
	
	
	/* end select_box functions */

	$(".select_box .items div").click(function(){
	
			 if(!$(this).hasClass('link')){
				
				var select_box = $(this).parent('.items').parent('div').parent('.select_box');    //$("#search_header .select_box");
				var val = $(this).text();
			
				//val = val.replace(/ <div(.*)<\/div>/g, ""); //wywal divy - mozna poprawic na ladniejsza funkcje...
				
				
				select_box.children(".select").children(".value").children("input").val(val); //umieszcza nazwe kategorii w inpucie
				
				
				
						if($(this).children('div').attr('class')) {
							 var id_kat = $(this).children('div').attr('class').replace(/id_cat kategoria_/g, ""); //wez numer
							name = $(this).parent('.items').children('input[type="hidden"]').attr("value", id_kat);	
						}
       
				}
		
	});
	
	
	
	$('.dest_items .dest_item:odd').addClass('odd');
	$('.event_item .inside p:first').addClass('nomargin');
	
	
		
	//pseudo-checkboxy jako input hidden w koszyku
	$('div.checkbox').click(function(){
	  
		if(!$(this).children('.field').hasClass('checked')  ){
	   $(this).children('.field').addClass('checked');
		 
		 var inputName = $(' div.field span', this).attr('class');
		 var val = $(' div.field span', this).attr('title');
		 
		 
		 
		 $(this).children('.field').after('<input type="hidden" value="'+val+'" name='+inputName+' />');
		 
		}
		else {
		 $(this).children('.field').removeClass('checked');
		 $(this).children('input').remove();
		}
	});
	
	
	
	$('.cups').each(function(index, elem){

	  var numb = $(elem).html().substr(0,1);
			
		$(elem).html("");
		
		var new_html = "";
		
		//pełne kubeczki
		for(var i=0; i<numb; i++){ new_html = new_html + '<span class="cup"></span>';	}
		var amp = 5-numb;
		
		//puste kubeczki
		for(var i=0; i<amp; i++){  new_html = new_html + '<span class="cup_empty"></span>';	}
		
		$(elem).html(new_html);
		
}); 
  
	
	
	
	//radio uniwersalne
	$('div div.radiobuttons').click(function(){
	  
		if(!$(this).children('.field').hasClass('checked')){
	
	   var name = $(this).parent('div').attr('id');
		 var value = $(this).children('span').attr('class');
	
	
	   $('div#'+name+' div.radiobuttons .field').removeClass('checked');
		 $(this).children('.field').addClass('checked');

		 $('input[name="'+name+'"]').attr('value', value);
		 
		 if($(this).hasClass('firstLevel')){
		    //jesli trzeba pokazac kolejny level
				
		    //domyslnie - schowane wszystkie
				$('div.secondLevel div.radiobuttons').hide();
	
				//wyzeruj zaznaczenie
				$('div.secondLevel input').attr("value", 0);
				
				//pokaz opcje nalezace do tego levelu
				$('div.secondLevel div.radiobuttons.option_'+value).show();
		 }
		 
	  }
	});
	
	
	
	
$('#platnosc .radiobuttons, #dostawa .radiobuttons').click(function(){


	if ( $('input[name="platnosc"]').attr("value") > 0 && $('input[name="dostawa"]').attr("value") >0  ) {

		 $('div#form_submit').show();
     $('div#form_submit button').removeAttr("disabled");

	}
	else {
	    $('div#form_submit').hide();
			$('div#form_submit button').attr("disabled", "disabled");
	}

});	
	
	
	
	
	/* rotacja - do promocji i nowości */

	
	$('.rotator .rot_item .arrow').click(function(){
	  var element = $(this).parents('.rot_item');
		
	  var count = element.parent('.rotator').children('.rot_item').length;  //ile elementow
		var indeks = element.index();  //numer elementu
		var nowy=1;
		
		
		if( $(this).hasClass('arrow_right') ) { //minus
				if(indeks<1) nowy = count-1;
				else         nowy = indeks-1;
		} else if ($(this).hasClass('arrow_left') ){ //plus
		   if(indeks+1>=count) nowy = 0;
			 else           nowy = indeks+1;
		} //else nic nie rob
			
		$(element.parent('.rotator').children('.rot_item').get(indeks)).addClass('hidden');
	  $(element.parent('.rotator').children('.rot_item').get(nowy)).removeClass('hidden');

	});
	
	
	/* rating - gwiazdki */
	
	
	//hidden input - przy załozeniu ze jest jeden rating
	
	$('.rating').each(function(i,e){
	    var hidden_radio =  $(this).children('input[type="radio"]').attr('name');
			
			var selected = $(this).children('input[type="radio"]:checked').attr('value');
			
			selected = (selected)?selected:0;
			
	  $(this).children('strong').after('<input type="hidden" name="'+hidden_radio+'" value="'+selected+'" />')
	
	});
	

		//usuwamy radio
	$('.rating input[type=radio]').each(function(i,e){
	
	    var value = $(this).attr('value');
			var active = $(this).parent('.rating').children('input[type="radio"]:checked').attr('value');
			
			 active = (active >= value)?'clicked_star':'';
			
			var link = '<a class="link star '+active+'" title="'+value+'" href="#'+value+'"></a>';

			
			   
			
	     $(this).after(link);  
			 
			 $(this).remove();
	});
	
	//kolorowanie
	
	$('.rating a.link').mouseover(function(){
				$(this).prevAll('a').andSelf().addClass('active_star');		
	}).mouseout(function(){
				$(this).prevAll('a').andSelf().removeClass('active_star');			
	}).click(function(){
	   
		  $(this).nextAll('a').removeClass('clicked_star');
			$(this).prevAll('a').andSelf().addClass('clicked_star');
			
			var value = $(this).attr('title');
	
	    $(this).parent('.rating').children('input[type="hidden"]').attr('value', value);
	
	   return false;
	});
	
	
	//generator gwiazdek; 
	{
	  var ocena =  parseFloat( $('.overall_note .stars').html(), "" );
		var html = "";
		
		for(var i = 1 ; i <= 5; i++){
		   
		  if(i <= ocena) {
			  
				reszta = ocena - i;
			
			   if(reszta >= 0.5 && reszta < 1)
					 html = html+'<span class="star half_star"></span>';
				 else
		       html = html+'<span class="star coloured_star"></span>';
			 }
			else 
			   html = html+'<span class="star"></span>';
		}
		
		$('.overall_note .stars').html(html);
	
	}
	
	/* opinie - pokaż wszystkie */
	
	$('div.allOpinions').click(function(){
     $(this).remove();
		 
		 $('.opinion').removeClass('hidden');
	});
	
	
	
	/* autocomplete - wyłącz */
	
	$('input.off, input#kcaptcha').each(function(i,e){
	  var pole = this;
    pole.setAttribute("autocomplete", "off");

	});
	
	
	
	/* mess box */
	
	
	$('#message_box div a.close').after('<div class="top"></div><div class="bottom"></div>');
	
	if(!isIE()) {
	   $('#message_box').delay(2500).fadeOut(600);
	}
	
	$('#message_box .close, #message_box').click( function(){
	    $('#message_box').hide();
			return false;
	});

	

});
	
	
	


Cufon.replace(".product_box h2, #submenu h1", {
  hover: {
	  fontFamily: "Myriad Pro",
		color: "#604F47"
	 }
	});
	
Cufon.replace("#profile_menu h2", {
  hover: true,
	fontFamily: "Myriad Pro"
	});
 

Cufon.replace("h1,h2", {fontFamily: "Myriad Pro"});
Cufon.replace(".cufon_myriad", {fontFamily: "Myriad Pro"});
Cufon.replace(".inci .ingredient", {fontFamily: "Stencil"});


function isIE() {
	 if(navigator.userAgent.match(/MSIE \d\.\d+/))  {
		 return true;  
	 }
	 return false;  
}



function zIndexWorkaround() {
	// If the browser is IE,  
	if(isIE())
	{  
		$("div.overlay, div.sub, div.message_box div").parents().each(function(i,e){
			var p = $(this);
			var pos = p.css("position");
			
			// If it's positioned,  
			if(pos == "relative" ||  pos == "absolute" || pos == "fixed") {
				p.hover(function(){
					$(this).addClass("on-top");  
				},  
				function() {  
					$(this).removeClass("on-top");  
				}); 
			}  
		});  
	}  
}



