$(document).ready(function(){
	initSlider();
	initRightTabs();
	initWidget();
	initCufon();
	initExternal();
});

function initCufon(){
	if ($('#slider_image').length == 0) return false;
	Cufon.replace('#slider_image p, #slider_image span.date, #slider_image p.explore' ,  {fontFamily: 'Bembo Std'});
}
function initExternal(){
	$('a[rel=external]').attr('target','_blank');
}
$(window).load(function(){
	initHeight();
	
});
$(window).resize(function(){
	initHeight();
});
function initHeight(){
	var h_window = $(window).height();
	var h_theflash = $('object#theflash').height();
	var h_flashcontent = $('object#flashcontent').height();
	if (h_theflash > 0) {
		if(h_theflash > h_window) $('body').height(h_theflash); else $('body').height(h_window);
	} else
	if (h_flashcontent > 0) {
		if(h_flashcontent > h_window) $('body').height(h_flashcontent); else $('body').height(h_window);
	}
}
function initSlider() {	
	if ($('#slider_image').length == 0) return false;
	$('#slider_image').after('<ul id="nav">').cycle({ 
	    speed:  'fast', 
	    timeout: 0, 
	    pager:  '#nav',      
	    // callback fn that creates a thumbnail to use as pager anchor 
	    pagerAnchorBuilder: function(idx, slide) { 
	        return '<li><a href="#">'+(idx+1)+'</a></li>'; 
	    } 
	});
	
	$('#slider_blocks').jcarousel({
      scroll: 1,
	  wrap: 'circular'
  });
}

function initRightTabs() {
	if($('ul.right-tabs').length) {
		$('ul.right-tabs li span > a').click(function() {			
			var li = $(this).parents('li');
			if($(li).hasClass('active')) {
				$(li).removeClass('active');
			}
			else {
				var div_content = $(this).parent().next();
				if($(div_content).hasClass('content')) {		
					if($(div_content).hasClass('content')) {
						$(this).parents('ul').find('li').removeClass('active');
					  $(li).addClass('active');
						return false;
					}
				}
			}		
		});
	}
}

function initWidget() {
	if ($('input.date-pick').get(0)) {
		$('input.date-pick').datepicker({
			minDate: new Date(),
			showOn: 'button',
			buttonImage: '_img/calendar.gif',
			buttonImageOnly: true,
			dateFormat: 'mm/dd/yy'
		});	
	}
	
	
	var now = new Date();
	now = dateFormat(now, 'mm/dd/yyyy');  
	$('#chk_in').val(now);
	$('#slider_chk_in').val(now);
	var tomorrow = new Date();
	tomorrow.setDate(tomorrow.getDate()+1);
	tomorrow = dateFormat(tomorrow, 'mm/dd/yyyy');
	$('#hotel-check-out').val(tomorrow);
	$('#slider_hotel-check-out').val(tomorrow);
	
	$('#HotelSearch').submit(function() {
		splitDate('chk_in', 'doa');
		splitDate('hotel-check-out', 'dod');
	});	
	
	$('#slider_HotelSearch').submit(function() {
		splitDate('slider_chk_in', 'slider_doa');
		splitDate('slider_hotel-check-out', 'slider_dod');
	});
} 

function splitDate(input, output) 
{
	$('#'+input).each(function()
	{
		var date = $(this).val();
		var pieces = date.split('/');
		var outputs = ['mm', 'dd', 'yy'];
		
		for (var i=0; len=pieces.length,i<len; i++)
		{
			$('#'+output+'_'+outputs[i]).val(pieces[i]);
		}
	});
}  
