/**
 * EXPLICITLY DECLARED PAGE SCOPED VARIABLES
 */
// Element ID of selected tab on product page
var selectedTabIndex = 1;
// Element ID of selected tab on product page
var maxTabContentHeight = 0;

/* --------------------------------------------------------------------- */

/**
 * Displays the div element that holds the selected tab content
 *
 * @param	index	(Number) - index of tab html element id
 */
function overCategory(elmt) {
	elmt.className = "category selected";
}
function offCategory(elmt) {
	elmt.className = "category";
}

function overProduct(elmt) {
	elmt.style.backgroundImage = "url('/media/img/arrows/arrow_category_on.gif')";
	elmt.className = "product selected";
}
function offProduct(elmt) {
	elmt.style.backgroundImage = "url('/media/img/arrows/arrow_category_off.gif')";
	elmt.className = "product";
}

/**
 * Displays the div element that holds the selected tab content
 *
 * @param	index	(Number) - index of tab html element id
 */
function selectTab(index) {
	// Increase height of container if needed
	//setTabContentHeight(index);

	// Hide all tabs and content elements
	$(".tabcontenton").attr("class", "tabcontentoff");
	$(".tabon").attr("class", "taboff");

	// Display tab and content
	$("#tab" + index).attr("class", "tabon");
	$("#tabContent" + index).attr("class", "tabcontenton");
	
	// Update current tab page variable
	selectedTabIndex = index;
}

/**
 * Sets the maximum height needed for the tabcontent div which houses the
 * content divs for the tabs.  Height only increased if the passed
 * element is larger in height.
 */
function setTabContentHeight(index) {
	var newTabContentHeight = Element.getHeight('tabContent' + index);
	var oldTabContentHeight = Element.getHeight('tabContent' + selectedTabIndex);
	//alert(oldTabContentHeight + "\n" + newTabContentHeight);	
	var tallerTab = Math.max(newTabContentHeight, oldTabContentHeight);
	if (tallerTab > maxTabContentHeight) {
		maxTabContentHeight = tallerTab;
		getElement('tabcontent').style.height = maxTabContentHeight + "px";
	}
}

/**
 * Handles clicking of SKU link on a product page.
 */
function goto(url, useNewWindow) {
	document.location.href=url;
}

$(document).ready(function() {
	$("a[href^='/videos/']").click(function() {
		$.fancybox({
			'scrolling' : 'no',
			'height' : (this.rel) ? new Number(this.rel).valueOf() : 386,
			'href' : this.href,
			'width' : 540,
			'speedIn' : 600,
			'type' : 'iframe'
		});
		return false;
	})
});
