var currentContentTab;
var tabContentTimer;
var GlobalNavCurrentTab = 'x';
var GlobalNavTabTimer;


$(document).ready(function(){
	/*
	$("#flashBtnLi").bind("mouseenter", function() {
		setCurrentTab(0);
		if ($("#flashBtnLiDesc").is(":hidden")) { 
			$("#flashBtnLiDesc").slideDown("fast");
		}
	}).bind("mouseleave", function() { leaveTab() });
	
	$("#ecoSystemBtnLi").bind("mouseenter", function() {
		setCurrentTab(1);
		if ($("#ecoSystemBtnLiDesc").is(":hidden")) { 
			$("#ecoSystemBtnLiDesc").slideDown("fast");
		}
	}).bind("mouseleave", function() { leaveTab() });
	
	$("#productsBtnLi").bind("mouseenter", function() {
		setCurrentTab(2);
		if ($("#productsBtnLiDesc").is(":hidden")) { 
			$("#productsBtnLiDesc").slideDown("fast");
		}
	}).bind("mouseleave", function() { leaveTab() });
	
	$("#servicesBtnLi").bind("mouseenter", function() {
		setCurrentTab(3);
		if ($("#servicesBtnLiDesc").is(":hidden")) { 
			$("#servicesBtnLiDesc").slideDown("fast");
		}
	}).bind("mouseleave", function() { leaveTab() });
	
	$("#clientsBtnLi").bind("mouseenter", function() {
		setCurrentTab(4);
		if ($("#clientsBtnLiDesc").is(":hidden")) { 
			$("#clientsBtnLiDesc").slideDown("fast");
		}
	}).bind("mouseleave", function() { leaveTab() });
	
	$("#newsBtnLi").bind("mouseenter", function() {
		setCurrentTab(5);
		if ($("#newsBtnLiDesc").is(":hidden")) { 
			$("#newsBtnLiDesc").slideDown("fast");
		}
	}).bind("mouseleave", function() { leaveTab() });
	
	$("#interestBtnLi").bind("mouseenter", function() {
		setCurrentTab(6);
		if ($("#interestBtnLiDesc").is(":hidden")) { 
			$("#interestBtnLiDesc").slideDown("fast");
		}
	}).bind("mouseleave", function() { leaveTab() });
	
	
	$("div.desc").bind("mouseleave", function() {
		tabContentTimer = setTimeout('clearTabs()', 2000);
	});
	*/
	$("a#single_image").fancybox(); 
	
	$("div.topNavFlyOuts").bind('mouseenter', function(){
		GlobalNavFlyoutEnter(this.id);
	}).bind('mouseleave', function() { GlobalNavFlyoutLeave(this.id); });
});
function GlobalNavFlyoutEnter(input){
	var parent = GlobalNavParseID(input); 	//zz1_GlobalNavn0
	var link = document.getElementById(parent).getElementsByTagName('table')[0];
	if (link == GlobalNavCurrentTab){
		// re roll same tab
		clearInterval(GlobalNavTabTimer);
	} else {
		if (GlobalNavCurrentTab != 'x'){
			// new tab with old tab open
			clearInterval(GlobalNavTabTimer);
			GlobalNavClearTab(GlobalNavCurrentTab);
		}
		link.className += " topNavHover";
		GlobalNavCurrentTab = input;
	}

}
function GlobalNavFlyoutLeave(input){
	var parent = GlobalNavParseID(input);
	var link = document.getElementById(parent).getElementsByTagName('table')[0];
	GlobalNavTabTimer = setTimeout("GlobalNavClearTab('"+input+"')", 500);
}

function GlobalNavClearTab(input){
	var parent = GlobalNavParseID(input);
	var link = document.getElementById(parent).getElementsByTagName('table')[0];
	link.className = link.className.replace(/ topNavHover/, '');
	GlobalNavCurrentTab = 'x';
}

function GlobalNavParseID(val){
	return val.replace(/Items/, '');
}
function leaveTab(){
	//tabContentTimer = setTimeout('clearTabs()', 2000);
}
function descClose(){
	// close a menu drop down description div
	//clearTabs();
	var list = document.getElementById('topNav').getElementsByTagName('ul')[0];
	var listItems = list.childNodes;
	var curEl;
	var corispondingMenuContent;
	var a;
	var divs;
	for ( var i = 0; i < listItems.length; i++) {
		if (listItems[i].nodeName =="LI") {
			divs = listItems[i].childNodes;
			for ( var x = 0; x < divs.length; x++) {
				if (divs[x].nodeName == 'DIV' && divs[x].className == 'desc'){
					divs[x].style.display = 'none';
					//divs[x].style = ;
					//divs[x].removeAttribute('style');
					//setTimeout(divs[x].removeAttribute('style'), 200);
				}
			}
			
		}
	}
	
	
}

