$(document).ready(function(){
	var siteurl ='http://mok.siedlce.pl/';
	
	 
	var obj = $(this);
	
	/*
	 * 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 ==
	 */
	  
	  
	  
	  
	  
	if($("#map").length){
		load();
	}
	
	/* 
	 * Gray tabs
	 */
	//grayscale($(".gray"));

	$(".gray").css({'position':'relative'});
	 
	$(".gray").hover(function(){
		//grayscale.reset($(this));
		$(this).stop(true, true).animate({
			top: '-30px',
			left: '23px'
		}, 500, function() {
			// Animation complete.
		});

	},function(){
		//grayscale($(this));
		$(this).stop(true, true).animate({
			top: '0px',
			left: '0px'
		}, 500, function() {
		// Animation complete.
		});
	});
	
	$(function() {
		$('#galeria .foto a').lightBox({fixedNavigation:true});
	});
	
	
	/* kalendarz */
	post_data();

		function post_data(){
		
			$(".cal-day").mouseover(function(){
				$("body",obj).append('<div id="podpowiedz"></div>');
			});
		
		
			$(".cal-day").mousemove(function(e){

			this.top = e.pageY+15;
			this.left = e.pageX+10;
			
			$("#podpowiedz").addClass("show-hover").css("top", this.top+"px").css("left", this.left-400+"px").css("width", 400+"px").css("opacity", 0.8);		

			$("#podpowiedz").slideDown('slow', function() {

			
			// Animation complete.
			});
			
			$.post(siteurl+'modules/Kalendarz/panel.Kalendarz.php', {data: $(this).attr("id")}, function(data){
					$("#podpowiedz").empty();
					$("#podpowiedz").append(data);
				});

			//post_data();
		});
		
		$(".cal-day").mouseout(function(){
			
			$("#podpowiedz").slideUp('slow', function() {
			// Animation complete.
			});
			$("#podpowiedz").detach();

			//post_data();
		});
			$(".cal-change").click(function(e){
				$.post(siteurl+'modules/Kalendarz/panel.Kalendarz.php', {miesiac: $(this).attr("id")}, function(data){
					$("#kalendarz").empty();
					$("#kalendarz").append(data);
					
					post_data();

				});
			});
		}
	
	
	
	
	
	/* kalendarz end */
	
	/* 
	 * Sonda
     */
	var cookmonsta = $.cookie("sonda");
	$("#send").click(function(){
		
		var id = $(".sonda:checked").attr('title');
		var son = $("#sonid").val();
		cookmonsta = son+' '+id;
		//alert(son);
		
		$.post(siteurl+'modules/Sonda/panel.Sonda.php', { which: id, sonda: son},
		function(data){
			$.cookie("sonda", cookmonsta, { path: '/', expires: 30 });
			$("#ss").fadeOut('slow',function(){
				$("#sonda").append(data);
				$("#sw").fadeIn('slow',function(){
				// complete
				});
			});
			
		});
	});
	
	if($("#tabs").length){
		$("#tabs").tabs();
	}
	
	/* oceny */
	
	$(".gray-star").hover(function(){
		var obj = $(this);
		obj.addClass('stop');
		var index = 0;
		obj.parent().children().each(function (idx) {
			$(this).css('background','url(\''+siteurl+'gfx/bkg-star-orange.png\') no-repeat');
			if ($(this).is(".stop")) {
				index = idx;
				return false;
			}
		});
				
	}, function(){
		var obj = $(this);
		
		obj.removeClass('stop');
		$(".gray-star").each(function () {
			$(this).css('background','url(\''+siteurl+'gfx/bkg-star-gray.png\') no-repeat');
		});
	});
	
	$(".gray-star").click(function(){
	
		var obj = $(this);
	
		var idArray = obj.attr('class').split(' ');
		var id = idArray[1];
		
		var ocArray = obj.attr('class').split(' ');
		var oc = idArray[2];
		
		var tableArr = obj.parent().attr('class').split(' ');
		var table = tableArr[1];
		
		var cookmonsta = table+' '+id;
		$.post(siteurl+'modules/Oceny/panel.Oceny.php', { which: id, tab: table, ocena: oc},
		function(data){
		//alert(data);
			$.cookie("ocena", cookmonsta, { path: '/', expires: 30 });
		});
	});
	
	$(".m").click(function(){
		var href = $(this).attr('href');
		
		var cook = href;
		$.cookie("menu", cook, { path: '/', expires: 30 });
		
	});
	
});

/*
 * google maps
 */
    function load() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));

map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());

	
    map.setCenter(new GLatLng(52.16756478168258, 22.280412912368774), 14);

	var baseIcon = new GIcon();
baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
baseIcon.iconSize = new GSize(20, 34);
baseIcon.shadowSize = new GSize(37, 34);
baseIcon.iconAnchor = new GPoint(9, 34);
baseIcon.infoWindowAnchor = new GPoint(9, 2);
baseIcon.infoShadowAnchor = new GPoint(18, 25);

function createMarker(point, index, description) {
  
  // Create a lettered icon for this point using our icon class
  var letter = String.fromCharCode("A".charCodeAt(0) + index);
  var icon = new GIcon(baseIcon);
  icon.image = "http://www.google.com/mapfiles/marker" + letter + ".png";
  var marker = new GMarker(point, icon);
  
  
  
  GEvent.addListener(marker, "click", function() {
      marker.openInfoWindowHtml(description);
  });
  
  return marker;
}

// Add 10 markers to the map at random locations
  var bounds = map.getBounds();
var southWest = bounds.getSouthWest();
var northEast = bounds.getNorthEast();
var lngSpan = northEast.lng() - southWest.lng();
var latSpan = northEast.lat() - southWest.lat();

			var point = new GLatLng(52.16756478168258, 22.280412912368774);
			map.addOverlay(createMarker(point, 0, "<b>Miejski Ośrodek Kultury w Siedlcach</b><br>ul. Pułaskiego 6<br>08-110 Siedlce"));
		
 }
 }
 
  

