$(function(){
	/***
	 * Generic functions that come out of the box
	 */
	
	$("span.collapse-content").hide();
	$("a.collapse").click(function(){
		$(this).parents("div").children("span.collapse-content").slideToggle("slow");
		$(this).toggleClass("hide");
		($(this).hasClass("hide")) ? $(this).html("<span class='collapse-minus'><</span> Hide Text") : $(this).html("Read More <span class='collapse-plus'>></span>");
		
		return false;
	});
	
	/*E-mail Exclusives Input Clear*/
	$("input[name=EMAIL]").focus(function()
	{
		$(this).val("");		
		$(this).blur(function()
		{
			if($(this).val()=="")
				$(this).val("Enter email here");
		});
	});
	
	/*Lightbox Event Handler*/
	if($("a.lightbox").length>0){
		$("a.lightbox").lightBox({
			imageBtnPrev 	: assets+'images/lightbox-btn-prev.gif',
			imageBtnNext 	: assets+'images/lightbox-btn-next.gif',
			imageBtnClose	: assets+'images/lightbox-btn-close.gif',
			imageLoading   	: assets+'images/lightbox-ico-loading.gif',
			fixedNavigation	: true
		});
	}
	
	/*Datepicker Event Handler*/
	$("a.datepickeropen").click(function(){		
		$("#sitewrapper").after('<div id="datepicker"><a href="javascript:void(0);" class="dp-close" style="float:right;">Close</a>&nbsp;</div>');		
		$("#datepicker").css({'display':'none','position':'absolute','z-index':'100','left':$(this).offset().left,'top':$(this).offset().top});
		$("a.dp-close").click(function(){$("#datepicker").remove();});

		var opts;
		var arr = $(this).attr("rel").split("_");
		
		switch(arr[0])
		{
			case "res":
				opts = {
					dateFormat:'yy-mm-dd',
					altField: arr[1],
					onSelect: function(dateText){
						var split = dateText.split("-");
						var altField = $("#datepicker").datepicker("option", "altField");
						if (altField == "calArrivalDateField") {
							date = new Date(split[0],split[1]-1,split[2]);
							date.setDate(date.getDate()+1);
							
							month = date.getMonth()+1<10 ? "0"+(date.getMonth()+1) : (date.getMonth()+1);
							day   = date.getDate()<10 ? "0"+date.getDate() : date.getDate(); 
							$("input[name=calDepartureDateField]").val(date.getFullYear()+"-"+month+"-"+day);
						}
						$("input[name="+arr[1]+"]").val(dateText);
						$("#datepicker").remove();
						
					}
					
				}				
			break;
			case "text":
				opts = {
					dateFormat:'m-d-yy',
					onSelect: function(dateText){						
						$("."+arr[1]).val(dateText);									
						$("#datepicker").remove();
					}
				}
			break;
		}
		
/*
		
		switch(arr[0])
		{
			case "res":
				opts = {
					dateFormat:'yy-mm-dd',
					//onSelect: function(dateText){
					//	$("input[name="+arr[1]+"]").val(dateText);
					//	$("#datepicker").remove();
					//}
					altField: arr[1],
					onSelect: function(dateText){
						var split = dateText.split("-");
						var altField = $("#datepicker").datepicker("option", "altField");
						if (altField == "calArrivalDateField") {
							$("#calDepartureDateField").val(split[0]+"-"+eval(parseInt(split[1])+1)+"-"+split[2]);
						}
						$("#"+altField).val(dateText);
						$("#datepicker").remove();
						
					}
					
				}				
			break;
			case "text":
				opts = {
					dateFormat:'m-d-yy',
					onSelect: function(dateText){						
						$("."+arr[1]).val(dateText);									
						$("#datepicker").remove();
					}
				}
			break;
		}
*/
		
		$("#datepicker").datepicker(opts);		
		$("#datepicker").toggle();
		
		return false;
	});
	
	/**
	 * End Generic Functions
	 */
});