function toggleLoginForm(){
	var loginForm = document.getElementById("loginForm");
	if(loginForm.style.display == "block"){
		$("#loginForm").slideUp("fast");
	} else {
		$("#loginForm").slideDown("fast");
	}
}

/*
function setCurrentTab(index) {
	clearInterval(tabContentTimer);
	if (currentContentTab == index) return;
	clearTabs();
	//resetContent();
	//setCurrentContent(index);
	var list = document.getElementById('topNav').getElementsByTagName('ul')[0];
	var listItems = list.childNodes;
	var a;
	var counter = -1;
	for (i = 0; i < listItems.length; i++) {
		if (listItems[i].nodeName =="LI") {
			counter++
		}
		if (counter == index) {
			listItems[i].className = 'navLiSelected';
			a = listItems[i].childNodes[0];
			a.className = 'navASelected';
			currentContentTab = index;
			return;
		}
	}
	
}

function clearTabs() {
	var list = document.getElementById('topNav').getElementsByTagName('ul')[0];
	var listItems = list.childNodes;
	var curEl;
	var corispondingMenuContent;
	var a;
	for ( var i = 0; i < listItems.length; i++) {
		if (listItems[i].nodeName =="LI") {
			curEl = listItems[i];
			curEl.className = '';
			a = curEl.getElementsByTagName('a')[0];
			a.className = '';
			corispondingMenuContent = "#" + curEl.id + 'Desc';
			$(corispondingMenuContent).slideUp("fast");
		}
	}
	currentContentTab = 'x';
}

function setCurrentContent(index) {
	resetContent();
	var contentEl = document.getElementById('content_' + index);
	contentEl.style.display = "block";
}

function resetContent() {
	var contentEls = document.getElementById('content').getElementsByTagName('div');
	for ( var i = 0; i < contentEls.length; i++) {
		contentEls[i].style.display = 'none';
	}
}
*/
function addIconicButtonFunctionality() {
	var list = Array('iconicButton_stratEnroll', 'iconicButton_soa');
	var el;
	for ( var i = 0; i < list.length; i++) {
		el = document.getElementById(list[i]);
		if (el){
			el.onmouseover = IconicButtonOver;
			el.onmouseout = IconicButtonOut;
			el.onclick = IconicButtonClick;
		}
	}
}

function IconicButtonOver() {
	this.style.cursor = 'pointer';
	var name = this.id;
	this.className =  'iconicButton ' + name +'_hover';
}
function IconicButtonOut(){
	this.className =  'iconicButton';
}
function IconicButtonClick(){
	/* expects an anchor in the h3 */
	var a = this.getElementsByTagName("h3")[0].getElementsByTagName('a')[0];
	location = a.href;
}

function openContactWindow(){
	var pop = document.getElementById('contactWindow');
	if (pop.style.display == 'block'){
		//pop.style.display = 'none';
		$('#contactWindow').fadeOut("fast");
	}else{	
		//pop.style.display = 'block';
		var x = ($(document).width()/2) - ($(pop).width()/2);
		var yoffset = (window.pageYOffset) ? window.pageYOffset : document.documentElement.scrollTop;
		var z = ( typeof( window.innerWidth ) == 'number' ) ? window.innerHeight : document.documentElement.clientHeight;
		//alert('off: ' + yoffset + ' z: ' + z); 
		y = (z/2) - ($(pop).height()/2) + yoffset;
		if (y < yoffset) y = yoffset;
		pop.style.left = x+"px";
		pop.style.top = y+"px";
		$('#contactWindow').fadeIn("fast");		
	}
}

function resizeTabbedFlashContent(id, height){
	var target = '#'+id;
	$(target).height(height);
	$('#another').height(200);
}

function D2RequestDemoConversion() {
	ifrm = document.createElement("IFRAME");
	var url = "/swf/InlineConversion.html?" + Math.random();
	//alert("conversion " +url);
	
	ifrm.setAttribute("src", url);
	ifrm.setAttribute('id', 'hiddenIframe');
	ifrm.style.width = 0+"px";
	ifrm.style.height = 0+"px";
	document.body.appendChild(ifrm);
	return "";
}
