/*
This file compensates for the lack of certain CSS 2.1 selectors (notably :first-child and :hover) in 
InternetExplorer 6.  It also handles photogallery thumbnails and font size widgets. Also handles some 
special functionality for the events filter form
*/

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 clearFilters(oInput){
	var oFilterForm = document.getElementById("filter_form");
	var oFilterGroup = new Array();
	var count = 0;

	for(var i=0; i<oFilterForm.elements.length; i++){
		if(oFilterForm.elements[i].name == oInput.name){
			oFilterGroup[count] = oFilterForm.elements[i];
			count++;
		}
	}

	if(oInput == oFilterGroup[0]){
		if(oInput.checked){
			for(i=0; i<oFilterGroup.length; i++){
				oFilterGroup[i].checked = true;
			}
		} else {
			for(i=0; i<oFilterGroup.length; i++){
				oFilterGroup[i].checked = false;
			}	
		}
	} else {
		oFilterGroup[0].checked = false;
	}
}

function compensate_init() {
	//COMPENSATE FOR LACK OF A RELIABLE :FIRST-CHILD SELECTOR	
	//$j("#header li:first-child").addClass("first");
	$j("#footer li:first-child").addClass("first");
	$j("#content .chunk h2").append("&nbsp;<img src=\"/ui/img/arrow.gif\" alt=\"\" / class=\"arrow\">");
	$j(".pod:first-child").addClass("first");
	$j("#main .chunk").hover(
		function(){ $j(this).addClass("chunk-over"); },
		function(){ $j(this).removeClass("chunk-over"); }
	);
	$j("#main .review").hover(
		function(){ $j(this).addClass("review-over"); },
		function(){ $j(this).removeClass("review-over"); }
	);
	$j("#main .chunk").click(function(){
		var link = $j("h2 a", this);
		var the_href = link.get(0).getAttribute("href", 2);
		window.location.href = the_href;
		return false;
	});
	$j("#main .review").click(function(){
		var link = $j("h3 a", this);
		var the_href = link.get(0).getAttribute("href", 2);
		window.location.href = the_href;
		return false;
	});
	$j(".gallery_link").bind("click", function (e){
		$j("#main_photo").get(0).src = this.getAttribute("href", 2);
		$j("#main_photo_caption").html($j("#gallery_" + this.getAttribute("id")).html());
		$j("#main_photo").get(0).setAttribute("alt", $j("img", this).get(0).getAttribute("alt"));
		return false;
	});
	
	
	//FONT SIZE WIDGETS
	$j(".font_size_up_link").bind("click", function(e){
		$j("body").addClass("largeprint");
		$j(".font_size_up_link").hide();
		$j(".font_size_down_link").show();
		createCookie("fontsize", "largeprint", 365);
		return false;
	});
	$j(".font_size_down_link").bind("click", function(e){
		$j("body").removeClass("largeprint");
		$j(".font_size_up_link").show();
		$j(".font_size_down_link").hide();
		createCookie("fontsize", "normal", 365);
		return false;
	});
	if (cookiecontents == "largeprint") { 
		$j("body").addClass("largeprint"); $j(".font_size_up_link").hide(); }
	else { 
		$j(".font_size_down_link").hide(); 
	}
	$j(".font_size_up_link").html("<img src=\"/ui/img/font_up.gif\" alt=\"Increase Font Size\" />");
	$j(".font_size_down_link").html("<img src=\"/ui/img/font_down.gif\" alt=\"Decrease Font Size\" />");
}
function remove_compensate() { //redefines the function to be empty so it won't execute a second time in Firefox 1.5.*
	compensate_init = function() { /*pass */ }
}
window.onpageshow = function() {
	compensate_init();
	remove_compensate();
};

var cookiecontents = readCookie("fontsize");
var initialized = false;
$j(document).load(window.onpageshow);


