$(function(){	 
	/***
	 * Generic functions that come out of the box
	 */

	Cufon.replace('h1,h3');
	
	
	$("span.collapse-content").hide();
	$("a.collapse").click(function(){
		$(this).parents("div").children("span.collapse-content").slideToggle("slow");
		$(this).toggleClass("hide");
		($(this).text() == "Read More") ? $(this).text("Hide") : $(this).text("Read More");
		
		return false;
	});
	
	
	var num_mastheads = $("#masthead-images img").length
		
	/* $("#header-wrapper").everyTime("8s", "masthead", function() {
		onDeck = $("#header-wrapper").attr("rel");
		if (onDeck == undefined || onDeck == false || onDeck >= num_mastheads) {
			onDeck = 0;
		} 
		src=$($("#masthead-images img").get(onDeck)).attr("src");
		alert(src)
		$("#header-wrapper").css("background", "transparent url("+src+") 50% 100px no-repeat");
		onDeck++;
		$("#header-wrapper").attr("rel", onDeck);
	})*/
	
	/*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){
		var boxes = [];
		$('a.lightbox').each(function() {
		    //push only unique lightbox[gallery_name] into boxen array
			if ($(this).attr('rel') != undefined) {
				if ($.inArray($(this).attr('rel'),boxes)) boxes.push($(this).attr('rel'));
			}
		  });
		  //for each unique lightbox group, apply the lightBox
		$(boxes).each(function(i,val) { $('a[rel='+val+']').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(){		
		$("#footer-wrapper").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("_");
		var altField = $(this).attr("rel");
		
		switch(arr[0])
		{
			case "res":
				opts = {
					minDate: 0, 
					maxDate: '+1Y',
					dateFormat:'mm-dd-yy',
					altField: altField,
					onSelect: function(dateText){
						$("#"+$("#datepicker").datepicker("option", "altField")).val(dateText);
						$("#datepicker").remove();
					}
					
				}				
			break;
			case "text":
				opts = {
					minDate: 0, 
					maxDate: '+1Y',	
					dateFormat:'mm-dd-yy',
					altField: altField,
					onSelect: function(dateText){	
						$("#"+$("#datepicker").datepicker("option", "altField")).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;
	});
	
	$("a.rollover").hover(function() {
		$("img", this).attr("rel", $("img",this).attr("src"));
		$("img", this).attr("src", $(this).attr("rel"));
		
	}, 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;
			});
		});
	});
}