/*
	NVTC scripts (utilizing jQuery 1.2.6)
	Developed by Saforian
*/




/* --- 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);
	});
}





// Logo sliding animation
function slideleft(){

	$obj = $("#partners-logos ul");

	var offset = parseInt($obj.css("left"));

	if (offset > -logowidth) {
		// Slide left
		$obj.css("left", (offset-sliderDistance) + "px");

	} else {
		// Reset position
		$obj.css("left", "800px");
	}
}


/* --- Navigation pull-downs --- */

function navpulldown(clickedButton) {
	var $current = $(clickedButton);
	var $parentli = $current.parent();

	// Find associated pull-down
	var $matchingBox = $('div#' + $parentli.attr("id") + '_box');


	// Check if already selected/open
	if ($parentli.hasClass("open")) {

		// Hide open pull-down
		$matchingBox.slideUp('fast', function(){
			// Change tab state
			$parentli.removeClass("open");
		});

	} else {

		// Hide other open pull-down
		oldboxid = $("#navigation>li.open").attr("id");
		$oldbox = $('div#' + oldboxid + '_box');
		$oldbox.css("zIndex", "10").slideUp();

		// Change other open tab state
		$("#navigation>li.open").removeClass("open");

		// Show new pull-down
		$parentli.addClass("open");
		$matchingBox.css("zIndex","90").slideDown();
	}

	return false;
}



/* handler for drop-down buttons */
function toggleDropDown(clickedButton)
{
	var $matchingMenu = $($(this).next());//$('div#' + $($(this).next()).attr("id") );// + '_menu');

	// check to see if we're already visible
	var alreadyVisible = $matchingMenu.is(":visible");

	// if we were already selected, then this click should close us
	if (!alreadyVisible)
	{
		$matchingMenu.slideDown();
		return false;
	}
	else
	{
		$matchingMenu.slideUp();
		return false;
	}
}

/* handler for hiding */
function hideDropDown(objToHide)
{
	$(objToHide).slideUp();
/*
	if (this.class == "dropdown_button")
	{
		var matchingMenu = $('div#' + this.id + '_menu');
	}
	else
	{
		var matchingMenu = $('div#' + this.id);
	}

	// check to see if we're already visible
	var alreadyVisible = matchingMenu.is(":visible");

	// if we were already selected, then this click should close us
	if (alreadyVisible)
	{
		matchingMenu.slideUp();
	}
*/
}



/* --- 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");
	
	$("#news ul li:last-child").addClass("last");

	// View more buttons
	$("a.morebutton").wrapInner("<span></span>");
	$(".bil_button").wrapInner("<span></span>");


	// Hide all but first cycling item

	/* Cycling boxes */

	/* Cycling Calendar boxes */

	// Hide all but first cycling item
	$(".calendar").each(function(){
		$(this).children("div.calendar_item:not(':eq(0)')").hide();
	});

	$(".calendar_arrows .calendar_next").click(function(){

		// Capture this box and its children
		var $cyclebox = $(this).parents("div.calendar");
		var $cycleitems = $cyclebox.children("div.calendar_item");

		var $active = $cycleitems.filter(":visible");

		// Loop to beginning?
		if ($cycleitems.eq($cycleitems.length-1).is(":visible")) {
			var $next = $cycleitems.eq(0);
		} else {
			var $next = $active.next("div");
		}

		$active.hide();
		$next.show();
		return false;
	});

	$(".calendar_arrows .calendar_prev").click(function(){

		// Capture this box and its children
		var $cyclebox = $(this).parents("div.calendar");
		var $cycleitems = $cyclebox.children("div.calendar_item");

		var $active = $cycleitems.filter(":visible");

		// Loop to end?
		if ($cycleitems.eq(0).is(":visible")) {
			var $next = $cycleitems.eq($cycleitems.length-1);
		} else {
			var $next = $active.prev("div");
		}

		$active.hide();
		$next.show();
		return false;
	});
	

//$(".cycle_item>#video").wrap('<div class="cycle_video"></div>');

	// Tabbed box
	$(".tabbox>ul.tabs>li>a").each(function(){

			// Hide all boxes (except hard-coded active one)
			if (!$(this).parent("li").is(".active")) {
				$(this.hash).hide();
			}

		}).click(function(){

			// Hide current tab
			$(this).parents("ul.tabs").find("li.active a").each(function(){
				var oldtab = this;  // Avoid 'this' conflicts
				$(oldtab.hash).hide();
				$(oldtab).parent("li").removeClass("active");
			});

			// Show new one
			$(this.hash).show();
			$(this).parent("li").addClass("active");

			return false;
		});


	// IE6 helper functions
	if ($.browser.msie && $.browser.version < 7) {

		// PNG fix
		iepngfix();
	}


	// Primary navigation pull-downs
	
	$("#navigation>li>a.arrow").click(function(){
		return navpulldown(this);
	});

//$("div.dropdown_button_menu").wrap("<div class='dropdown_button_menu_wrap'></div>");
	// initialize dropdown buttons
	var dropdown_buttons = $("a.dropdown_button");
	var dropdown_button_menus = $("div.dropdown_button_menu");
	dropdown_buttons.each(function() {
				this.onclick = toggleDropDown
	});


});

// iWEB popup window

function openWindow(URL, width, height) {
	popWin = window.open(URL, "popWin", "width=" + 800 + ",height=" + 800 + ",resizable=1,scrollbars=1,location=0,toolbar=0");
}