function DESemail(emailname,emailserver) {
	document.write("<a href='mailto:" + emailname + "@" + emailserver +"'>");
	document.write(emailname + "@" + emailserver); 
	document.write("</a>"); 
}

// Accessible Pop Ups
function DESopen(url,width,height,toolbar,scroll) {
	window.open(url, "", "scrollbars="+scroll+",toolbar="+toolbar+",height="+ height +",width="+width);
	return false;
}



$(document).ready(function(){
	
	
	//  Photo Gallery
	$("ul.thumbs a").click(function() {
		
		
		$("#image img").fadeOut('fast').remove();
		$("#preloading").css("display","block");
		var randomnumber=Math.floor(Math.random()*150)
		var newSrc = $(this).get(0).href;
		/*
			Add a random number to image to make browser load again
			Ensures .onload works in IE/Opera
			Rubbish hack, would like to improve
		*/
		var newSrc = ''+newSrc+'?ran='+randomnumber+'';

		var nextImg = new Image();
		nextImg.src = newSrc;
		
		var nextImgHTML = '<img src="'+newSrc+'" with="260" />';
		nextImg.onload = function()
		{
			$("#preloading").css("display","none");
			// Safari didn't like append, don't know why I used it anyways!!
			//$("#image").append(nextImg);
			$("#image").html(nextImgHTML);
			$("#image img").fadeIn('medium');
		}
			
		//if (nextImg.complete) {
		//	nextImg.onload();
		//}
		$("ul.thumbs a").removeClass("current");
		$(this).addClass("current");
		
		return false;
	});
	
	$("#ml_name").one("click",function() {
		var sqVal = $(this).val();
		if (sqVal == 'enter your name here') {
			$(this).val("");
		}
	});
	
	$("#ml_email").one("click",function() {
		var sqVal = $(this).val();
		if (sqVal == 'enter your email here') {
			$(this).val("");
		}
	});
	
	
	$("#mailing_list").submit(
		function() {
			
			var nameVal = $("#ml_name").val();
			var emailVal = $("#ml_email").val();
			
			$("#ml_name").removeClass("error");
			$("#ml_email").removeClass("error");
			
			if (nameVal=='' || nameVal=='enter your name here') {
				$("#ml_name").addClass("error");
				alert('You must enter your name');
				return false;
			}
			
			var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			// Invalid email
			if (!filter.test(emailVal)) {
				$("#ml_email").addClass("error");
				alert('You must enter a valid email address');
				return false;
			}
			
			// Submit form
			else {
				$("#signup_button").html('<img src="/img/design/spinner.gif" width="16" height="16" id="spinner" /><em>Sending Request</em>');
				$("#form_message").show();
				$.ajax({
					type: "GET",
					dataType: "html",
					url: "/incs/ahah/signup.php?email="+emailVal+"&name="+nameVal+"",
					success: function(msg){
						if (msg == 'The email address you entered is already subscribed to our mailing list') {
							$("#signup_button").html('<input type="image" src="/img/design/btn.gif" alt="Subscribe" id="subscribe-btn" />');
							alert(msg);
						}
						else {
							$("#mailing_list").hide();
							$("#mailing_list_wrap").html('<p id="form_valid"><strong>Success!</strong> You have been added to our mailing list, and will recieve our latest newsletter shortly.</p>');
						}
					}
				});
				return false;
			}
		}
	);
	
	
	

}); // End jQuery