/*
	Aruba4u.com Generic JS
	Written by: John P. Barbagallo
	john@arisemedia.net
*/
	
	// setup blur and focus for e-mail form
	function focusSuggest(textfield_id, msg, reset) {
		$("#" + textfield_id).focus(function(){
			if($(this).val() === msg) {
				$(this).val("");
				$(this).css({color: "#000"});
			}
		});
		
		if(reset){
			$("#" + textfield_id).blur(function(){
				if($(this).val() === "") {
					$(this).val(msg);
					$(this).css({color: "#999"});
				}
			});
		}
		
		if($("#" + textfield_id).val() != msg){
			$(this).css({color: "#000"});
		}
	}
	
	function sendContactForm(aFormId) {
		if($("#" + aFormId).validate().form()) {
			// hide the form
			$("#" + aFormId).slideToggle("350");
			
			// set variables to use for the ajax data
			var fullname = $("#" + aFormId + " fieldset ol>li input#fullname").attr('value');
			var email = $("#" + aFormId + " fieldset ol>li input#email").attr('value');
			var themessage = $("#" + aFormId + " fieldset ol>li textarea#themessage").val();
			
			//submit it
			$.post("submit_email.php",{fullname: fullname, email: email, themessage: themessage}, function(data){
					if(data == "success"){
						//show success msg
						$("div#contact-form-wrap h3.success").fadeIn("400");
					} else if(data == "error"){
						$("div#contact-form-wrap h3.error").fadeIn("400").fadeOut("3000");
						$("#" + aFormId).slideToggle("350");
					}					
				}
			);
		}
	}
	
	function initPreviewCycle() {
			$('div#TB_ajaxContent #main-image').cycle({
						fx:      'fade', 
						speed: 900,
						next: "div.resort-wrapper div.left-content div#next-btn",
						prev: "div.resort-wrapper div.left-content div#prev-btn"
			});
	}
	
	$(document).ready(function(){
		
		function attachNavEvents(parent, myClass) {
			$(parent + " ." + myClass).mouseover(function() {
				// create the pseudo-div for the animation
				$(this).before('<div class="nav-' + myClass + '"></div>');
				$("div.nav-" + myClass).css({display:"none"}).fadeIn(350);
			}).mouseout(function() {
				// fade out and destroy the pseudo-link
				$("div.nav-" + myClass).fadeOut(550, function() {$(this).remove();});
			}).mousedown(function() {
				// fade in highlighted menu item
				$("div.nav-"+ myClass).attr("class", "nav-" + myClass + "-click");
			}).mouseup(function() {
				// fade out
				$("div.nav-" + myClass + "-click").attr("class", "nav-" + myClass);
			});
		}
		
		attachNavEvents("ul.nav", "resorts");
		attachNavEvents("ul.nav", "specials");
		attachNavEvents("ul.nav", "about");
		attachNavEvents("ul.nav", "contact");
		attachNavEvents("ul.nav", "blog");
		
		// add the e-mail form by default
		focusSuggest("emailAddress", "YOUR@EMAIL.COM", true);
	});