
document.write("<scr" + "ipt src='/RipeCMS/scripts/jquery.1.5/jquery-ui-1.8.12.custom.min.js'></scr" + "ipt>");
document.write("<link href='/RipeCMS/css/jquery/start.1.5.css' rel='stylesheet' type='text/css' />");


$(window).ready(function(){
	// Attach calendar:
//	$("input[class='InputCalendar']").each(function(index, itm){
//		var $parent = $(itm).parent();
//		var $txt = $(itm).detach().css('cursor', 'pointer');
//		var $tbl = $("<table border='0' cellpadding='0' cellspacing='2'><tr><td></td><td></td></tr></table>");
//		var $cal = $("<img src='/images/Calendar.gif' border='0' width='20' height='21' align='absmiddle' style='cursor:pointer;' />");
//		
//		// Build:
//		$parent.append( $tbl );
//		$tbl.find('td:first').append( $txt );
//		$tbl.find('td:last').append( $cal );
//		
//		// Attach events:
//		$txt.click(function(){ Calendar.Show(itm.id); });
//		$cal.click(function(){ Calendar.Show(itm.id); });
//	});
	
	$(".bookNowBox input:text[name='adults']").each(function(idx, ele){
		$(ele).val(1);
	});
	$(".bookNowBox input:text[name='children'], .bookNowBox input:text[name='infants']").each(function(idx, ele){
		$(ele).val(0);
	});
	
	ProcessCalendars();
	
	try{ ProcessHomebox(); }catch(e){}
});

function ProcessHomebox(){
	$('.homeBox').hover(function(e){
		$(this).find('a.btnExplore').addClass('btnExplore-hover');
	}, function(e){
		$(this).find('a.btnExplore').removeClass('btnExplore-hover');
	})
	.css('cursor', 'pointer')
	.click(function(e){
		if ($(this).parent().attr('href') == undefined)
			document.location.href = $(this).find('a.btnExplore').attr('href');
	});
}

function ProcessCalendars(){
	$("input[class='InputCalendar']").each(function(index, itm){
		//<img id="imgDateFrom" src="/images/icons/calendar_2.png" style="cursor:pointer" align="texttop" />
		var $parent = $(itm).parent();
		var $txt = $(itm).detach();
		var $tbl = $("<table border='0' cellpadding='0' cellspacing='2'><tr><td></td><td></td></tr></table>");
		var $cal = $("<img src='/images/Calendar.gif' border='0' width='20' height='21' align='absmiddle' style='cursor:pointer;' />");
		
		// Build:
		$txt.css('cursor', 'pointer');
		$parent.append( $tbl );
		$tbl.find('td:first').append( $txt );
		$tbl.find('td:last').append( $cal );
		
		// Attach events:
		//$txt.click(function(){ Calendar.Show(itm.id); });
		//$cal.click(function(){ Calendar.Show(itm.id); });
		
		// Init cal:
		$txt.datepicker({dateFormat:'dd/mm/yy', defaultDate:$txt.val() });
		$cal.click(function(){ $txt.focus(); });
	})
}

/* Custom booking checkboxes */
jQuery.fn.extend({
	bookStyle: function()
	{
		// Initialize with initial load time control state
		$.each($(this), function(){
			var elm	= $(this).children().get(0);
			elmType = $(elm).attr("type");
			$(this).data('type',elmType);
			$(this).data('checked',$(elm).attr("checked"));
			$(this).bookClear();
		});
		$(this).mousedown(function() { $(this).bookEffect(); });
		$(this).mouseup(function() { $(this).bookHandle(); });	
	}
	, bookClear: function()
	{
		if($(this).data("checked") == true)
		{
			$(this).css("backgroundPosition","center -"+(elmHeight*2)+"px");
			}
		else
		{
			$(this).css("backgroundPosition","center 0");
			}	
	}
	, bookEffect: function()
	{
		if($(this).data("checked") == true)
			$(this).css({backgroundPosition:"center -"+(elmHeight*3)+"px"});
		else
			$(this).css({backgroundPosition:"center -"+(elmHeight)+"px"});
	}
	, bookHandle: function()
	{
		var elm	=	$(this).children().get(0);
		if($(this).data("checked") == true)
			$(elm).bookUncheck(this);
		else
			$(elm).bookCheck(this);
		
		if($(this).data('type') == 'radio')
		{
			$.each($("input[name='"+$(elm).attr("name")+"']"),function()
			{
				if(elm!=this)
					$(this).bookUncheck(-1);
			});
		}
	}
	, bookCheck: function(div)
	{
		
		$(this).attr("checked",true);
		$(div).data('checked',true).css({backgroundPosition:"center -"+(elmHeight*2)+"px"});
	}
	, bookUncheck: function(div)
	{
		$(this).attr("checked",false);
		if(div != -1)
			$(div).data('checked',false).css({backgroundPosition:"center 0"});
		else
			$(this).parent().data("checked",false).css({backgroundPosition:"center 0"});
	}
});

function validateEmail(Ctrl)
{
	return FormsHelper.ValidateEmail($(Ctrl).val());
}
