$(document).ready(function()
{	

	// Drop down menus for IE6
	$("#nav li").hover(
		function () 
		{
			$(this).addClass("hover");
		},
		function()
		{
			$(this).removeClass("hover");
		}
	);
	$("#nav li:last-child").not("#nav li li:last-child").addClass("last");
	
	// Add class to links that surround images
	$("a>img").parent().addClass("imagelink");
	
	// Add some fancy visual effects
	$("#header").append("<div id=\"crest\"></div>");
	$("#header").append("<div id=\"sloganbar\"></div>");
	$(".template-small-feature #feature-image img").after("<div id=\"feature-image-overlay\"></div>");
	
	// Coloured boxes on the home page and in left side and right side columns get a shadow
	$(".template-home div.box1").wrap("<div class=\"shadow-dark\"></div>");
	$(".template-home div.box2").wrap("<div class=\"shadow-light\"></div>");
	$(".template-home div.box3").wrap("<div class=\"shadow-light\"></div>");
	$(".template-home div.box4").wrap("<div class=\"shadow-light\"></div>");
	$(".content2 div.box1").not(".template-home .content2 div.box1").wrap("<div class=\"shadow-dark\"></div>");
	$(".content2 div.box2").not(".template-home .content2 div.box2").wrap("<div class=\"shadow-light\"></div>");
	$(".content2 div.box3").wrap("<div class=\"shadow-light\"></div>");
	$(".content2 div.box4").wrap("<div class=\"shadow-light\"></div>");
	$("#sidebar div.box1").wrap("<div class=\"shadow-dark\"></div>");
	$("#sidebar div.box2").wrap("<div class=\"shadow-light\"></div>");
	$("#sidebar div.box3").wrap("<div class=\"shadow-light\"></div>");
	$("#sidebar div.box4").wrap("<div class=\"shadow-light\"></div>");
	
	// IE fix
	$("div.box1").wrapInner("<div class=\"box-inner\"></div>");
	$("div.box2").wrapInner("<div class=\"box-inner\"></div>");
	$("div.box3").wrapInner("<div class=\"box-inner\"></div>");
	$("div.box4").wrapInner("<div class=\"box-inner\"></div>");

	// Links with rel="external" open in a new window
	$("a[rel='external']").attr("target","_blank");
	
	// Zebra striped table rows
	$("table.data tr:even").addClass("alt");
	
	// Print link functionality
	$("a.print").click(
		function () 
		{
			if (window.print)
				window.print();
			else
				alert("Sorry, your browser doesn't support the print feature. Use the File menu on your browser to select Print.");
			return false;	
		}
	);
	
	// Tidy up image boxes
	$(".imagebox .caption").wrapInner("<div class=\"caption-inner\"></div>");
	$("#content div.imagebox > img").each(function() 
	{
		$(this).parent().width($(this).attr("width"));
		$(this).next("div.caption").width($(this).attr("width"));
	});
	$("#content div.imagebox > img.frame").each(function() 
	{
		$(this).parent().addClass("hasframe")
	});
	
	// Add list first/last classes
	$("#footer-menu li:first-child").addClass("first");
	$("#tools li:first-child").addClass("first");
	$("#tools li:eq(1)").addClass("second");
	$("#subnav li li:first-child").not("#subnav li li li:first-child").addClass("first");
	
	// Lightbox links
	$('a.lightbox').lightBox();
	
	// Tooltips
	/* Tooltip code from: http://bassistance.de/jquery-plugins/jquery-plugin-tooltip/ */
	$(".thumbnails a").tooltip(
	{
		bodyHandler: function() { return $(this).next("div.caption").html(); },
		track: true,
		delay: 0,
		showURL: false,
		fade: 100,
		extraClass: 'large-tooltip'
	});
	$('a.hastooltip').tooltip(
	{
		track: true,
		delay: 0,
		showURL: false,
		fade: 100
	});
	
	// Fix PNG for IE6
	if(typeof pngFix==='function')
		$(document).pngFix();
	
	
	// Nice hover effect on icons
	$("img[src*='icons/']").css("opacity","0.6");
	$("img[src*='icons/']").hover(
		function () 
		{
			$(this).css("opacity","1.0");
		},
		function()
		{
			$(this).css("opacity","0.6");
		}
	);
	
	// Remove bullets on lists of file downloads
	$("li > a.ai").closest("ul").addClass("nobullet");
	$("li > a.aiff").closest("ul").addClass("nobullet");
	$("li > a.bz2").closest("ul").addClass("nobullet");
	$("li > a.c").closest("ul").addClass("nobullet");
	$("li > a.chm").closest("ul").addClass("nobullet");
	$("li > a.conf").closest("ul").addClass("nobullet");
	$("li > a.cpp").closest("ul").addClass("nobullet");
	$("li > a.css").closest("ul").addClass("nobullet");
	$("li > a.deb").closest("ul").addClass("nobullet");
	$("li > a.divx").closest("ul").addClass("nobullet");
	$("li > a.doc").closest("ul").addClass("nobullet");
	$("li > a.file").closest("ul").addClass("nobullet");
	$("li > a.gif").closest("ul").addClass("nobullet");
	$("li > a.gz").closest("ul").addClass("nobullet");
	$("li > a.hlp").closest("ul").addClass("nobullet");
	$("li > a.htm").closest("ul").addClass("nobullet");
	$("li > a.html").closest("ul").addClass("nobullet");
	$("li > a.iso").closest("ul").addClass("nobullet");
	$("li > a.jpeg").closest("ul").addClass("nobullet");
	$("li > a.jpg").closest("ul").addClass("nobullet");
	$("li > a.js").closest("ul").addClass("nobullet");
	$("li > a.mov").closest("ul").addClass("nobullet");
	$("li > a.mp3").closest("ul").addClass("nobullet");
	$("li > a.mpg").closest("ul").addClass("nobullet");
	$("li > a.odc").closest("ul").addClass("nobullet");
	$("li > a.odf").closest("ul").addClass("nobullet");
	$("li > a.odg").closest("ul").addClass("nobullet");
	$("li > a.odi").closest("ul").addClass("nobullet");
	$("li > a.odp").closest("ul").addClass("nobullet");
	$("li > a.ods").closest("ul").addClass("nobullet");
	$("li > a.odt").closest("ul").addClass("nobullet");
	$("li > a.ogg").closest("ul").addClass("nobullet");
	$("li > a.pdf").closest("ul").addClass("nobullet");
	$("li > a.php").closest("ul").addClass("nobullet");
	$("li > a.pl").closest("ul").addClass("nobullet");
	$("li > a.gif").closest("ul").addClass("nobullet");
	$("li > a.ppt").closest("ul").addClass("nobullet");
	$("li > a.ps").closest("ul").addClass("nobullet");
	$("li > a.py").closest("ul").addClass("nobullet");
	$("li > a.ram").closest("ul").addClass("nobullet");
	$("li > a.rar").closest("ul").addClass("nobullet");
	$("li > a.rb").closest("ul").addClass("nobullet");
	$("li > a.rm").closest("ul").addClass("nobullet");
	$("li > a.rpm").closest("ul").addClass("nobullet");
	$("li > a.rtf").closest("ul").addClass("nobullet");
	$("li > a.swf").closest("ul").addClass("nobullet");
	$("li > a.swx").closest("ul").addClass("nobullet");
	$("li > a.sxc").closest("ul").addClass("nobullet");
	$("li > a.sxd").closest("ul").addClass("nobullet");
	$("li > a.sxi").closest("ul").addClass("nobullet");
	$("li > a.sxw").closest("ul").addClass("nobullet");
	$("li > a.tar").closest("ul").addClass("nobullet");
	$("li > a.tex").closest("ul").addClass("nobullet");
	$("li > a.tgz").closest("ul").addClass("nobullet");
	$("li > a.txt").closest("ul").addClass("nobullet");
	$("li > a.vcf").closest("ul").addClass("nobullet");
	$("li > a.wav").closest("ul").addClass("nobullet");
	$("li > a.wma").closest("ul").addClass("nobullet");
	$("li > a.wmv").closest("ul").addClass("nobullet");
	$("li > a.xls").closest("ul").addClass("nobullet");
	$("li > a.xml").closest("ul").addClass("nobullet");
	$("li > a.xpi").closest("ul").addClass("nobullet");
	$("li > a.xvid").closest("ul").addClass("nobullet");
	$("li > a.zip").closest("ul").addClass("nobullet");

	
});



