var curr = null;
var tab = null;
var pos = [150, 270, 390, 490, 590, 710, 810];
var myindex;
var current = null;
var t = null;

function resetDiv() {

	clearTimeout(t);	
 
		$(curr).fadeIn("slow");
		$("#uppernav").css("margin-left", pos[myindex]);
	
}

function initNavRollovers() {


	$("a#why").hover( 
					 
		function()
		{
			hideAll();
			$("#top_why").css({display: "block"});
			$("#uppernav").css("margin-left", pos[0]);		
		},
		
		function() 
		{						 
			hideAll();			
			tab = null;
			tab = $(this).find("img").attr("alt");			
			tab = "#top_"+tab.toLowerCase();
			t = setTimeout("resetDiv()", 1000);

		}		
	) 
	$("a#what").hover(
		function()
		{			
			hideAll();
			$("#top_what").css({display: "block"});
			$("#uppernav").css("margin-left", pos[1]);

		},
		function() 
		{				
			hideAll();			
			tab = null;
            tab = $(this).find("img").attr("alt");			
			tab = "#top_"+tab.toLowerCase();	
			t = setTimeout("resetDiv()", 1000);
		
		}
	)
	$('a#how').hover(
		function()
		{
			hideAll();
			$("#top_how").css({display: "block"});
			$('#uppernav').css("margin-left", pos[2]);
		},
		function()
		{
			hideAll();
			tab = null;
			tab = $(this).find("img").attr("alt");
			tab = "#top_"+tab.toLowerCase();
			t = setTimeout( "resetDiv()", 1000);
		}
		
	)

	$("a#who").hover(
		function()
		{
			hideAll();
			$("#top_who").css({display: "block"});
			$("#uppernav").css("margin-left", pos[3]);
		},
		function() 
		{
			hideAll();
			tab = null;
			tab = $(this).find("img").attr("alt");
			tab = "#top_"+tab.toLowerCase();
			t = setTimeout( "resetDiv()", 1000);
		}
	)
	$("a#know").hover(
		function()
		{
			hideAll();
			$("#top_know").css({display: "block"});
			$("#uppernav").css("margin-left", pos[4]);
		},
		function() 
		{
			hideAll();
			tab = null;
			tab = $(this).find("img").attr("alt");
			tab = "#top_"+tab.toLowerCase();
			t = setTimeout( "resetDiv()", 1000);
		}
	)
	$("a#talk").hover(
		function()
		{
			hideAll();
			$("#top_talk").css({display: "block"});
			$("#uppernav").css("margin-left", pos[5]);
		},
		function() 
		{
			hideAll();
			tab = null;
			tab = $(this).find("img").attr("alt");
			tab = "#top_"+tab.toLowerCase();
			t = setTimeout( "resetDiv()", 1000);
		}
	)
	$("a#try").hover(
		function()
		{
			hideAll();
			$("#top_try").css({display: "block"});
			$("#uppernav").css("margin-left", pos[6]);
		},
		function() 
		{
			hideAll();
			tab = null;
			tab = $(this).find("img").attr("alt");
			tab = "#top_"+tab.toLowerCase();
			t = setTimeout( "resetDiv()", 1000);
		}
	)

	$("#uppernav ul li a").hover(
		function() {
			clearTimeout(t);
		},
		function() {
			t = setTimeout( "resetDiv()", 1000);
		}
		
	)
	
}
function hideAll() {
	clearTimeout(t);
	$("#uppernav ul").each(function(i) 
	{
		$(this).css({display: "none"});
	})
}

$(document).ready(function() {
	jQuery.preloadImages = function()
	{
		for(var i = 0; i<arguments.length; i++)
		{
			jQuery("<img>").attr("src", arguments[i]);
		}
	}
	
//	$.preloadImages("images/top_why.gif", "images/top_what.gif");
	hideAll();
	
	curr = $("body").attr("id");
	curr = "#top"+curr;
	$(curr).fadeIn("slow");
	current = curr;
	
	switch(current) {
		case "#top_why":
		myindex = 0;
		break;
		case "#top_what":
		myindex = 1;
		break;
		case "#top_how":
		myindex = 2;
		break;
		case "#top_who":
		myindex = 3;
		break;
		case "#top_know":
		myindex = 4;
		break;
		case "#top_talk":
		myindex = 5;
		break;
		case "#top_try":
		myindex = 6;
		break;
	}

	$('#upper').css("visibility", "visible");
	
	// Moved this code to a function so a delay can be set, this fixes rollover bug on load
	
	setTimeout("initNavRollovers()", 1200);
	
	//rollovers
		$('.rollover').each(function() {
		var origsrc;
		$(this).hover(
			function() 
			{
				origsrc = $(this).find("img").attr("src");
				var len = origsrc.length;
				var src = origsrc.substr(0, len-4);
				src = src+'_o.gif';
				$(this).find("img").attr("src", src);
			},
			
			function() 
			{
				
				$(this).find("img").attr("src", origsrc);
			}
		)
	})
	
	$(".privacy_link").click(function() {
		window.open ("privacy.html", "mywindow","width=450, height=400'");
	})
	
	$('.ourterms').click(function() {
		ourterms = window.open ("terms.html", "ourterms","width=450, height=400'");
	})
	
	$('.sitemap').click(function() {
		ourterms = window.open ("sitemap.html", "sitemap","width=450, height=400'");
	})
});

function validEmail(email) {
  var emailReg = "^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,4}$";
  var regex = new RegExp(emailReg);
  return regex.test(email);
}


