$(document).ready(function(){
	var siteurl = '';
	var hostArray = window.location.host.split(".");
	
	if(hostArray[0]=='www'){
		siteurl = 'http://'+window.location.host.substr(4)+'/';
	}else{
		siteurl ='http://'+window.location.host+'/';
	}
	
	

	/*
	 * obsługa koszyka
	 */
	$('.do_koszyka').click(function(){
		var id = $(this).attr('id').split('_')[1];
		$.post(siteurl+"module/Koszyk/panel.Koszyk.php", { doKoszyka: id},
		   function(data){
				var dane = data.split(';');
				if($('#ul-koszyk').length==0){
					$('#koszyk').empty();
					$('#koszyk').append('<ul id="ul-koszyk"><li><span class="grey">'+dane[0]+'</span><span>'+dane[1]+' zł</span></li></ul><a href="#" class="wiecej" id="oproznij-koszyk">Opróżnij</a><a href="./Koszyk,kasa" class="wiecej" style="margin-left:35px;">Do kasy</a>');
						$('#oproznij-koszyk').click(function(){
						   if(confirm('Czy napewno chcesz opróżnić koszyk?')){
							$.post(siteurl+"module/Koszyk/panel.Koszyk.php", { doKoszyka: '-1'},
							   function(data){
									$('#ul-koszyk').detach();
									$('#koszyk').empty();
									$('#koszyk').append('<span class="grey">Koszyk jest pusty.</span>');
							   });
						   }
						});
				}else{
					$('#ul-koszyk').append('<li><span class="grey">'+dane[0]+'</span><span>'+dane[1]+'zł</span></li>');
				}
				
		   });

	});
	$('#oproznij-koszyk').click(function(){
		if(confirm('Czy napewno chcesz opróżnić koszyk?')){
			$.post(siteurl+"module/Koszyk/panel.Koszyk.php", { doKoszyka: '-1'},
			   function(data){
					
					$('#ul-koszyk').detach();
					$('#koszyk').empty();
					$('#koszyk').append('<span class="grey">Koszyk jest pusty.</span>');
			   });
		}
	});
	$('.usun_prod').click(function(){
		if(confirm('Czy napewno chcesz usunąć ten element z koszyka?')){
			var id = $(this).attr('id').split('_')[1];
			$.post(siteurl+"module/Koszyk/panel.Koszyk.php", { usun: id},
			   function(data){
				location.reload();
			});
		}
		
	});
	
	//
	// zmiana liczby sztuk w koszyku
	//
	$(".up").click(function(){
		var id = $(this).attr('id');
		id = id.split('_');
		
		if(id[0]=='additem'){//dodawanie do koszyka
			$.post(siteurl+"module/Koszyk/panel.Koszyk.php", { doKoszyka: id[1]},
				function(data){
					location.reload();
				}
			);
		}
	});
	
	$(".down").click(function(){
		var id = $(this).attr('id');
		id = id.split('_');
		
			if(id[0]=='delitem'){//usuwanie z koszyka
				$.post(siteurl+"module/Koszyk/panel.Koszyk.php", { zKoszyka: id[1]},
					function(data){
						location.reload();
					}
				);
			}
		});

	 /*
	 * obsługa koszyka == end ==
	 */


	/*
	 * obsługa menu
	 */
	var ciacho = $.cookie("menu");
	if(ciacho!=null){
		
			$("#left .main").find(".plus").each(function(){
				if(ciacho.indexOf($(this).next('a').attr('href'))!=-1){
					$(this).removeClass('plus').addClass('minus');
					$(this).parent().children('.sub').slideToggle('slow',function(){});
				}
			});
	}

	$('#left .plus').click(function(){
		if($(this).parent().children('.sub').is(':visible')){
			$(this).removeClass('minus').addClass('plus');
			
		}else{
			$(this).removeClass('plus').addClass('minus');
		}
			$(this).parent().children('.sub').slideToggle('slow',function(){});
			ciacho = '';
			$("#left .main").find(".minus").each(function(){
				ciacho += $(this).next('a').attr('href')+";";
			});
			$.cookie("menu", ciacho, { path: '/', expires: 1 });
	});
	
	$('#left .minus').click(function(){
		if($(this).parent().children('.sub').is(':visible')){
			$(this).removeClass('minus').addClass('plus');
			
		}else{
			$(this).removeClass('plus').addClass('minus');
		}
		
		$(this).parent().children('.sub').slideToggle('slow',function(){});
		ciacho = '';
			$("#left .main").find(".minus").each(function(){
				ciacho += $(this).next('a').attr('href')+";";
			});
			$.cookie("menu", ciacho, { path: '/', expires: 1 });
	});
	/*
	 * obsługa menu == end ==
	 */

	/*
	 * licznik znaków w formie
	 */
	function checkLength(ob,len){
		if($(ob).val().length<len){
			a = $(ob).val().length;
			b = len-1;
			c = b-a;
			$(".charCount", $(ob).parent().parent().parent()).empty();
			$(".charCount", $(ob).parent().parent().parent()).append(""+c+"");
		}else{
			alert('Przekroczono dozwoloną liczbę znaków!!!');
			$(ob).val($(ob).val().substring(0, len-1));
		}
	}
	
	$(".checkLength").focus(function(){
		checkLength($(this),150);
	});
	
	$(".checkLength").keydown(function(){
		checkLength($(this),150);
	});
	 /*
	  * licznik znaków == end ==
	  */
	  
	/*
	 * form komentowania - pokaż/ukryj
	 */
	 
	 $("#show_hide").toggle(function(){
		$("#komentarz").show('blind',{},700);
	 },
	 function(){
		$("#komentarz").hide('blind',{},700);
	 });
	 
	 /*
	  * form komentowania - pokaż/ukryj == end ==
	  */
	  
	  /*
	   * info dl aie6 ;p
	   */
	  
	  if($.browser.msie && $.browser.version=="6.0")
	  {
			var tresc = '<p style="color:#d00; clear:both; font-weight:bolder; width:500px;">Twoja przeglądarka jest przestarzała i nie wspiera wielu standardów.</p><p style=" width:500px;">Jeśli chcesz przeglądać internet szybciej i bezpieczniej, pobierz nowoczesną przeglądarkę:</p><ul style=" width:500px;"><li><a href="http://www.opera.com/browser/download/">Operę</a></li><li><a href="http://download.mozilla.org/">Firefoksa</a></li><li><a href="http://www.google.pl/chrome/eula.html">Google Chrome</a></li><li>lub ostatecznie <a href="http://www.microsoft.com/poland/windows/internet-explorer/worldwide-sites.aspx">IE 8</a></li></ul>';
			$("body").append('<div id="bkd"></div><div id="foto-big"><a href="#" id="foto-close"></a></div>');
			
			$("#foto-big").append('<div id="foto-mid" style="width:120px; height:120px;">'+tresc+'</div>');
			
			
			$("#bkd").animate({opacity:0.0}, 10, function(){
				$(this).show().animate({opacity:0.7}, 500, function(){
					$("#foto-big").show('scale', {percent: 100},500,function(){
					var totalH = $(document).height()+50;
					$("#bkd").css('height',totalH+"px");
				});
				});				
			});
			
			$("#foto-close").click(function(){
					close();
				}); 
			
			$("#bkd").click(function(){
					close();
			});			
	}
	
	function close(){
		$("#foto-big").hide('scale',{percent: 0},500,function(){
					$("#foto-big").detach();
					$("#bkd").animate({opacity:0.0}, 500, function(){
						$(this).detach();
					});
				});
	}
	/*
	 * info dla ie6 == end ==
	 */
	  
	  
	 /*
	* usuwanie treści inputów
	*/
	$("input:text").focus(function(){
		if(!$(this).hasClass('edited')){
		$(this).val('');
		$(this).addClass('edited');
		}
	});
	$("textarea").focus(function(){
		if(!$(this).hasClass('edited')){
		$(this).val('');
		$(this).addClass('edited');
		}
	});
	/*
	* usuwanie treści inputów == end ==
	*/ 
	  
	
	  
	
	
	
	if($(".paging").length){
		$(".paging").bind('click', paging);
	}
	
	function paging(){
		var id = $(this).attr('id').split('_')[1];
		
		$.post(siteurl+"modules/Newsy/panel.Newsy.php", {ajax_news: id}, function(data){
			  if(data!=""){
				$("#news").empty();
				$("#news").append(data);
				$(".paging").bind('click', paging);
			  }
		   }
		 );
	 }
	
	
	
	if($(".foto-gal").length){
		$(".foto-gal").lightBox();
	}
	  
	  
	 if($("#map").length){
		load();
	}
});

/*
 * google maps
 */
    function load() {
      var myOptions = {
		zoom: 13,
		center: new google.maps.LatLng(52.17358428642868, 22.272382378578186),
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	var map = new google.maps.Map(document.getElementById('map'),myOptions);
	var position = new google.maps.LatLng(52.17358428642868, 22.272382378578186);	
	var marker = new google.maps.Marker({position: position, map: map});
	
	
	marker.setTitle('tytul');
	var infowindow = new google.maps.InfoWindow({content: 'Studio Pielęgnacji Dłoni i Stóp BETA<br>08-110 Siedlce<br>ul. Sokołowska 36'});
	google.maps.event.addListener(marker, 'click', function() {
		infowindow.open(marker.get('map'), marker);
	});
 }
 
  

