$(function(){	 
	/***
	 * Generic functions that come out of the box
	 */
	
	/*E-mail Exclusives Input Clear*/
	$("input[name=EMAIL]").focus(function()
	{
		var $default = $(this).val();
		$(this).val("");		
		$(this).blur(function()
		{
			if($(this).val()=="")
				$(this).val($default);
		});
	});
	
	/*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':'10000','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 = {
					minDate: 0, 
					maxDate: '+1Y',
					dateFormat:'mm/dd/yy',
					altField: arr[1],
					onSelect: function(dateText){
						var split = dateText.split("/");
						$("#checkInMonth").val(split[0])
						$("#checkInDay").val(split[1])
						$("#checkInYear").val(split[2])
						
						$("#MM1").val(split[0])
						$("#DD1").val(split[1])
						$("#YY1").val(split[2])
						
						$("#"+$("#datepicker").datepicker("option", "altField")).val(dateText);
						$("#datepicker").remove();
					}
					
				}				
			break;
			case "text":
				opts = {
					minDate: 0, 
					maxDate: '+1Y',	
					dateFormat:'mm-dd-yy',
					altField: arr[1],
					onSelect: function(dateText){						
						$("."+arr[1]).val(dateText);
						$("#datepicker").remove();
					}
				}
			break;
		}
		
		$("#datepicker").datepicker(opts);		
		$("#datepicker").toggle();
		
		return false;
	});
	
	$("a.modal-link").click(function()
	{
		loadModal(780, "/layout/set/modal/"+$(this).attr("href"));
		return false;
	});
	
	$("ul.activities li span.rollover").bind("mouseenter", function(){
		$("img", this).attr("rel", $("img", this).attr("src")).attr("src", $(this).attr("rel"));
	}).bind("mouseleave", function() {
		$("img", this).attr("src", $("img", this).attr("rel"));
	});
	
	/**
	 * End Generic Functions
	 */
});

function loadModal(mWidth,mURL)
{
	$("#sitewrapper").after('<div id="overlay">&nbsp;</div><div id="modal"><div id="modal-content"><img src="' + assets + 'images/spinner.gif"></div></div>');
	$("#overlay").css({width:$("body").width(),height:$(document).height()}).show();
	$("#modal").css({"top":($(document).scrollTop()+100),"left":($(window).width()/2)-(mWidth/2)});
	$("#modal").animate({"width":mWidth,"height":"50px"},250,function(){
		$("#modal-content").load(mURL,function(){
			$("#modal").animate({"height":$("#modal-content").outerHeight(true)},500,function(){
				$("#overlay").css({height:$(document).height()});
			});

			$("#overlay, #modal-content p.close a").click(function(){
				$("#modal").animate({"height":"50px"},500,function(){
					$("#modal-content").html("&nbsp");
					$("#modal").animate({"width":"0px","height":"0px"},500,function(){
						$("#modal").remove();
						$("#overlay").remove();
					});
				});
				return false;
			});
		});
	});
}