;//---------------------------------------------------------------------------------------------------------------
var active_tab_id = 2;
var history_tab_id = 2;

//---------------------------------------------------------------------------------------------------------------
function showTab(id, site_anchor)
{
	if(isNaN(id))
		return;
		
	var active_tab = $("tab_" + active_tab_id);
	active_tab.className = "";
	var active_tabs = $("tabcontent_" + active_tab_id);
	active_tabs.style.display = "none";
	
	var tab = $("tab_" + id);
	tab.className = "tab-selected";
	var tabs = $("tabcontent_" + id);
	tabs.style.display = "block";
	active_tab_id = id;
	
	SWFAddress.setValue(tab.title + "?t=" + id);
		
	//if(id == 1)
	//	loadProductTOC(active_product_id);
		
	if(String(site_anchor).length > 0)
		if($(site_anchor) != null)
			$(site_anchor).scrollIntoView(true);
	
	return false;
}
	
//---------------------------------------------------------------------------------------------------------------
function handleTabHistory(event) 
{	
	var tab_id = 0;
	var site_anchor = "";

	for(var i = 0; i < event.parameterNames.length; i++)
	{		
		if(event.parameterNames[i] == "t")
		{
			if(event.parameters["t"] != null && event.parameters["t"] != active_tab_id)
			{
				tab_id = event.parameters["t"];
			}
		}	
		if(event.parameterNames[i] == "a")
			if(event.parameters["a"] != null)
				site_anchor = event.parameters["a"];
	}
	if(tab_id > 0)
	{
		showTab(tab_id, site_anchor);
		return;
	}
	
	if(event.path == "/" && active_tab_id != history_tab_id)
	{
		showTab(history_tab_id);
	}
}

//---------------------------------------------------------------------------------------------------------------
function initVideoDetails(video_id, product_id) 
{	
	//if(isNaN(product_id))
	//	return;
		
	//if(active_tab_id == 1)
	//	loadProductTOC(product_id);
	//active_product_id = product_id;
}

//---------------------------------------------------------------------------------------------------------------
function loadProductTOC(product_id)
{
	if(isNaN(product_id))
		return;
	
	var product_toc = $("product_toc_" + product_id);
	if(product_toc.className.length == 0)
		return;
		
	var params = new Object();
	params.product_id = product_id;
	
	new Ajax.Request("custom/modules/product/product_ajax.cfc?method=renderProductDetailTOC", {
		method: 'post',
		parameters : params,
		onSuccess: function(transport) {
			var obj = transport.responseText.evalJSON();
			
			var product_toc = $("product_toc_" + obj.ID);
			product_toc.className = "";
		
			if(obj.UPDATE == true)
				product_toc.innerHTML = obj.HTML;
		}
	});
}



//---------------------------------------------------------------------------------------------------------------
function updateVideoControls(title, prevId, nextId, currentId)
{
	$("video-title").innerHTML = title;
	$("video-prev-button").removeClassName("disabled");
	$("video-next-button").removeClassName("disabled");	
	
	if(prevId == "0")
		$("video-prev-button").addClassName("disabled");
	if(nextId == "0")
		$("video-next-button").addClassName("disabled");
		
	$("video-prev-button").writeAttribute("href", "videos-" + prevId + ".htm?autoPlay=1");
	$("video-next-button").writeAttribute("href", "videos-" + nextId + ".htm?autoPlay=1");
	
	if(prevId != "0")
		$("video-row-" + prevId).removeClassName("active");	
	if(nextId != "0")
		$("video-row-" + nextId).removeClassName("active");	
	if(currentId != "0")
		$("video-row-" + currentId).addClassName("active");	
}










//---------------------------------------------------------------------------------------------------------------
var product_info_window_id = "";
var product_info_timer = "";
var product_info_height = 0;
var product_info_width = 0;
var adjustment = "left";
var caller = null;

//---------------------------------------------------------------------------------------------------------------
function startStopProductInfoWindow(evt, id, adjustment, caller)
{
	this.adjustment = adjustment;
	this.caller = caller;
	product_info_window_id = id;
	product_info_timer = setTimeout(prepareInfoWindow = function() { getInfoWindowContent(id); }, 700);
}

