$(function() {

	//contact staff blurbs
	$('.staff').hover(
		function(){
			$(this).children('.staff_blurb_dormant').attr('class', 'staff_blurb_hover');
		},
		function(){
			$(this).children('.staff_blurb_hover').attr('class', 'staff_blurb_dormant');
		}
	)

	//Show list under menu category
	$('#nav > li').each(
		function() {
			var target = $(this).contents('ul');
			var height = target.height();
			var width  = 237;
			$(this).hover(
				function() {
					$(this)
						.prepend(
							'<div '+
								'id="navBacking" '+
								'style="'+
									'background: #7CA500;'+//#973075;'+//#00AEFF;'+//#00c6ff;'+
									'filter:alpha(opacity=90);'+
									'opacity: 0.8;'+
									'height:'+height+'px;'+
									'width:'+width+'px;'+
									'position:absolute;'+
									'top:20px;'+
									'z-index:1;'+
							'"></div>');
					target.show()
						.css({
							position:'relative',
							'z-index':'10'
							});
				},
				function() {
					$(this).contents('ul').hide();
					$('#navBacking').remove();
				});
		});

	//Do hover effects on nav list items
	$("#nav > li > ul > li > a").hover(
		function() {
			$(this).css({background:'#9c0', color:'black'});
		},
		function() {
			$(this).css({background:'none', color:'white'})
		});

	//news
	$('.news')
		.each(
			function() {
				$(this)
					.hover( function() {
							$(this).css( {
								background:'#9c0',
								color:'black'
							});
						},
						function() {
							$(this).css( {
								background:'#666',
								color:'white'
							});
						})
					.click( function(){
							window.location = $(this).find('a').attr('href');
						})
					.find('a').hide();
	})

	//pages viewed
	var page = $('#page').attr('title');
	if(page == 'home') return;
	var list;
	if(c = readCookie('viewed'))
	{
		list = c.split('|');
		c = '';
		for(i=0; i<list.length; i++)
		{
			if(!list[i].match(page))
				c += list[i]+'|';
		}
		c += page+"#"+window.location.pathname+window.location.search;
		createCookie('viewed', c, 5);
	}
	else
	{
		createCookie('viewed', page, 5);
	}
	if(!c) return;
	list = c.split('|');
	if(list.length > 7)
		limit = list.length - 7;
	else
		limit = 0;
	var cc = '<ul>';
	for(i=list.length-1; i>=limit; i--)
	{
		var lump = list[i].split('#');
		if(lump[0] == 'undefined') continue;
		cc += '<li>'+
					'<a href="'+lump[1]+'">'+
					lump[0]+
					'</a></li>';
	}
	cc += '</ul>';
	$('#pageHistory').append(cc);
});

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);
}

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=/";
}
