/**
 * FIX IE6 IMAGE FLICKER PROBLEM
 *
 */
try {
	document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}

$(document).ready(Init);

function Init()
{
	// Setup "Print This Page"
	$("#print a").click(function() {
		window.print();
		return false;

	});
	
	// Setup "Print Contact Form"
	$("a#print").click(function() {
		window.print();
		return false;

	});

	// Data Table Striping
	$("table.data").each(function(i) {
		ZebraStripe($(this));
	});

	// Shadow Box Resizing
	ShadowBoxResize();

	// Text Resizing
	$("#small a").click(function() {
		ShadowBoxResizeReset();
		setActiveStyleSheet('small');
		ShadowBoxResize();
		return false;
	});

	$("#medium a").click(function() {
		ShadowBoxResizeReset();
		setActiveStyleSheet('medium');
		ShadowBoxResize();
		return false;
	});

	$("#large a").click(function() {
		ShadowBoxResizeReset();
		setActiveStyleSheet('large');
		ShadowBoxResize();
		return false;
	});

	// Home Page Feature Boxes
	HomeFeatures();
}


function ZebraStripe(e)
{
	$("tr.heading", e).each(function(i) {
		$("th:first", this).addClass("first");
		$("th:last", this).addClass("last");
	});

	$("tr", e).each(function(i) {
		if(i % 2 == 0)
		{
			$(this).addClass("shade");
		}
	});
}


function ShadowBoxResize()
{
	var maxHeight = 0;

	$("div.shadow div.box").each(function(i) {
		if($(this).height() > maxHeight)
		{
			maxHeight = $(this).height();
		}
	});

	$("div.shadow div.box").each(function(i) {
		$(this).height(maxHeight);
	});
}

function ShadowBoxResizeReset() {
	$("div.shadow div.box").each(function(i) {
		maxHeight = $(this).height("auto").css({minHeight:"auto"});
	});
}


function HomeFeatures()
{
	if($("#municipal-matters").size() > 0)
	{
		$("#municipal-matters").click(function(e){
			window.location.href = $("a.hdr-graphic", $(this)).attr("href");
		});
	}
	if($("#making-complaint").size() > 0)
	{
		$("#making-complaint").click(function(e){
			window.location.href = $("a.hdr-graphic", $(this)).attr("href");
		});
	}
	if($("div.shadow").size() > 0)
	{
		$("div.shadow:first").click(function(e){
			window.location.href = $("span.readmore a", $(this)).attr("href");
		});
	}
}