var loadedSSImages = 0;
var homeSSImages = Array("/images/ss_index_7.jpg", "/images/ss_index_6.jpg","/images/ss_index_3.jpg", "/images/ss_index_4.jpg", "/images/ss_index_5.jpg");

jQuery(function() {
	jQuery("#signupEmail").focus(function(){
		if (jQuery(this).val() == "" || jQuery(this).val() == "ENTER EMAIL HERE")
		{
			jQuery(this).val("");
		}
	});
	jQuery("#signupEmail").blur(function(){
		if (jQuery(this).val() == "" || jQuery(this).val() == "ENTER EMAIL HERE")
		{
			jQuery(this).val("ENTER EMAIL HERE");
		}
	});
	var rulesShown = false;
	jQuery("#header a.promoRules").click(function(){
		if (rulesShown)
		{
			jQuery("#promoRulesPopup").fadeOut();
			rulesShown = false;
		}
		else
		{
			jQuery("#promoRulesPopup").fadeIn();
			rulesShown = true;
		}
	});
	jQuery("#header #promoRulesPopup p.xButton").click(function(){
		jQuery("#promoRulesPopup").fadeOut();
		rulesShown = false;
	});
	
	jQuery("#borderContainer #shadow #mainContainer #mainOffer a.grandGuestroom").click(function(){
		if (rulesShown)
		{
			jQuery("#grandGuestroomPopup").fadeOut();
			rulesShown = false;
		}
		else
		{
			jQuery("#grandGuestroomPopup").fadeIn();
			rulesShown = true;
		}
	});
	jQuery("#borderContainer #shadow #mainContainer #mainOffer #grandGuestroomPopup p.xButton").click(function(){
		jQuery("#grandGuestroomPopup").fadeOut();
		rulesShown = false;
	});
	jQuery("#borderContainer #shadow #mainContainer #mainOffer a.resortAmenities").click(function(){
		if (rulesShown)
		{
			jQuery("#resortAmenitiesPopup").fadeOut();
			rulesShown = false;
		}
		else
		{
			jQuery("#resortAmenitiesPopup").fadeIn();
			rulesShown = true;
		}
	});
	jQuery("#borderContainer #shadow #mainContainer #mainOffer #resortAmenitiesPopup p.xButton").click(function(){
		jQuery("#resortAmenitiesPopup").fadeOut();
		rulesShown = false;
	});



	// preload home page ss images
	 for (var i = 0; i < homeSSImages.length; i++)
	 {
	 	var img = new Image();
	 	jQuery(img).load(function(){
	 		loadedSSImages++;
	 		finishImageLoad();
	 	}).attr("src", homeSSImages[i]);
	 }
	 // dropdown nav
	 jQuery('ul.sf-menu').superfish({speed: 0});
     
     jQuery('#testdiv1').css("z-index", "999999");

	// packages more options and family activites page
	jQuery("a.packagesExpand").unbind("click");
	jQuery("a.packagesExpand").click(function(e){
		e.preventDefault();
		jQuery(this).hide();
		jQuery(this).parent(".morePackageBullets").css("height", "100%");
	});
	jQuery("a.packagesContract").click(function(e){
		e.preventDefault();
		jQuery(this).parent(".morePackageBullets").find("a.packagesExpand").show();
		jQuery(this).parent(".morePackageBullets").css("height", "18px");
	});

	
	// packages page SS
	jQuery("#packagesSS").cycle({
		timeout: 5000
	});
	// top slideshows
	jQuery("#doubleSS .leftSS").cycle({
		timeout: 7000,
		delay: -3500
	});
	jQuery("#doubleSS .rightSS").cycle({
		timeout: 7000
	});
	
	jQuery("a.disabledLink").click(function(e){
		e.preventDefault();
	});
	
	jQuery("a.galClose").click(function(){
		jQuery(this).parent("div").hide();
		var area = "#" + (jQuery(this).parent("div").parent("div").attr("id")) + "Menu";
		jQuery(area).children("a").removeClass("text-link-on");
	});
    
});
function finishImageLoad()
{
	if (loadedSSImages == homeSSImages.length)
	{
		for (var i = 0; i < homeSSImages.length; i++)
		{
			$("#indexSS").append("<img src='"+homeSSImages[i]+"' />");
		}
		$("#indexSS").append("<img src='/images/ss_index_2.jpg' />");
		jQuery("#indexSS").cycle({
			timeout: 5000,
			autostop: 1
		});
		
	}
}

