$(function(){	 
	/***
	 * Generic functions that come out of the box
	 */
	
	$("#collapse-more").hide();
	if ($("#collapse-more").length && $("p#collapse-read_more").length) {
		$("p#collapse-read_more a").click(function() {
			$("#collapse-more").slideToggle(700, function() {
				$("p#collapse-read_more a").toggleClass("more-hide");
				($("p#collapse-read_more a").hasClass("more-hide")) ? $("p#collapse-read_more a").html("Close") : $("p#collapse-read_more a").html("Read More");
	      		});
		  
			return false;
		});
	}
	
	$("form input[type=text]").focus(function(){
		var $default = $(this).val();
		$(this).val("");
		$(this).blur(function(){
			if($(this).val()=="") $(this).val($default);
		});
	});

    if($("a[rel^='prettyPhoto']").size()>0){
        $("a[rel^='prettyPhoto']").prettyPhoto({
            theme: 'facebook',
            default_width: 740,
            default_height: 700
        });
    }
	
    $("form[name=omni_reservation_form] input.arrival").datepicker({
	    closeText: 'Close',
	    dateFormat: 'mm/dd/yy',
	    defaultDate: 0,
	    minDate: '+0',
	    maxDate: '+1Y',
	    showAnim: 'slideDown',
	    showButtonPanel: true,
	    onSelect: function(date,thisPicker){
		date = $(this).datepicker("getDate");
		date.setDate(date.getDate()+1);
		$("form[name=omni_reservation_form] input.departure").datepicker("setDate",date);
	    }
	});
	
	$("form[name=omni_reservation_form] input.departure").datepicker({
	    closeText: 'Close',
	    dateFormat: 'mm/dd/yy',
	    defaultDate: +1,
	    minDate: '+1',
	    maxDate: '+1Y',
	    showAnim: 'slideDown',
	    showButtonPanel: true
	});
	
	$("form.styled .date").datepicker({
		buttonImage: '/extension/cdev_base/design/cdev_base/images/calendar.png',
		buttonImageOnly: true,
		closeText: 'Close',
		dateFormat: 'MM d, yy',
		minDate: '+0',
		maxDate: '+1Y',
		showAnim: 'slideDown',
		showOn: 'both',
		showButtonPanel: true
	});
	
	$("form input.email-validate").addClass("email-invalid");
	$("form input.email-validate").each(function(){
		$(this).blur(function(){
			var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
			
			if(reg.test( $(this).val() ) == false)
				$(this).addClass("email-invalid");
			else
				$(this).removeClass("email-invalid");
		})
		
		$(this).parents("form").submit(function(){
			var valid; 
			
			$(this).find("input.email-validate").each(function(){
				if( $(this).hasClass("email-invalid") )
					valid = "false";
				else
					valid = "true";
			});
			
			if(valid=="true"){
				return true;
			}else{
				alert('Please enter a valid email');
				return false;
			}
		});
	});
	
	$("a.modal-link").click(function()
			{
				loadModal(780, "/layout/set/modal/"+$(this).attr("href"));
				alert ($(this).attr("href"));
				return false;
			});
			
			/**
			 * End Generic Functions
			 */
		});

		$( document ).ready(
	function()
	{
		if( $(window).height() < 580 )
		{
			var splash = $( '#splash' )
			if( splash.length > 0 )
			{
				splash.css( 'top', 0 );
				splash.css( 'margin-top', 0 );
			}
		}
	}
);

		function loadModal(mWidth,mURL)
		{
			$("body").append('<div id="overlay">&nbsp;</div><div id="modal"><div id="modal-content" class="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;
					});
				});
			});
		}