// News ticker 
/* Inspired by http://groups.google.com/group/jquery-en/browse_thread/thread/c874c299007be2bc */
var newsItems;
var currentNewsItem=0;
var isPaused=0;
var isForward=1;
var tickerTimer;

$(document).ready(function()
{
	if ($('#ticker-box').length)
	{
		
		$("#ticker-buttons").show();
		$("#ticker-pause").show();
		$("#ticker-play").hide();
		$("#ticker-box li").css("position","absolute");
		$("#ticker-box ul").css("height","225px");
		$("#ticker-box li").css("height","200px");
		
		newsItems = $("ul#ticker li").hide().hover(
			function()
			{
				isPaused=1;
			},
			function()
			{
				isPaused=0;
			}
		).filter(":eq(0)").show().add("ul#ticker li").size();
		tickerTimer = setInterval(ticknews,4000); 
		
		
		$("#ticker-pause").click(function() 
		{
			if (isPaused==0)
			{
				isPaused=1;
				$("#ticker-play").show();
				$("#ticker-pause").hide();
			}
			else
			{
				isPaused=0;
				$("#ticker-pause").show();
				$("#ticker-play").hide();
			}
		});
		
		$("#ticker-play").click(function() 
		{
			if (isPaused==0)
			{
				isPaused=1;
				$("#ticker-play").show();
				$("#ticker-pause").hide();
			}
			else
			{
				isPaused=0;
				$("#ticker-pause").show();
				$("#ticker-play").hide();
			}
		});
	
		$("#ticker-next").click(function() 
		{
			isForward=1;
			tickonce();
			clearInterval(tickerTimer)
			tickerTimer = setInterval(ticknews,4000);
		});
	
		$("#ticker-prev").click(function() 
		{
			isForward=0;
			tickonce();
			clearInterval(tickerTimer)
			tickerTimer = setInterval(ticknews,4000);
		});
	}
});

