/*
New suckerfish menu
*/
$(document).ready(function(){
	$("#nav-one li").hover(
		function(){ $("ul", this).fadeIn("fast"); }, 
		function() { } 
	);

  	if (document.all) {
		$("#nav-one li").hoverClass ("sfHover");
	}
	
	rollovers();
	rollover_custom();
});
	  
$.fn.hoverClass = function(c) {
	return this.each(function(){
		$(this).hover( 
			function() { $(this).addClass(c);  },
			function() { $(this).removeClass(c); }
		);
	});
};


function rollovers()
{
	$(".rollover").hover(
		function () {
			imgSrc = $(this).attr("src");
			newImgSrc = imgSrc.replace("_off","_on");
			
			$(this).attr("src",newImgSrc);
		}, 
		function () {
			imgSrc = $(this).attr("src");
			newImgSrc = imgSrc.replace("_on","_off");
			
			$(this).attr("src",newImgSrc);
		}
	);
}

function scrollTo(id, nofade)
{
	if(nofade == undefined)
		nofade = false;

	$.scrollTo($('div#'+id), 1000);


	if(nofade == false)
	{
		$('div#'+id).animate({opacity: "0.4"}, 500, function() { $('div#'+id).animate({opacity: "1.0"}, 500); });
	
		$('div#left_panel a').removeClass("on");
		$('a.'+id).addClass("on");
	}
}

function isEmail(str)
{
	if(str == "") return false;

	var re = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i

	return re.test(str);
}

function validateContactForm()
{
	var name = $("input[name='Name']").val();
	var email = $("input[name='Email']").val();
	
	if(name == "")
	{
		alert("Please enter in your name.");
		return false;
	}
	else if(!isEmail(email))
	{
		alert("Please enter in your email address.");
		return false;
	}
	else
	{
		return true;
	}
}

function switchColours(id)
{
	if(id == "2tone")
	{
		$('div#3tone').hide();
		$('div#2tone').show();
		
		$('img#2tonebtn').attr("src","images/colour_2tone_on.png");
		$('img#3tonebtn').attr("src","images/colour_3tone_off.png");
	}
	else
	{
		$('div#2tone').hide();
		$('div#3tone').show();
		
		$('img#2tonebtn').attr("src","images/colour_2tone_off.png");
		$('img#3tonebtn').attr("src","images/colour_3tone_on.png");
	}
}

function rollover_custom()
{
	$(".rollover_custom").hover(
		function () {
			imgSrc = $(this).attr("src");
			newImgSrc = imgSrc.replace("_off","_on");
			
			$(this).attr("src",newImgSrc);
		}, 
		function () {
			id = $(this).attr("id");
			id = id.replace("btn","");
			if($('div#'+id).css("display") != "block")
			{
				imgSrc = $(this).attr("src");
				newImgSrc = imgSrc.replace("_on","_off");
			
				$(this).attr("src",newImgSrc);
			}
		}
	);
}