// JavaScript Document
var loaderImg = '<img id="loader" src="images/loader.gif" alt="Loading..." />';  // Lader
//Rotator global variable
var mn = 0;				//
var current_x =0;		//
//------End---------------

function getUrl(file,contener)
{
	$('#'+contener.toString()).html(loaderImg);   
	$('#'+contener.toString()).load(file.toString(), function(){ 
    $("#loader").hide(); 
	
	});
	$('#'+contener.toString()).hide(); 
	$('#'+contener.toString()).fadeIn(500);


}
function getUrlNoLoad(file,contener)
{
	$('#'+contener.toString()).load(file.toString())
}

function sendForm(form,div)
{			
			var url = $('#'+form).attr('action');
			var met = $('#'+form).attr('method');				
			var data;
		
			$('#'+div).append(loaderImg);  
			$('#'+form+' :input').each
			(
				function (elementIndex)
				{
					var name = $(this).attr('name');
					var value = $(this).val();
 
					if (data == null)
						data = name+'='+value;
					else
						data += '&'+name+'='+value;
				}
			);
			$('#'+form+' textarea').each
			(
				function (i)
				{
					var name = $(this).attr('name');
					var value = $(this).val();
 
					if (data == null)
						data += name+'='+value;
					else
						data += '&'+name+'='+value;
				}
			);
			$.ajax
			(
				{					
					type: met,
					url: url,
					data: data,
 
					error: function (XMLHttpRequest, textStatus, errorThrown)
					{
						$('#'+div).show();
						$('#'+div).append('Bladd obiektu o nazwie:'+XMLHttpRequest+'<br />Komunikat:'+textStatus+'<br />Rodzaj:'+ errorThrown);
					},
					success: function(html)
					{
						$('#'+div).fadeIn('slow').html(html);
					}
				}
			); 
	}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function textSizeChange(s){
	createCookie('textSize',s,100);
	$("#textRead").animate({ 
    fontSize: parseInt(s)+"px", 
    lineHeight: (parseInt(s)+8)+"px"
  }, 200 );
	
}
function showIt()
{
	$("#toNewsletter").css('display','none');
	$("#form").addClass("showDiv").show("slow");
	
}
//Main hotel menu controller//
function initHotelMenu()
{
$("#hotelMenu li").click(function () { 

	if(!$(this).hasClass('current'))
	{
	 var id = $(this).attr('id');
 	 $('#hotelMenu').children().removeClass();
 	 $(this).addClass('current').fadeIn('slow');
	  $('#mainImgCont').fadeTo('fast', 0.3, function()
			{
			    $(this).css('background-image', 'url(img/' + id + 'bg.jpg)');
			}).fadeTo('fast', 1);
		 	 
		showHotelPromo(id);
	}
	})
$(".mapButton").click(function () { 

	 var id = $(this).attr('href');
 	 $('#'+id).fadeIn('slow');
 	  $('#'+id+' div').fadeIn('slow');
 	  setInterval("$('#"+id+" div img').fadeToggle();",1000);
 
 	  
 	 return false;
	})
$("#opiniaTxt").click(function () { 

	$('#addFeedback').animate({ 
    height: "350px"
  	}, 200 );
  	$('#opiniaTxt').animate({ 
    height: "200px"
  	}, 200 );
	})
$("#closeFeedback").click(function () { 

	$('#addFeedback').animate({ 
    height: "50px"
  	}, 200 );
  	$('#opiniaTxt').animate({ 
    height: "24px"
  	}, 200 );
	})
$(".mapa").click(function () { 

	$(this).fadeOut('slow');

 	 return false;
	})
}
function showHotelPromo(id)
{

	$('.promoContent div').css('display','none');
	$('.promoContent div').css('height','0px;');
	
	$('#info'+id+' img').css('display','none');
	 $('#info'+id).fadeIn('fast');
	$('#info'+id+' img').each(function(i) {
	setTimeout(function() {
    $('#info'+id+' #'+id+'type'+parseInt(i)).fadeIn('slow');
    }, 300*i);
	
	    
	  });
	 
}    
function sendFeedback()
{
	if($('#opiniaTxt').val()=='Dodaj swoją opinię')
	{
	$('#opiniaTxt').val('');
	}
if($('#opiniaIm').val()=='Podpis')
{
$('#opiniaIm').val('');
}

	if($("#feedbackForm").validate().form()== true)
	{
	$('#closeFeedback').trigger('click');sendForm('feedbackForm','addFeedback'); 
	return false;
	}else
	{
	return false;
	}
}

