var jcar = null;
var jcar_index = 0;
var pcount = 0;
var pidx = 0;
var parsed = [];
var promos_timeout = 4;

var t = n = count = 0;

var key = -1;
var isLoaded = false;







function OnBefore(){
}
function OnAfter(){
}





$(function(){
	
	$('#hero_images').cycle({
        timeout: 4000
    });
	
	//	Cufon font's fixing
	Cufon.set('fontFamily', 'Daxline-Bold');
	Cufon.replace('.fontStyle1', {
		fontStyle: 'Daxline-Bold',
	
		hover: true
	});
	
	Cufon.set('fontFamily', 'Futura MdCn BT');
	Cufon.replace('.searchTable .checkBtn', {
		fontStyle: 'Futura MdCn BT',
	
		hover: true
	});
	
	Cufon.set('fontFamily', 'Futura MdCn BT');
	Cufon.replace('.searchTable2 .checkBtn', {
		fontStyle: 'Futura MdCn BT',
	
		hover: true
	});	
	
	Cufon.set('fontFamily', 'Futura MdCn BT');
	Cufon.replace('.menu dt', {
		fontStyle: 'Futura MdCn BT',
	
		hover: true
	});
	
	Cufon.set('fontFamily', 'Futura MdCn BT');
	Cufon.replace('.right label', {
		fontStyle: 'Futura MdCn BT',
	    fontSize: '30px',
		hover: true
	});
	
	Cufon.set('fontFamily', 'Futura MdCn BT');
	Cufon.replace('.right .goBut', {
		fontStyle: 'Futura MdCn BT',
	
		hover: true
	});
	
    Cufon.set('fontFamily', 'DaxlineTF-Bold');
	Cufon.replace('.searchTable label', {
		fontStyle: 'DaxlineTF-Bold',
	
		hover: true
	});
	
    Cufon.set('fontFamily', 'DaxlineTF-Bold');
	Cufon.replace('.searchTable2 label', {
		fontStyle: 'DaxlineTF-Bold',
	
		hover: true
	});	
	
	/*Cufon.set('fontFamily', 'Futura MdCn BT');
	Cufon.replace('.adBox .title a', {
		fontStyle: 'Futura MdCn BT',
	
		hover: true
	});*/
	
	Cufon.set('fontFamily', 'Futura MdCn BT');
	Cufon.replace('.quickLabel', {
		fontStyle: 'Futura MdCn BT',
	
		hover: true
	});
	
	Cufon.set('fontFamily', 'Futura MdCn BT');
	Cufon.replace('.quickLabel_in', {
		fontStyle: 'Futura MdCn BT',
	
		hover: true
	});
	
	Cufon.set('fontFamily', 'Futura MdCn BT');
	Cufon.replace('.searchTable .checkBtn_in', {
		fontStyle: 'Futura MdCn BT',
	
		hover: true
	});
	
	Cufon.set('fontFamily', 'Futura MdCn BT');
	Cufon.replace('.searchTable2 .checkBtn_in', {
		fontStyle: 'Futura MdCn BT',
	
		hover: true
	});	
		
	Cufon.set('fontFamily', 'Futura MdCn BT');
	Cufon.replace('h2', {
		fontStyle: 'Futura MdCn BT',
	
		hover: true
	});
	
	Cufon.set('fontFamily', 'Arial');
	Cufon.replace('h4', {
		fontStyle: 'Arial',
	
		hover: true
	});
	
	Cufon.set('fontFamily', 'Daxline-Bold');
	Cufon.replace('h5', {
		fontStyle: 'Daxline-Bold',
	
		hover: true
	});		
	
	Cufon.set('fontFamily', 'Daxline-Bold');
	Cufon.replace('h5', {
		fontStyle: 'Daxline-Bold',
	
		hover: true
	});		
	
	Cufon.set('fontFamily', 'DaxlineTF-Bold');
	Cufon.replace('.foot', {
		fontStyle: 'DaxlineTF-Bold',
		
		hover: true
	});
	
	Cufon.set('fontFamily', 'Arial');
	Cufon.replace('.bestRates', {
		fontStyle: 'Arial',

		hover: true
	});
		
	Cufon.set('fontFamily', 'Arial');
	Cufon.replace('.bestRates_in', {
		fontStyle: 'Arial',

		hover: true
	});
	
	/*Cufon.replace('.icohare_trade_gothic_light', {
		fontStyle: 'TradeGothic',
		hover: true
	});*/		
	
	/*
	
	Cufon.set('fontFamily', 'Futura MdCn BT');
	Cufon.replace('h1, h2, h3, h4, h5, h6', {
		fontStyle: 'Futura MdCn BT',
	
		hover: true
	});
	
	Cufon.set('fontFamily', 'Arial');
	Cufon.replace('.bestRates', {
		fontStyle: 'Arial',
	
		hover: true
	});
	
	Cufon.set('fontFamily', 'Daxline-Bold');
	Cufon.replace('.fontStyle1', {
		fontStyle: 'Daxline-Bold',
	
		hover: true
	});
	
	Cufon.set('fontFamily', 'DaxlineTF-Bold');
	Cufon.replace('.dropListt', {
		fontStyle: 'DaxlineTF-Bold',
	
		hover: true
	});
	*/



	d = new Date();
	today_year = d.getFullYear();
	toyear=today_year-2000;
	today_month = d.getMonth()+1;
	if (today_month<10) {
		today_month = '0'+today_month;
	}
	today_day = d.getDate();
	if (today_day<10) {
		today_day = '0'+today_day;
	}
	today = today_month+'/'+today_day+'/'+toyear;
	t = d.getTime();
	d = new Date(t+1000*3600*24);
	tomorrow_year = d.getFullYear();
	tomyear=tomorrow_year-2000;
	tomorrow_month = d.getMonth()+1;
	if (tomorrow_month<10) {
		tomorrow_month = '0'+tomorrow_month;
	}
	tomorrow_day = d.getDate();
	if (tomorrow_day<10) {
		tomorrow_day = '0'+tomorrow_day;
	}
	tomorrow = tomorrow_month+'/'+tomorrow_day+'/'+tomyear;	
	$("#check-in-date").datepicker({
	    closeText: 'Close',
	    dateFormat: 'mm/dd/y',
	    defaultDate: 0,
	    minDate: '+0',
	    maxDate: '+1Y',
	    showAnim: 'slideDown',
	    showButtonPanel: true,
	    onSelect: function(date,thisPicker){
			date = $(this).datepicker("getDate");
			date.setDate(date.getDate()+1);
			$("#check-out-date").datepicker("setDate",date).datepicker("option", "minDate", date);
	    }
	}).val(today);
$('#arrival_date,#event_date_start,#event_date_end,#proposal,#event_date').datepicker({
	    closeText: 'Close',
	    dateFormat: 'mm/dd/yy',
	    defaultDate: 0,
	    minDate: '+0',
	    maxDate: '+5Y',
	    showAnim: 'slideDown',
	    showButtonPanel: true		
	});
	
	$('#arrival_date_a,#event_date_start_a,#event_date_end_a,#proposal_a,#event_date_a').click(function(){
		_key_ = $(this).attr('id');
		$('#'+_key_.replace('_a', '')).trigger('focus');
		return false;
	});
	$("#check-out-date").datepicker({
	    closeText: 'Close',
	    dateFormat: 'mm/dd/y',
	    defaultDate: +1,
	    minDate: '+1',
	    maxDate: '+1Y',
	    showAnim: 'slideDown',
	    showButtonPanel: true
	}).val(tomorrow);

	$("#nights").spicyselect();
	$("#adults").spicyselect();
	$("#kids").spicyselect();
	$("#rooms").spicyselect();

	

	
	
	pcount = parseInt($('#bar a').size());


	$('div.rb').jcarousel({
		scroll: 1,
		animation: 1500,
		auto: promos_timeout,

		wrap: "circular",
		initCallback: function(e,s) {

		},		
		itemLoadCallback: {
			onBeforeAnimation: callback1,
			onAfterAnimation: callback2
		}
	});
	
	function callback1(e){
			isLoaded = false;
			running = e.first%pcount - 1;
			$('#bar a').removeClass('current').eq(running).addClass('current');
			href1 = $('div.rb a').eq(running).attr('href');
			om = $('div.rb a').eq(running).attr('name');
			$('#bara').unbind('click').attr('href', href1).attr('name',om).attr('target','_blank').bind('click', function(){
				window.open(href1);
				return false;
			});
	}	
	
	function callback2(e){
		isLoaded = true;
	}


	$('#bar a').click(function(e){
		if(isLoaded == false) return false;
		jcar = $('div.rb').data('jcarousel');
		jcar.stopAuto();
		
		this_idx = parseInt($(this).attr('idx'));
		jcar.scroll(this_idx+1);
		jcar.first = this_idx+1;
		jcar.last = this_idx+1;

		$('#bar a').removeClass('current').eq(this_idx).addClass('current');
		href = $('div.rb a').eq(this_idx).attr('href');
	
		$('#bara').unbind('click').attr('href', href).attr('target','_blank').bind('click', function(){
			window.open(href);
			return false;
		});

		jcar.startAuto();	
		isLoaded == false;
		return false;   
	});	
	




	
	
	
	$("#rm").click(function(){
		$("#hide_content").removeClass("hide");
		$(this).removeClass("readMore").addClass("hide");
		$("#rl").removeClass("hide").addClass("readLess");
	});
	$("#rl").click(function(){
		$("#hide_content").addClass("hide");
		$(this).removeClass("readLess").addClass("hide");
		$("#rm").removeClass("hide").addClass("readMore");
	});
	$('#contactus_submit,#meeting_submit,#wedding_submit').click(function(){
		_key_ = $(this).attr('id');
		$('#'+_key_.replace('_submit', '')).trigger('submit');		
		return false;
	});
	
	$('#contactus_reset, #meeting_reset,#wedding_reset').click(function(){
		_key_ = $(this).attr('id');
		$('#'+_key_.replace('_reset', '')).trigger('reset');	
		return false;
	});
	
	$('#contactus_country_select').change(function(){
		val = '';
		$(this).find('option').each(function(){
			if ($(this).attr('selected')) {
				val = $(this).text();
			}
		});
		if (val!='') {
			$('#contactus_country').val(val);
		}
	});
});


function updateCheckOutDate(){
	var checkInDate = $("#check-in-date").val();
	var nights = parseInt( $("#nights").val() );
	var dateArr = checkInDate.split("/");
	var tempY = parseInt(dateArr[2]) + 2000;
	var tempM = dateArr[0];
	var tempD = dateArr[1];
	
	var newDate = new Date();
	newDate.setFullYear(tempY);
	newDate.setMonth(tempM);
	newDate.setDate(tempD);
	
	d = new Date();
	d.setFullYear(newDate.getFullYear());
	d.setMonth(newDate.getMonth());
	d.setDate(newDate.getDate() + nights);
	
	tomorrow_year = d.getFullYear();
	tomyear=tomorrow_year-2000;
	tomorrow_month = d.getMonth();
	if (tomorrow_month<10) {
		tomorrow_month = '0'+tomorrow_month;
	}
	tomorrow_day = d.getDate();
	if (tomorrow_day<10) {
		tomorrow_day = '0'+tomorrow_day;
	}
	tomorrow = tomorrow_month+'/'+tomorrow_day+'/'+tomyear;		
	
	$("#check-out-date").val(tomorrow);
}