function printFlash(source, width, height, id, bg_color) {
document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" ');
document.write('width="'+width+'" height="'+height+'" id="'+id+'" align="middle" wmode="opaque"/>');
document.write('<param name="allowScriptAccess" value="sameDomain" />');
document.write('<param name="movie" value="'+source+'" />');
document.write('<param name="menu" value="false" />');
document.write('<param name="wmode" value="opaque" />');
document.write('<param name="quality" value="high" />');
document.write('<param name="bgcolor" value="'+bg_color+'" />');
document.write('<embed src="'+source+'" menu="false" quality="high" bgcolor="'+bg_color+'" width="'+width+'" height="'+height+'"  wmode="opaque" name="'+id+'" align="middle" ');
document.write('allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
document.write('</object>');
}

function Validate( theForm ){
	if ( theForm.Prefix.value == "" ){
		alert( 'Please provide your prefix.' );
		return false;
		}	
	if ( theForm.FirstName.value == "" || theForm.LastName.value == "" ){
		alert( 'Please enter your full name.' );
		return false;
		}	
	if ( theForm.BrideGroomWeddingParty.value == "" ){
		alert( 'Please provide the Bride/Groom Wedding Party.' );
		return false;
		}
	if ( theForm.Address1.value == "" ){
		alert( 'Please enter your address.' );
		return false;
		}
	if ( theForm.City.value == "" ){
		alert( 'Please enter your city.' );
		return false;
		}
	if ( theForm.Country.selectedIndex == 0 ){
		alert( 'Please select your country.' );
		return false;
		}
	if ( theForm.Country.selectedIndex == 1 && theForm.State.selectedIndex == 0 ){
		alert( 'Please select your state.' );
		return false;
		}
	if ( theForm.Zip.value == "" ){
		alert( 'Please enter your zip code.' );
		return false;
		}
	if ( theForm.Phone.value == "" ){
		alert( 'Please enter your phone number.' );
		return false;
		}
	if ( theForm.Email.value == "" ){
		alert( 'Please enter your email address.' );
		return false;
		}
	if ( theForm.Email.value != theForm.ConfirmEmail.value ){
		alert( 'Please make sure the email and confirm email fields match.' );
		return false;
		}
	if ( theForm.NumCeremonyGuests.value == "" ){
		alert( 'Please enter the number of Ceremony guests.' );
		return false;
		}
	if ( theForm.NumReceptionGuests.value == "" ){
		alert( 'Please enter the number of Reception guests.' );
		return false;
		}
	return true;
}


function Validate2( theForm ){
/*	if ( theForm.Prefix.value == "" ){
		alert( 'Please provide your prefix.' );
		return false;
		}	
	if ( theForm.FirstName.value == "" || theForm.LastName.value == "" ){
		alert( 'Please enter your full name.' );
		return false;
		}	
	if ( theForm.City.value == "" ){
		alert( 'Please enter your city.' );
		return false;
		}
	if ( theForm.Country.selectedIndex == 0 ){
		alert( 'Please select your country.' );
		return false;
		}
	if ( theForm.Country.selectedIndex == 1 && theForm.State.selectedIndex == 0 ){
		alert( 'Please select your state.' );
		return false;
		}
	if ( theForm.Zip.value == "" ){
		alert( 'Please enter your zip code.' );
		return false;
		}
	if ( theForm.Email.value == "" ){
		alert( 'Please enter your email address.' );
		return false;
		}
	return true;
*/	
	if ( theForm.Address1.value != "" ){
		if ( theForm.City.value == "" ){
		    alert( 'Please enter your city.' );
		    return false;
		    }
		 if ( theForm.Country.selectedIndex == 0 ){
		    alert( 'Please select your country.' );
		    return false;
		    }
	    if ( theForm.Country.selectedIndex == 1 && theForm.State.selectedIndex == 0 ){
		    alert( 'Please select your state.' );
		    return false;
		    }
	    if ( theForm.Zip.value == "" ){
		    alert( 'Please enter your zip code.' );
		    return false;
		    }      
		}	
	if ( theForm.Email.value == "" ){
		alert( 'Please enter your email address.' );
		return false;
		}
	if ( theForm.Email.value != theForm.ConfirmEmail.value ){
		alert( 'Please make sure the email and confirm email fields match.' );
		return false;
		}	
}


var newWindow = null;

function closeWin(){
	if (newWindow != null){
		if(!newWindow.closed)
			newWindow.close();
	}
}

function popUpWin(url, type, strWidth, strHeight){
	closeWin();
	if (type == "fullScreen"){
		strWidth = screen.availWidth - 10;
		strHeight = screen.availHeight - 160;
	}
	var tools="";
	if (type == "standard" || type == "fullScreen") tools = "resizable=no,toolbar=no,location=no,scroll=yes,scrollbars=yes,menubar=no,width="+strWidth+",height="+strHeight+",top=0,left=0";
	if (type == "console") tools = "resizable=no,toolbar=no,location=no,directories=no,status=no,scroll=no,scrollbars=no,menubar=no,width="+strWidth+",height="+strHeight+",left=0,top=0";
	newWindow = window.open(url, 'newWin', tools);
	newWindow.focus();
}


// remove/replace input text
function clearText(thefield) {
  if (thefield.defaultValue==thefield.value) { thefield.value = "" }
} 
function replaceText(thefield) {
  if (thefield.value=="") { thefield.value = thefield.defaultValue }
}

function spaPackageToggle(which, linkId)
{
    $(".spaPackage").hide();
    $("#package" + which).show();
    $(".packageToggleLink").removeClass("text-link-on");
    $("#packageToggle" + which).addClass("text-link-on");
}