// JavaScript Document

/*  This script was written by Aaron Gough for Walden
    http://aarongough.com http://waldendesign.com
	
	This script requires jQuery 1.2.1     */
	
var menuVisible = true;
var sponsorList = "";
var sponsorNo = 555;
	
function init ()
	{
    if( readCookie('mast') != "open" )
		{
		jQuery("#secondary_menu").hide();
		menuVisible = false;
		}
	
	jQuery("#menu_trigger").click( toggleMenu );
	
	sponsorList = jQuery(".sponsors");
	
	jQuery(".sponsors li").hide();
	jQuery(".sponsors").show();
	
	setInterval( cycleSponsors, 5000 );
	cycleSponsors();
	
	
	//This bit of code finds any links that point to the page we are already at ( read: menu link! ) and highlights them in a given color... voila! Easy context highlighting.
	var links = document.getElementsByTagName( "a" );
	for( var x = 0; x < links.length; x++)
		{
		if( window.location.href == links[x])
			{
			links[x].style.color = "#efb310";	
			}
		}
	}
	
function toggleMenu ()
	{
	if( !menuVisible )
		{
		jQuery("#secondary_menu").slideDown("slow");
		menuVisible = true;
		createCookie("mast", "open");
		}
	else
		{
		jQuery("#secondary_menu").slideUp("slow");
		menuVisible = false;
		createCookie("mast", "closed");
		}
	}
	
function cycleSponsors ()
	{
	var sponsors = jQuery(".sponsors li");
    if( sponsorNo == 555 ) sponsorNo = 0;
	else
		{
		jQuery(sponsors[ sponsorNo ]).slideUp("normal");
		sponsorNo++;
		if( sponsorNo > ( sponsors.length - 1 ) ) sponsorNo = 0;
		}
	jQuery(sponsors[ sponsorNo ]).slideDown("normal");
	}
	
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
	
jQuery(document).ready( init );