$(document).ready(function($){
	$('#submit').mouseenter(function() {
		$('#submit').attr("src", "images/join-over.png");
	});
	$('#submit').mouseleave(function() {
		$('#submit').attr("src", "images/join.png");
	});
	$('#submit1').mouseenter(function() {
		$('#submit1').attr("src", "images/join-over-en.png");
	});
	$('#submit1').mouseleave(function() {
		$('#submit1').attr("src", "images/join-en.png");
	});
	$('#menu li').mouseenter(function() {
		$(this).children('.submenu').stop().delay(200).show(0);
	});
	$('#menu li').mouseleave(function() {
		$(this).children('.submenu').stop().hide(0);
	});
	$('#welcome').fadeIn(2000);
	$('#news').fadeIn(2000);
	$('#email').focusin(function() {
		if($(this).val() == 'Twój e-mail') $(this).val('');
	});
	$('#email').focusout(function() {
		if($(this).val() == '') $(this).val('Twój e-mail');
	});
	$('#email-en').focusin(function() {
		if($(this).val() == 'Your e-mail') $(this).val('');
	});
	$('#email-en').focusout(function() {
		if($(this).val() == '') $(this).val('Your e-mail');
	});
	
	
	$('#hotel').submit(function() {
		var fullname = $('#fullname').attr('value');
		var address = $('#address').attr('value');
		var phone = $('#phone').attr('value');
		var email = $('#email').attr('value');
		var company = $('#company').attr('value');
		var arrival = $('#arrival').attr('value');
		var departure = $('#departure').attr('value');
		var other = $('#other').val();
		$('form#hotel').css('display','none');
		$('#response').html('Trwa wysyłanie danych. Proszę czekać ...');
		var res = new Array('fullname', 'email', 'phone', 'arrival', 'departure');
		for(i=0; i<res.length; i++) {
			$('#'+res[i]).removeClass('error');
		}
		$.ajax({
			type: "POST",
			url: "?macro=hotel-res",
			data: "fullname="+ fullname +"&email="+ email +"&address="+ address +"&phone="+ phone +"&company="+ company +"&arrival="+ arrival +"&departure="+ departure +"&other="+ other,
			success: function(data, text, xmlhttp){
				res = xmlhttp.responseText.split("\n");
				if (res[0] !== 'Formularz rezerwacji został wysłany. Dziękujemy!'){
					$('form#hotel').css('display','block');
				}
				$('#response').html(res[0]);
				for(i=1; i<res.length; i++) {
					$('#'+res[i]).addClass('error');
				}
			}
		});
		return false;
	});
	$('#hotel-en').submit(function() {
		var fullname = $('#fullname').attr('value');
		var address = $('#address').attr('value');
		var phone = $('#phone').attr('value');
		var email = $('#email').attr('value');
		var company = $('#company').attr('value');
		var arrival = $('#arrival').attr('value');
		var departure = $('#departure').attr('value');
		var other = $('#other').val();
		$('form#hotel-en').css('display','none');
		$('#response').html('Processing request...');
		var res = new Array('fullname', 'email', 'phone', 'arrival', 'departure');
		for(i=0; i<res.length; i++) {
			$('#'+res[i]).removeClass('error');
		}
		$.ajax({
			type: "POST",
			url: "?macro=hotel-res-en",
			data: "fullname="+ fullname +"&email="+ email +"&address="+ address +"&phone="+ phone +"&company="+ company +"&arrival="+ arrival +"&departure="+ departure +"&other="+ other,
			success: function(data, text, xmlhttp){
				res = xmlhttp.responseText.split("\n");
				if (res[0] !== 'Rezervation form has been sent!'){
					$('form#hotel-en').css('display','block');
				}
				$('#response').html(res[0]);
				for(i=1; i<res.length; i++) {
					$('#'+res[i]).addClass('error');
				}
			}
		});
		return false;
	});
	$('#hotel2').submit(function() {
		var fullname = $('#fullname').attr('value');
		var address = $('#address').attr('value');
		var phone = $('#phone').attr('value');
		var email = $('#email').attr('value');
		var company = $('#company').attr('value');
		var other = $('#other').val();
		$('form#hotel2').css('display','none');
		$('#response').html('Trwa wysyłanie danych. Proszę czekać ...');
		var res = new Array('fullname', 'email', 'phone', 'arrival', 'departure');
		for(i=0; i<res.length; i++) {
			$('#'+res[i]).removeClass('error');
		}
		$.ajax({
			type: "POST",
			url: "?macro=hotel-res2",
			data: "fullname="+ fullname +"&email="+ email +"&address="+ address +"&phone="+ phone +"&company="+ company +"&other="+ other,
			success: function(data, text, xmlhttp){
				res = xmlhttp.responseText.split("\n");
				if (res[0] !== 'Formularz rezerwacji został wysłany. Dziękujemy!'){
					$('form#hotel2').css('display','block');
				}
				$('#response').html(res[0]);
				for(i=1; i<res.length; i++) {
					$('#'+res[i]).addClass('error');
				}
			}
		});
		return false;
	});
	$('#hotel-en2').submit(function() {
		var fullname = $('#fullname').attr('value');
		var address = $('#address').attr('value');
		var phone = $('#phone').attr('value');
		var email = $('#email').attr('value');
		var company = $('#company').attr('value');
		var other = $('#other').val();
		$('form#hotel-en2').css('display','none');
		$('#response').html('Processing request...');
		var res = new Array('fullname', 'email', 'phone', 'arrival', 'departure');
		for(i=0; i<res.length; i++) {
			$('#'+res[i]).removeClass('error');
		}
		$.ajax({
			type: "POST",
			url: "?macro=hotel-res-en2",
			data: "fullname="+ fullname +"&email="+ email +"&address="+ address +"&phone="+ phone +"&company="+ company +"&other="+ other,
			success: function(data, text, xmlhttp){
				res = xmlhttp.responseText.split("\n");
				if (res[0] !== 'Rezervation form has been sent!'){
					$('form#hotel-en2').css('display','block');
				}
				$('#response').html(res[0]);
				for(i=1; i<res.length; i++) {
					$('#'+res[i]).addClass('error');
				}
			}
		});
		return false;
	});
	$('#est').submit(function() {
		var fullname = $('#fullname').attr('value');
		var email = $('#email').attr('value');
		var other = $('#other').val();
		$('#est').css('display','none');
		$('#response').html('Trwa wysyłanie danych. Proszę czekać ...');
		var res = new Array('fullname', 'email', 'other');
		for(i=0; i<res.length; i++) {
			$('#'+res[i]).removeClass('error');
		}
		$.ajax({
			type: "POST",
			url: "?macro=est-send",
			data: "fullname="+ fullname +"&email="+ email +"&other="+ other,
			success: function(data, text, xmlhttp){
				res = xmlhttp.responseText.split("\n");
				if (res[0] !== 'Wiadomość wysłano. Dziękujemy!'){
					$('#est').css('display','block');
				}
				$('#response').html(res[0]);
				for(i=1; i<res.length; i++) {
					$('#'+res[i]).addClass('error');
				}
			}
		});
		return false;
	});
	$('#est-en').submit(function() {
		var fullname = $('#fullname').attr('value');
		var email = $('#email').attr('value');
		var other = $('#other').val();
		$('#est-en').css('display','none');
		$('#response').html('Processing request...');
		var res = new Array('fullname', 'email', 'other');
		for(i=0; i<res.length; i++) {
			$('#'+res[i]).removeClass('error');
		}
		$.ajax({
			type: "POST",
			url: "?macro=est-send-en",
			data: "fullname="+ fullname +"&email="+ email +"&other="+ other,
			success: function(data, text, xmlhttp){
				res = xmlhttp.responseText.split("\n");
				if (res[0] !== 'Formularz rezerwacji został wysłany. Dziękujemy!'){
					$('#est-en').css('display','block');
				}
				$('#response').html(res[0]);
				for(i=1; i<res.length; i++) {
					$('#'+res[i]).addClass('error');
				}
			}
		});
		return false;
	});
	
	var tmp = $('#photo').children().hide();
	var img = $('#photo').children('.img').first();
	img.fadeIn(300);
	
	$('#rightside').click(function() {
		tmp = img.next();
		if(tmp.size()>0) {
			img.fadeOut(300);
			img = tmp;
			img.fadeIn(300);
		} else {
			img.fadeOut(300);
			img = $('#photo').children('.img').first();
			img.fadeIn(300);
		}
	});
	
	$('#leftside').click(function() {
		tmp = img.prev();
		if(tmp.size()>0) {
			img.fadeOut(300);
			img = tmp;
			img.fadeIn(300);
		} else {
			img.fadeOut(300);
			img = $('#photo').children('.img').last();
			img.fadeIn(300);
		}
	});
	
	$( ".foodlist" ).hide();
	
	var tmp = $('#daniaphotolist').children().hide();
	var img = $('#daniaphotolist').children('.danie').first();
	img.fadeIn(300);
	
	$('#btup').click(function() {
		tmp = img.next();
		img.fadeOut(300);
		if(tmp.size()>0) {
			img = tmp;
		} else {
			img = $('#daniaphotolist').children('.danie').first();			
		}
		img.fadeIn(300);
	});
	
	$('#btdown').click(function() {
		tmp = img.prev();
		img.fadeOut(300);
		if(tmp.size()>0) {
			img = tmp;
		} else {
			img = $('#daniaphotolist').children('.danie').last();			
		}
		img.fadeIn(300);
	});
	
	$('.foodcat a').click(function() {
		var i = $('.foodcat a').index($(this));
		$('.foodlist').fadeOut(300);
		$('.foodlist').eq(i).fadeIn(300);
		$('.foodcat a').removeClass('kat-zaz');
		$(this).addClass('kat-zaz');
	});
	
	var newsleft = 0;
	var news = $('.news').first();
	$('#next').click(function() {
		news = news.next();
		if(news.html()) {
			newsleft -= 330;
		} else {
			news = $('.news').first();
			newsleft = 0;
		}
		$('#newslist').stop().animate({left:newsleft+'px'}, 550);
	});
});

