/*
	NAMA scripts (utilizing jQuery 1.2.6)
	Developed by Saforian
*/

var hometimer = null;


/* --- Initialize page --- */
$(document).ready(function(){

	// Stripe row colors
	$("table.data tr:nth-child(even)").not(".even").not(".odd").addClass("even");

	// Insert document icons
	$("a[href$=pdf]:not(:has(img))").append('<img class="icon" src="/images/icon_pdf.gif" width="14" height="14" alt=" (PDF)">');
	$("a[href$=doc]:not(:has(img)), a[href$=docx]:not(:has(img))").append('<img class="icon" src="/images/icon_word.gif" width="14" height="14" alt=" (Word Document)">');
	$("a[href$=xls]:not(:has(img)), a[href$=xlsx]:not(:has(img))").append('<img class="icon" src="/images/icon_excel.gif" width="14" height="14" alt=" (Excel Spreadsheet)">');
	$("a[href$=ppt]:not(:has(img)), a[href$=pptx]:not(:has(img))").append('<img class="icon" src="/images/icon_powerpoint.gif" width="14" height="14" alt=" (Powerpoint Presentation)">');

	// Column childs (IE6 selector fix)
	$(".columns .col:last-child").addClass("last-child");
	$(".three .col:first-child").addClass("first-child");

	// Add wrappers to boxes
	$(".box").wrapInner("<div class='wrapper'><div class='wrapper'></div></div>");


	/* Homepage links */

	// Set timer for auto-rotation until manual action is taken
	hometimer = window.setInterval('homerotate()', 3400);

	// Manual action
	$("#homelinks a")
		.mouseover(function(){ stophomerotate(); return homelinks(this); })

		// Register clicks and keyboard focus
		.click(function(){ $(this).mouseover(); return false; })
		.focus(function(){ $(this).mouseover(); });


	// IE6 PNG fix
	iepng();
});


// Switch to next homepage title link
function homerotate() {

	var $nextlink = $("#homelinks a.active").next("a");

	// If on last link, switch to first
	if ($nextlink.size() == 0) {
		$nextlink = $("#homelinks a:first");
	}

	// Rotate to next link
	$nextlink.each(function(){
		homelinks(this);
	});
}


// Stop auto-rotation
function stophomerotate(){
	if (hometimer != null) {
		window.clearInterval(hometimer);
		hometimer = null;
	}
}


// Change active homepage title links
function homelinks(newlink) {

	// Don't change if already active
	if ($(newlink).is(".active")) return false;

	// Hide current area
	$("#homelinks a.active").each(function(){
		var activehash = this.hash;

		$(this).removeClass("active");
		$(activehash).fadeOut("normal");
	});

	// Show new area
	var hash = newlink.hash;
	$(newlink).addClass("active");
	$(hash).fadeIn("slow");

	return false;
};


// IE 5.5 - 6.0 PNG support
function iepng() {
	var i, src, div;

	var isIE = (document.all && navigator.appName == "Microsoft Internet Explorer" &&
	(navigator.userAgent.indexOf("MSIE 5.5") >= 0 || navigator.userAgent.indexOf("MSIE 6.") >= 0));

	if (!isIE) return;

	// Inline image PNG transparency for IE (derived from youngpup.net)
	for (i = document.images.length - 1, img = null; (img = document.images[i]); i--)
		if (img.src.match(/\.png$/i) != null) {
			src = img.src;

			div = document.createElement("div");
			div.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizing='scale')";
			div.style.width = img.width + "px";
			div.style.height = img.height + "px";
			div.id = img.id;
			div.className = img.className;
			img.replaceNode(div);
		}
}
