// 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");
	
}
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'
						
					}
				}
			});

////-------------Koniec walidacji formularzy-----------------------------------------------
//Event na formularzu newslettera
			$("#addMail").click(function() {	
			  $("#newsletterForm").submit();	
			});  

//Event na formularzu szukajki
			$("#goSearch").click(function() {
			  $("#serchForm").submit();	
			});  
//obsluga galerii
			$("#mainGalleryList li a").click(function() {
				img = $(this).attr('href');
				$('#mImg').attr('src',img+'.jpg');
				$('#mHref').attr('href',img+'_big.jpg');
				$("#mainGalleryList li a").removeClass('aImg');
				$(this).addClass('aImg');
			}); 
			
	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);
		
//FB slider	
	$('.fbSlider').mouseenter(function(){
	$(this).stop(true, true).animate({ 
				    width: "255px"
				   }, 300 );
	}).mouseleave(function(){
	    
			$(this).stop(true, true).animate({ 
				    width: "0px"
				   }, 300 );
	    });
	    
		$(function(){
  			 $(".toolpit").tipTip({maxWidth: "500px;", edgeOffset: 5});
		});

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