// LAKE FEVER JavaScript Document

function doMail(user,domain) {
	locationstring = "mailto:" + user + "@" + domain;
	window.location = locationstring;
}

function checkEmail(addy) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(addy)){
		return (true)
	} else {
		return (false)
	}
}

/* MUSIC */
function $$(id) {
	 if ($.browser.msie) {
		return window[id];
	 }
	 else {
		return document[id];
	 }
}

var nowPlaying = 0;

function jsSendAudio(sender) {
	
	var targ = $("#preview"+sender).attr("href");
	targ = targ.replace("_preview/","");
	targ = targ.replace(".mp3","");
	
	if (nowPlaying == sender){
		jsStopAudio();
		nowPlaying = 0;
	} else {
		if (nowPlaying){
			jsStopAudio();
		}
		$$('previewer').sendAudio(targ);
		$("#preview"+sender).addClass("active");

		nowPlaying = sender;
	}
}
function jsStopAudio(){
	$$('previewer').stopAudio();
	$("#preview"+nowPlaying).removeClass("active");
}
function switchPreview(){
	$("#preview"+nowPlaying).removeClass("active");
}


// CONTACT page
function sendForm(){
	thename = $("#thename").val();
	theemail = $("#theemail").val();
	themsg = $("#themessage").val();
	smsg = "";
	$("#therror").html(" ");
	
	if (!themsg){
		smsg = "Please provide a message.";
	}
	if (!theemail){
		smsg = "Please provide a valid email.";
	}
	if (!checkEmail(theemail)){
		smsg = "Please provide a valid email.";
	}
	if (!thename){
		smsg = "Please provide a name.";
	}
	
	
	if (!smsg){
		
		$.post("_lib/func_contact.php",
       		{action: 'send', author: thename, email: theemail, msg: themsg, key: "lfs"},
      		function(data)
         	{
				if (data == "ok"){
					sendSuccess();
				} else {
					$("#therror").html("<strong>Message Not Sent!</strong><br />We're not sure why but your message was unable to be sent. Please try the email links in the footer.");
					$("#therror").fadeIn();
				}
				
		
				

        	});
		
	
		
	} else {
		$("#therror").html("<strong>Message Not Sent!</strong><br />"+smsg);
		$("#therror").fadeIn();
	}
		
}
function sendSuccess(){
	$(".theform").slideUp();
	$(".sent").slideDown();
}
function resetForm(){
	$(".theform").slideDown();
	
	$(".sent").slideUp();
	$("#themessage").val("");
}
function showMore(targ){
	// <a href="#" onclick="showMore('3'); return false;" class="readmore" id="more3"><span class="arrow">&raquo;</span> Read More</a><div class="extended" id="extended3"><br />
	$("#more"+targ).hide();
	$("#extended"+targ).slideDown();
}

$(document).ready(function() {
	// setup mailing list
	// clear the email input field on focus
	// restore default value on exit
	$("#headerInputEmail").focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
		}).blur(function() {
			if( !this.value.length ) {
				this.value = this.defaultValue;
		}
	});
	
	// disable the Get Updates nav function
	$("#navUpdates").click(function(){
		if ($("#nav .updateBlock").css("display") != "block"){
			$("#nav .updateBlock").slideDown();
		} else {
			$("#nav .updateBlock").slideUp();
		}
		return false;
	});
	
	if ($("#navPromo").exists()){
		setTimeout("showPromo()", 3000);	
	}
	
});


function showPromo(){
	$("#navPromo").fadeIn("slow");	
}
/* jQUERY */
/*	******************************
		PLUGIN - Utility Functions 
		Author: Jack Lukic - KNI (all plugins)
		Notes: Used to extend jQuery functionality and shorten code
	******************************	*/

jQuery.fn.extend({
	// test if el exists
	exists: function() {
		if(this.size() > 0) {
			return true;
		}
		else {
			return false;	
		}
	}
});
