/*
	DashGo homepage scripts (utilizing jQuery 1.2.3)
	Developed by Noah Lazar, 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)").append('<img class="icon" src="images/icon_word.gif" width="14" height="14" alt=" (Word Document)">');
	$("a[href$=xls]").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)").append('<img class="icon" src="images/icon_powerpoint.gif" width="14" height="14" alt=" (Powerpoint Presentation)">');

	// CSS3 first and last child replacement
	$(".columns .col:last-child").addClass("last-child");
	$(".three .col:first-child").addClass("first-child");


	// Navigation tabs and sections
	initTabs();


	// IE6 interface fixes
	if ($.browser.msie && $.browser.version <= 6) {
		initIE6();
	}

});



// Toggle hide/show/edit for boxes
function initTabs(){

	var $tabs = $("#tabs");

	// Get active tab
	var $activetab = $tabs.find("li.active");

	// Hide content blocks
	$("#content .section").hide();

	// Show box
	$("#tabs a").click(function(){

		var oldtab;
		var newtab = this;

		// Get old tab object
		$("#tabs li.active a").each(function(){
			oldtab = this;
		});

		// Don't change same tab
		if (oldtab == newtab) { return false; }


		if (oldtab) {

			// Hide section
			$(oldtab.hash).slideUp("fast", function(){

				// Change active tab
				$(oldtab).parent("li").removeClass("active");
				$(newtab).parent("li").addClass("active");

				// Show new section
				$(newtab.hash).slideDown("normal");
			});

		} else {

			// First time, just show new section
			$(newtab.hash).show();
			$(newtab).parent("li").addClass("active");

		}

		return false;

	}).filter(":first").click();
	
}


// IE6 fixes for missing CSS features
function initIE6(){

	// PNG support
	$("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);

	});

}
