/*
	ISBA scripts (utilizing jQuery 1.2.6)
	Developed by Saforian
*/

/* --- 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 CSS3 fix
	$(".columns .col:last-child").addClass("last-child");
	$(".columns .col:first-child").addClass("first-child");
	$(".columns.three .col:eq(1)").addClass("middle-child");


	// Homepage even column height
	if (document.getElementById("home")) {
		resizehome();
		// Check again on resize
		$(window).resize(function(){ resizehome(); });
	}


	// Flyout nav right-alignment
	$("#navigation td").not(".sep").slice(-2).addClass("end");


	// IE6 helper functions
	if ($.browser.msie && $.browser.version < 7) {

		// Navigation hover (can't set parent class due to speed delay)
		$("#navigation td").hover(function(){
			$(this)
				.children("div").css("display", "block")
				.end()
				.children("a").addClass("hover");

		},function(){
			$(this)
				.children("div").css("display", "none")
				.end()
				.children("a").removeClass("hover");

		});

		// PNG fix
		iepngfix();
	}

});



/* --- Homepage even column height --- */
function resizehome() {
	var colheight = 0;

	if ($.browser.msie && $.browser.version < 7) {

		// IE6
		$("body#home #contentwrapper div.columns>div").each(function(){
			// Get new current height
			colheight = Math.max(colheight, $(this).height());
		})
		.height(colheight + "px");

	} else {

		// All other browsers
		$("body#home #contentwrapper div.columns>div").each(function(){
			// Reset minimum height
			$(this).css("minHeight", "1px");

			// Get new current height
			colheight = Math.max(colheight, $(this).height());
		})
		.css("minHeight", colheight + "px");

	}
}


/* --- IE6 PNG fix --- */
function iepngfix() {

	// IE 5.5 and 6.0 PNG filter support (derived from youngpup.net)
	$("img[src$=png]").each(function(){
		var src = this.src;
		var div = document.createElement("div");

		// Set replacement div properties
		div.id = this.id;
		div.className = this.className;
		div.title = this.title || this.alt;
		div.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.src + "', sizing='scale')";
		div.style.width = this.width + "px";
		div.style.height = this.height + "px";

		// Replace image with transparent div
		this.replaceNode(div);
	});
}