// JavaScript Document

jQuery(document).ready(function($){

/**************** setting the img resize of the background */
                var bgMargin		=	0;
		var windowHeight	= 	$('#superwrapper').height();
		var windowWidth 	= 	$('#superwrapper').width();
		var ratio			= 	0.75;
											   
		if ( windowWidth < (windowHeight / ratio))
		{
			$('.background img').css('height', windowHeight + 'px');
			$('.background img').css('width','auto');
			bgMargin = ($('.background img').width() - windowWidth) / 2;
			$('.background img').css('margin-left','-' + bgMargin + 'px');
			$('.background img').css('margin-top','0px');
		}
		else
		{
			$('.background img').css('height', 'auto');
			$('.background img').css('width',windowWidth + 'px');	
			bgMargin = ($('.background img').height() - windowHeight) / 2;
			$('.background img').css('margin-left','0px');
			$('.background img').css('margin-top','-' + bgMargin + 'px');		
		}
		
		$(window).bind('resize', function(){
			
			
			windowHeight	= 	$('#superwrapper').height();
			windowWidth 	= 	$('#superwrapper').width();
			
			if ( windowWidth < (windowHeight / ratio))
			{
				$('.background img').css('height', windowHeight + 'px');
				$('.background img').css('width','auto');
				bgMargin = ($('.background img').width() - windowWidth) / 2;
				$('.background img').css('margin-left','-' + bgMargin + 'px');
				$('.background img').css('margin-top','0px');
			}
			else
			{
				$('.background img').css('height', 'auto');
				$('.background img').css('width',windowWidth + 'px');	
				bgMargin = ($('.background img').height() - windowHeight) / 2;
				$('.background img').css('margin-left','0px');
				$('.background img').css('margin-top','-' + bgMargin + 'px');		
			}		
				
		});

	if ($('.date-pick').length > 0){
		$(function() {
			$('.date-pick').datepicker({
				showOtherMonths: true, 
				selectOtherMonths: true,
				minDate:0 , 
				showOn: 'button', 
				buttonImage: webURL + 'images/calendar.jpg',
				buttonImageOnly: true
			});
		
			if (currentLang == 'el') {
				$('.date-pick').datepicker('option', $.datepicker.regional['el']);
			} else {
				$('.date-pick').datepicker('option', $.datepicker.regional['en-GB']);
			}			
		});
		
		var today = new Date();
		today.setDate(today.getDate()+1);
		var todayDate = '' + today.getDate();
		var todayDateStr = ( todayDate.length==1 ? '0'+todayDate : todayDate );
		var todayMonth = '' + (today.getMonth()+1);
		var todayMonthStr = ( todayMonth.length==1 ? '0'+todayMonth : todayMonth );
		
		var dateInEl = document.getElementById('date-in');
		var usDateInEl = document.getElementById('eu-date-in');
		
		if (usDateInEl) {
			if (usDateInEl.value == 'unknown') {
				dateInEl.value = todayDateStr + '/' + todayMonthStr + '/' +  today.getFullYear();
				usDateInEl.name = 'usdatein';
				usDateInEl.defaultValue = 'waiting'; 
				usDateInEl.value = usDateInEl.defaultValue;
			}
		}
	}
	
	$(function(){
		$('#header .column2 .cell2').jScrollPane({
			verticalGutter: 10
		});
	});
	
	$('#header .column1 form:first').css('display', 'block');
});

$('#header .column1 h3').live('click', function() {
	if ($(this).hasClass('closed')) {
		$('#header .column1 h3').attr('class', 'closed');
		$(this).attr('class', 'open');
		$('#header .column1 form').slideToggle(500);
	}
});

$('#contentsToggler').live('click', function() {
	if ($('#contentsToggler').hasClass('closed')) {
		$('#header .column2').animate({
			right: '0'
		}, 500, function() {
			$('#contentsToggler').attr('class', 'open');
		});
	} else {
		$('#header .column2').animate({
			right: '-345px'
		}, 500, function() {
			$('#contentsToggler').attr('class', 'closed');
		});
	}
});

function bookingOnSubmit() {
	var dateParts = $('#date-in').val().split('/');
	document.getElementById('eu-date-in').value = $('#date-in').val();
	document.getElementById('date-in').value = dateParts[1] + '/' + dateParts[0] + '/' + dateParts[2];
	document.getElementById('eu-date-in').name = 'eudatein';
	
	_gaq.push(['_trackEvent', 'online booking', 'Submit', 'booking form']);
	
	return true;
}
				var _gaq = _gaq || [];
				_gaq.push(['_setAccount', 'UA-26796160-1']);
				_gaq.push(['_trackPageview']);
				_gaq.push(['_trackPageLoadTime']);
				
				(function() {
					var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
					ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
					var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
				})();