//Gallery init
$(document).ready(function() {

//wielkosc tekstu na stronie
	    var fontSize = readCookie("textSize") 
	    if(fontSize != null){  
		    $('.textBox').css('font-size',fontSize+'px'); 
		    $('.textBox').css('line-height',(parseInt(fontSize)+8)+'px'); 
		}else{
		    $('.textBox').css('font-size','12px'); 
		}

//Labele na inputach
			$(":text,textarea").labelify();
//OnScreen box init
			 $('a[rel*=facebox]').facebox();
//Gallery init
			$("a[rel=gallery_g]").fancybox({
				'transitionIn'		: 'elastic',
				'transitionOut'		: 'elastic',
				'titlePosition' 	: 'over',
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over"> ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
			});
//Walidacja danych w formularzeach
/////////Newsletter
			$("#newsletterForm").validate({
				
				rules: {
					mail: {
						required: true,
						email: true,
						remote: "mailCheck.php"
					}
				},
				messages: {
					mail: {
						required: "Podaj adres e-mail",
						email: "Podaj prawidłowy e-mail",
						remote: 'Ten adres już jest w naszej bazie'
						
					}
				}
			});
/////////Formularz kontaktowy
			$("#contactForm").validate({
		rules: {
			imie: {
				required: true,
				minlength: 2
			},
			tel: {
				required: true
			},
			mail_oso: {
				required: true,
				email: true
			},
			agree: "required"
		},
		messages: {
			imie: {
				required: "Podaj swoje imię",
				minlength: "Imię jest trochę za krótkie"
			},
			tel: {
				required: "Podaj telefon kontakowy."
			},
			mail_oso: {
				required: "Podaj adres e-mail. ",
				email: "Podaj prawidłowy adres e-mail"
				
			},
			agree: "Prosimy o wyrażenie zgody. W przeciwnym wypadku nie będziemy mogli dostarczyć jej do odpowiedniej osoby."
			}
		});
/////////Formularz opinie
			$("#feedbackForm").validate({
		rules: {
			feedback: {
				required: true,
				minlength: 2
			},
			im: {
				required: true,
				minlength: 2
			}
		},
		messages: {
			feedback: {
				required: "Brak opinii",
				minlength: "Opinia jest za krótka"
			},
			im: {
				required: "Brak podpisu",
				minlength: "Podpis jest za krótki"
			}
		}
		});
////-------------Koniec walidacji formularzy-----------------------------------------------
//Event na formularzu newslettera
			$("#addMail").click(function() {
			  $("#newsletterForm").submit();	
			});  

//Event na formularzu szukajki
			$("#goSearch").click(function() {
			  $("#serchForm").submit();	
			});  

	current_x = ($(document).width()-4200)/2;
	$('#mainImgCont').css({'background-position': current_x + 'px 0'}, 1);
	
     var current_y = 0;
 	mn=1400;
     setInterval(function()
     {
     //	current_x = current_x - 1400;
	
   	  $('#mainImgCont').animate({backgroundPosition: current_x-mn+'px 0px'}) 

	mn = mn +1400;
     }, 10000);
	
	initHotelMenu();//start hotel menu
	
	
//Stronnicowanie na opiniach
	$('.oHold').sweetPages({perPage:1});
	var controls = $('.swControls').detach();
	controls.appendTo('#oContener');
	
//FB slider	
	$('.fbSlider').mouseenter(function(){
	$(this).stop(true, true).animate({ 
				    width: "255px"
				   }, 300 );
	}).mouseleave(function(){
	    
			$(this).stop(true, true).animate({ 
				    width: "0px"
				   }, 300 );
	    });
	    
	

		}); 
$(window).resize(function() {
 	current_x = ($(document).width()-4200)/2;
	$('#mainImgCont').css({'background-position': current_x-mn + 'px 0'}, 1);
});
