$(document).ready(function(){
	dateWrite();
	dateWrite1();
	dateWrite2();
	$("a.galeria").fancybox();
	
	$("ul#partner").innerfade({
		speed: 1000,
		timeout: 5000,
		type: "sequence",
		containerheight: "128px"
	});
	
	$("ul#bannerFoto").innerfade({
		speed: 1000,
		timeout: 5000,
		type: "sequence",
		containerheight: "193px"
	});
	
	$("ul#liczby").innerfade({
		speed: 1000,
		timeout: 5000,
		type: "sequence",
		containerheight: "14px"
	});
	
	$('#coda-slider-1').codaSlider();
	$('#coda-slider-2').codaSlider();
	$('#coda-slider-3').codaSlider();
	$('#coda-slider-4').codaSlider();
	$('#coda-slider-5').codaSlider();
	$('#coda-slider-6').codaSlider();
	$('#coda-slider-7').codaSlider();
	$('#coda-slider-8').codaSlider();
	
	$("#commentForm").validate();
	
	$('form input, form textarea').focus(function() {
	    $(this).addClass('focus');
	  }).blur(function() {
	    $(this).removeClass('focus');
	  });
	    
	  $("#open-colorbox").colorbox({inline:true, href:"#form"});

	  
	  $("button#save").click(function(){
		  //kasujemy poprzednie bledy w formularzu
		  $('div.error-list').remove();
		  $('form *').removeClass('error');
		  // zmienna z ewentualnymi bledami
		  var errorlist = '';
		  //wysylamy zapytanie typu POST
		  $.ajax({
		    type: "POST",
		    dataType:"json",
		    cache: false,
		    data: $('form').serialize()+"&ajax=1",
		    success: function(msg){
		      if (msg.ok == 1)
		      {
		        //czynnosci wykonywane przy pomyslnym zapisie do bazy
		        alert('Treść wiadomości została wysłana');
		        //zamyka colorbox
		        $.colorbox.close();
		      }
		      else
		      {
		        //wyswietlanie bledow
		        $.each(msg, function(index, value) {
		          if (index =='all')
		            $('form input,form textarea').addClass('error');
		          else
		            $('#'+index).addClass('error');

		          errorlist += '<li>'+value+'</li>';
		        });
		        $("h2").after("<div class=\"error-list\"><p><strong>Wystąpiły blędy:</strong></p><ul>" +errorlist+"</ul></div>");
		        $.colorbox.resize();
		      }
		      return false;
		    }
		  });
		  return false;
		});
	  
	  $('#seoBar>div>a').show();
		$('#seoUkryte').hide();
		$("#seoBar div a").click(function() {
	   		var hidden = $(this).parents("div").children("p").is(":hidden");
			$("#seoBar>div>p").hide()        
		   	$("#seoBar>div>a").removeClass();
		   	if (hidden) {
		   		$(this)
			   		.parents("div").children("p").toggle()
			   		.parents("div").children("a").addClass("aSeo");
			   	} 
		   });
	
	
});

function mapaStart()  
{  
    if(GBrowserIsCompatible())  // sprawdzamy, czy przeglądarka jest kompatybilna  
    {  
        // tworzymy nowy obiekt mapy, i umieszczamy go w elemencie blokowym o ID "mapka"  
        var mapa = new GMap2(document.getElementById("mapka"));   
        mapa.setCenter(new GLatLng(54.2589254, 16.0576446),15); 
        mapa.addControl(new GLargeMapControl());
        // stworzenie markera  
                       var punkt  = new GLatLng(54.2569254, 16.0576446);  
                       var marker = new GMarker(punkt,{title: 'Pensjonat Solar'});  
                          
                       // dodanie markera na mapę  
                       mapa.addOverlay(marker); 

       // otwieramy okno informacyjne w punkcie (53.4193,14.5816)  
       mapa.openInfoWindowHtml(new GLatLng(54.2569254, 16.0576446),'<table><tr><td><img src="http://www.solar.mielno.pl/images/zdjecieMapa.jpg" style="border: 0;"></td><td><p style="color:#000000; padding: 0 0 0 10px">Pensjonat Solar</p><p style="line-height: 120%; font-size: 11px; color:#000000; padding: 0 0 0 10px">76-032 Mielno</p><p style="line-height: 120%; font-size: 11px; color:#000000; padding: 0 0 0 10px">ul. Północna 17</p></td></tr></table>');
       

    }  
}

function dateWrite()
{
$("#dateselect").datepicker({ 
dateFormat: "yy-mm-dd",
firstDay: 1, 
changeFirstDay: false, 
showOn: "both", 
buttonImage: "images/calendar.gif", 
buttonImageOnly: true 
});
}

function dateWrite1()
{
$("#dateselect1").datepicker({ 
dateFormat: "yy-mm-dd",
firstDay: 1, 
changeFirstDay: false,
showOn: "both", 
buttonImage: "images/calendar.gif", 
buttonImageOnly: true 
});
}

function dateWrite2()
{
$("#dateselect3, #dateselect4").datepicker({ 
dateFormat: "yy-mm-dd",
beforeShow: customRange,
firstDay: 1, 
changeFirstDay: false,
showOn: "both", 
buttonImage: "images/calendar.gif", 
buttonImageOnly: true 
});
}

function customRange(input) 
{ 
	return {
         minDate: (input.id == "dateselect4" ? $("#dateselect3").datepicker("getDate") : null)
       }; 
}