//---------------------------------------------------------------------------------------------------------------
function getInfoWindowContent(id)
{
	if($(id) != null)
	{
		calculateProductInfoWindowDimensions();
		showProductInfoWindow(caller, adjustment);
		return;
	}
	var params = new Object();
	var idsplit = id.split("_");
	params.product_id = idsplit[idsplit.length - 1];
	
	new Ajax.Request("custom/modules/product/product_ajax.cfc?method=renderProductInfoWindow", {
		method: 'post',
		parameters : params,
		onSuccess: function(transport) {
			var obj = transport.responseText.evalJSON();
			
			$("info_window").innerHTML = obj.WINDOW_CONTENT;
			
			calculateProductInfoWindowDimensions();
			showProductInfoWindow(caller, adjustment);
		}
	});
}

//---------------------------------------------------------------------------------------------------------------
function calculateProductInfoWindowDimensions()
{
	var info_window = $(product_info_window_id);	
	info_window.style.display = "block";
	product_info_height =  info_window.offsetHeight;
	product_info_width =  info_window.offsetWidth;
	info_window.style.display = "none";
}

//---------------------------------------------------------------------------------------------------------------
function showProductInfoWindow(caller, adjustment)
{
	var arrow_left = "product-window-arrow-left";
	var arrow_right = "product-window-arrow-right";
	var info_window = $(product_info_window_id);		

	var offset_x = $(caller).viewportOffset().left + $(caller).offsetWidth + 2;
	var offset_y = $(caller).viewportOffset().top;

	if(window.opera != "undefined" & navigator.userAgent.indexOf("Opera") > -1)
	{
		offset_y -= document.documentElement.scrollTop;
	}
	
	if(isIE6)
	{
		offset_y += document.documentElement.scrollTop;
	}	

	
	if(adjustment == "top")
	{
		offset_y = offset_y + (caller.offsetHeight / 2) - 62;
	}
	else
	{
		offset_y = offset_y - product_info_height + ($(caller).offsetHeight / 2) + 62;
	}

	var info_window_arrow = $(product_info_window_id + "_arrow");
	if(info_window_arrow != null)
	{
		if(offset_x + product_info_width > getWindowWidth())
		{
			offset_x = $(caller).viewportOffset().left - product_info_width;
			info_window_arrow.className = arrow_right + " " + arrow_right + "-" + adjustment;
		}
		else
		{
			info_window_arrow.className = arrow_left + " " + arrow_left + "-" + adjustment;
		}
	}
	
	if(info_window != null)
	{
		info_window.style.left = offset_x + "px";
		info_window.style.top = offset_y + "px";
		
		info_window.style.display = "block";
		
		info_window.style.visibility = "visible";
	}
}

//---------------------------------------------------------------------------------------------------------------
function adjustProductInfoWindow(evt, id, adjustment)
{	
	var value = 0;
	var top = 0;
	var arrow_left = "product-window-arrow-left";
	
	if(document.documentElement.scrollTop != "undefined" && document.documentElement.scrollTop != 0)
	{
		value = document.documentElement.scrollTop;
	}
	else
	{
		if(document.body.scrollTop != "undefined" && document.body.scrollTop != 0)
			value = document.body.scrollTop;
	}	

	var info_window = $(id);	
	var info_window_arrow = $(id + "_arrow");
	
	var offset_x = Event.pointerX(evt) + 15;
	var offset_y = Event.pointerY(evt) - value + 39;
	
	offset_y -= product_info_height;
	
	if(adjustment == "top")
	{
		top	= product_info_height - 25;
		offset_y -= 39 * 2 + 22;
	}

	info_window_arrow.className = arrow_left + " " + arrow_left + "-" + adjustment;
	
	info_window.style.left = offset_x + "px";
	info_window.style.top = offset_y + 25 + top + "px";
}

//---------------------------------------------------------------------------------------------------------------
function hideProductInfoWindow()
{
	clearTimeout(product_info_timer);
	var info_window = $(product_info_window_id);
	if(info_window != null)
	{
		info_window.style.visibility = "hidden";
		product_info_window_id = "";
	}	
}



