$(document).ready(function () {
	$('#reviews').cycle({ 
	    fx:     'fade', 
	    speed:   700, 
	    timeout: 4000, 
	    next:   '#reviews', 
	    pause:   1 
	});
	$('#slideshow').cycle({ 
	    fx:     'fade', 
	    speed:   1000, 
	    timeout: 4000,  
	    next:   '#slideshow', 
	    pause:   0,
		next:   '#next',
	    prev:   '#prev'
	});
	$('#floorplans').cycle({
	    fx:     'fade', 
	    speed:   1000, 
	    timeout: 0,  
	    next:   '#slideshow', 
	    pause:   0,
		next:   '.fpnl',
	});
	$('a.maplink').click(function () { 
      	var gm = $(this).attr("href");
      	getMap(gm);
      	return false;
    });
	
	
	var lh = $('#leftcont_eq').height();
	var rh = $('#rightcont_eq').height();
	if (lh < rh){
		$('#leftcont_eq').height(rh);
	}
	var lhp = $('#leftcont_eqp').height();
	if (lhp < 412){
		var rhp = $('#rightcont_eqp').height();
		rhp = rhp - 38;
		$('#leftcont_eqp').height(rhp);
	}
	
	var oh1 = $('#offer1').height();
	var oh2 = $('#offer2').height();
	var oh3 = $('#offer3').height();
	var maxh = (Math.max(oh1,oh2,oh3));
	$('#offer1').height(maxh);
	$('#offer2').height(maxh);
	$('#offer3').height(maxh);
		

	$('.date-pick').datePicker({
		clickInput:true
		})
	$('#start-date').bind(
		'dpClosed',
		function(e, selectedDates)
		{
			var d = selectedDates[0];
			if (d) {
				d = new Date(d);
				$('#end-date').dpSetStartDate(d.addDays(1).asString());
			}
		}
	);
	$('#end-date').bind(
		'dpClosed',
		function(e, selectedDates)
		{
			var d = selectedDates[0];
			if (d) {
				d = new Date(d);
				$('#start-date').dpSetEndDate(d.addDays(-1).asString());
			}
		}
	);
	$('#end-date').dpSetPosition($.dpConst.POS_BOTTOM, $.dpConst.POS_LEFT);
	$('#start-date').dpSetPosition($.dpConst.POS_BOTTOM, $.dpConst.POS_LEFT);

	$("#check").click(function () { 
      	checkAvailability();
      	return false;
    });
	$("#subscribe").click(function () { 
      	subscribe();
      	return false;
    });
    $(".top").click(function () { 
      	scrolltotop();
      	return false;
    });
});

function scrolltotop(){
	  $("body, html").animate({ scrollTop: 0 }, 500);
}

function makeUSdate(ukdate){
	var day = ukdate.substring(0,2);
	var month = ukdate.substring(3,5);
	var year = ukdate.substring(6);
	var usdate = year+"/"+month+"/"+day;
	return usdate;
}

function checkAvailability(){
	var startdate = $('#start-date').val();
	var enddate = $('#end-date').val();
	var adults = $('#adults').val();
	var children = $('#children').val();
	//var url = 'http://gc.synxis.com/xbe/rez.aspx?hotel=24728&arrive='+makeUSdate(startdate)+'&depart='+makeUSdate(enddate)+'&adult='+adults+'&child='+children;
	var url = 'https://gc.synxis.com/rez.aspx?Hotel=24728&Chain=9606&shell=GCO&arrive='+makeUSdate(startdate)+'&depart='+makeUSdate(enddate)+'&adult='+adults+'&child='+children;
	window.location = url;
}

function subscribe() {
	$('#subscribeform').submit();
}


function getMap(gm){
	$("#bigmap").load("/php/getmap.php",{g:gm});
}


function email(user,domain,subject) {
	locationstring = "mailto:" + user + "@" + domain+"?subject="+subject;
	window.location = locationstring;
}