function tickonce()
{
	$("#ticker li:eq("+currentNewsItem+")").hide();
	
	if(isForward==1)
	{
		currentNewsItem = ++currentNewsItem%newsItems;
	}
	else
	{
		if(currentNewsItem==0)
			currentNewsItem=newsItems-1;
		else
			currentNewsItem=--currentNewsItem;
	}
	
	$("#ticker li:eq("+currentNewsItem+")").show();
}

function ticknews() 
{
	if (isPaused==0)
	{
		$("#ticker li:eq("+currentNewsItem+")").hide();
		
		if(isForward==1)
		{
			currentNewsItem = ++currentNewsItem%newsItems;
		}
		else
		{
			if(currentNewsItem==0)
				currentNewsItem=newsItems-1;
			else
				currentNewsItem=--currentNewsItem;
		}
		
		$("#ticker li:eq("+currentNewsItem+")").show();
	}
}


$(document).ready(function()
{
	// Reset Font Size
	var originalFontSize = $('html').css('font-size');
	var $cookie_name = "hutchins-font-size";
	
	if($.cookie($cookie_name)) 
	{
		var $getSize = $.cookie($cookie_name);
		$("html").css({fontSize : $getSize + ($getSize.indexOf("px")!=-1 ? "" : "px")}); // IE fix for double "pxpx" error
	} 
	else 
	{
		$.cookie($cookie_name, originalFontSize);
	}
	
	$(".textreset").click(function()
	{
		$('html').css('font-size', originalFontSize);
		$.cookie($cookie_name, originalFontSize);
		return false;
	});
	// Increase Font Size
	$(".textup").click(function()
	{
		var currentFontSize = $('html').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum*1.1 + "px";
		$('html').css('font-size', newFontSize);
		$.cookie($cookie_name, newFontSize);
		return false;
	});
	// Decrease Font Size
	$(".textdown").click(function()
	{
		var currentFontSize = $('#page').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum/1.1 + "px";
		$('html').css('font-size', newFontSize);
		$.cookie($cookie_name, newFontSize);
		return false;
	});
});



/* Google map functions */
$(window).resize(function()
{
	if(typeof loadMap==='function')
		loadMap();
});

$(window).unload(function()
{
	if(typeof GUnload==='function')
		GUnload();
});

$(document).ready(function()
{
	if(typeof loadMap==='function')
		loadMap();
});
