$(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+'/';
	}

	

	/*
	 * 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 ==
	  */
	  
	
	  
	  /*
	   * 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 ==
	 */
	var foto;
	var SliderTime = 10000; //CZAS wyświetlania zdjęcia w PRODUKCYJNEJ WERSJI też ajaksem z CMSa
		
	var Photos = new Array(); //ARRAY na obiekty Fotek
	
	var Width = $(window).width();
	var Height = $(window).height();
	
	var origRatio = 1.8;
	
	var presentId = 0;
	var btnLock = 0;
	
	var autoDirection = 0;//0-left, 1-right;
	
	
	
	if($("#slider").length){
		var fotodir = 'file';
		
		
		$.post(siteurl+'modules/Glowna/panel.Glowna.php', {content: 'fotos'}, function(data){
			
			foto = data.split(",");
			
			$(window).bind("resize", resizeWindow); //EVENT na RESIZE OKNA
			
			for(i=0; i<foto.length; i++){ //Wczytanie fotek
				bufferPhoto(i);
				appendPhoto(i);
				resizePhoto(i);
				placePhoto(i);
			}
			
			$('#navi-prev').click(function(){//EVENT na klik poprzedniej foty
				if(btnLock==0){
					if(presentId<Photos.length-1){
						slidePhotosLeft();
					}
					if(presentId<Photos.length-1) presentId++;
				}
			});
			
			$('#navi-next').click(function(){//EVENT na klik kolejnej foty
				if(btnLock==0){
					if(presentId>0){
						slidePhotosRight();
					}
					if(presentId>0) presentId--;
				}
			});
			
			$.timer(SliderTime, function(timer){
				timerSlide();
			});
		});
		
		
		
	}
		function timerSlide(){
			if(autoDirection==0){
				if(btnLock==0){
					if(presentId<Photos.length-1){
						slidePhotosLeft();
					}else{
						autoDirection = 1;
					}
					if(presentId<Photos.length-1) presentId++;
				}
			}else{
				if(btnLock==0){
					if(presentId>0){
						slidePhotosRight();
					}else{
						autoDirection=0;
					}
					if(presentId>0) presentId--;
				}
			}
		}
		
		function bufferPhoto(id){ //BUFFER fotki i wrzucenie do arraya Image'ów
			var imgTesting = new Image();
			imgTesting.src = siteurl+fotodir+'/'+foto[id];
			Photos[id] = imgTesting;
			function CreateDelegate(contextObject, delegateMethod){
				return function(){
					return delegateMethod.apply(contextObject, arguments);
				}
			}
			function imgTesting_onload(){
				resizePhoto(id);
			}
			imgTesting.onload = CreateDelegate(imgTesting, imgTesting_onload);				
		}
		
		function appendPhoto(id){ //WSTAWIENIE fot do containera
			$('#slider-content').append('<img src="'+Photos[id].src+'" class="slider-photo" id="photo-'+id+'"/>');
		}
		
		function resizePhoto(id){//Resize fotki z danego id arraya fotek 
			var DOMid = '#photo-'+id;
			var w = $(DOMid).width();
			var h = $(DOMid).height();
			var ratio = w/h;
			var W = w;
			var H = h;
			
			if((Width/Height)>origRatio){
				W = Width;
				H = W/ratio;
			}else{
				H = Height;
				W = H*ratio;
			}
			if (/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent)){
				$(DOMid).css({'display':'block','width':W+'px', 'height':$(window).height()+'px', 'z-index':100-id});
			}else{
				if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
					 var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
					 if (ieversion>=9){
						$(DOMid).css({'display':'block','width':$(document).width(), 'height':H+'px', 'z-index':100-id});
					 }else{
						$(DOMid).css({'display':'block','width':W+'px', 'height':H+'px', 'z-index':100-id});
					 }
				}else{
					$(DOMid).css({'display':'block','width':W+'px', 'height':H+'px', 'z-index':100-id});
				}
			}
			
		}
		
		function placePhoto(id){//pozycjonowanie fotki z danego id arraya fotek
			var left = 0;
			
			for(i=0; i<id; i++){
				left += $('#photo-'+i).width();
			}
			$('#photo-'+id).css({'left':left+'px'});
		}
		
		function resizeWindow(){ //RESIZE okna
			Width = $(document).width();
			Height = $(window).height();
						
			for(i=0; i<foto.length; i++){
				resizePhoto(i);
			}
			for(i=0; i<Photos.length; i++){
				placePhoto(i);
			}
			
			var tmpLeft = 0;
			for(i=0; i<presentId; i++){
				tmpLeft -= $('#photo-'+i).width();
			}
			$('#slider-content').css({'left':tmpLeft+'px'});
		}

		function slidePhotosLeft(){//PRZESUNIĘCIE fot w lewo
			var tmpLeft = $('#slider-content').css('left');
			tmpLeft = tmpLeft.substring(0, tmpLeft.length-2);
			
			var currentLeft = 0;
			currentLeft = parseInt(tmpLeft);
			currentLeft = (isNaN(currentLeft)?0:currentLeft);
			
			tmpLeft = $('#photo-'+presentId).css('width');
			tmpLeft = tmpLeft.substring(0, tmpLeft.length-2);
			
			var moveLeft = parseInt(tmpLeft);
			moveLeft = currentLeft - moveLeft;
			
			btnLock = 1;
			
			$('#slider-content').animate({left: moveLeft+'px'},500,function(){
				btnLock = 0;
			});
		}
		
		function slidePhotosRight(){//PRZESUNIĘCIE fot w prawo
			var tmpLeft = $('#slider-content').css('left');
			tmpLeft = tmpLeft.substring(0, tmpLeft.length-2);
			
			var currentLeft = 0;
			currentLeft = parseInt(tmpLeft);
			currentLeft = (isNaN(currentLeft)?0:currentLeft);
			
			tmpLeft = $('#photo-'+presentId).css('width');
			tmpLeft = tmpLeft.substring(0, tmpLeft.length-2);
			var moveLeft = parseInt(tmpLeft);
			moveLeft = currentLeft + moveLeft;
			
			btnLock = 1;
			
			$('#slider-content').animate({left:moveLeft+'px'},500,function(){
				btnLock = 0;
			});
		}
	
	  
	/*
	 * slideshow tła
	 */
	  
	  
	  
	  
	 /*
	 * slideshow tła == end ==
	 */ 
	  
	  
	  
	  
	$(function() {
		$('.foto-gal').lightBox();
	});
	
	/*
	 * sticky notes
	 */
	if($('.corktable').length){
		$('.note').draggable({containment : '.corkmid', distance : 20});
		$('.note').bind('dblclick',function(){
			var href = $(this).children('p').children('.wiecej').attr('href');
			if(href !== undefined) window.location = href;
			
		})
	}

	/*
	 * sticky notes == end ==
	 */	
	  
	if($("#map").length){
		load();
	}
});

/*
 * 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.16762005865853, 22.280852794647217), 13);

	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.16762005865853, 22.280852794647217);
			map.addOverlay(createMarker(point, 0, "<b>Formacja Tańca Nowoczesnego LUZ,<br/>Alternatywny Teatr Tańca LUZ</b><br>ul. Pułaskiego 7<br>08-110 Siedlce"));
			var point = new GLatLng(52.169775800731195, 22.275906801223755);
			map.addOverlay(createMarker(point, 1, "<b>Akademia Tańca LUZ - ART</b><br>ul. Świrskiego 50A<br>08-110 Siedlce"));
		
 }
 }
 
  