var shiftRate = 3;

function setShiftRate(id) {
	if(id==7) {
		shiftRate = 1;
	} else {
		shiftRate = 3;
	}
}

var move = false;

function movebg(e){
	if(move) {
		var w = $(window).width();
		var p = $('#pimg').width();
		var l = (w-p)/2 + (w/2 - e.pageX)/shiftRate;
		if(l >= w - p && l <= 0) {
			return l+"px";
		}
	}
}
function shift(e){
	$('#panorama').css('left', movebg(e));
}

function exchange(img){
	$('#pimg').attr('src', img);	//podmien nad
	$('#pimg').show();			//pokaz nad
	move = true;
}

function go(id) {
	move = false;
	$('#dotscenter').html('');
	setShiftRate(id);
	var panorama = new Array('schody','sala-piwna','0','bar','sala-lunchowa','dwor','kadzie','piwnica1','piwnica-bar');
	var img = 'images/panorama/'+panorama[id]+'.jpg';
	$('#psec').attr('src', img);	//podmien pod
	$('#exch').css('width', $('#psec').width()+'px');	//ustaw wielkosc
	$('#exch').css('height', $('#psec').height()+'px');
	
	var left = ($('#psec').width()-$('#dotscenter').width())/2;
	$('#dotscenter').css('left', left+"px");
	
	//$('#psec').css('left', ($('#pimg').width()-$('#psec').width())/2+"px");
	
	var w = $(window).width();
	var p = $('#psec').width();
	var l = (w-p)/2;
	$('#panorama').css('left', l+"px");	//wycentrowanie panoramy
	
	$('#pimg').fadeOut(1000);	//odslon
	setTimeout("exchange('"+img+"')",1000);

	var root = new Array(
		new Array(1,7,3,4,5),
		new Array(6,0),
		new Array(0),
		new Array(5,0),
		new Array(0),
		new Array(0),
		new Array(1),
		new Array(2,8),
		new Array(7,1)
	);
	var img = root[id];
	$("#bufor").html('');
	for(i=0;i<img.length;i++){
		$("#bufor").append('<img src="images/panorama/'+panorama[img[i]]+'.jpg" />');
	}
	var lang = '';
	if(window.location.href.indexOf('/EN-H')>0) {
		lang = '-en';
	}
	$.ajax({
		type: "GET",
		url: "?macro=panorama-points"+lang,
		data: "id="+id,
		success: function(msg){
			$('#dotscenter').html(msg);
			$('#dots p').corner('4px');
		}
	});
}

function loadPanorama() {
	$("body").mousemove(function(e){shift(e)});
	$(window).resize(function() {
		var h = $(window).height();
		var t = (h-600)/2;
		$('#panorama').css('top', t+"px");
	});
	go(0);
}

