/*-- slideshow functions --*/
function manual(whId,itemTotal){

	// stop slideshow
	clearTimeout(t);
	//hide images
	for (i=1;i<=itemTotal;i++)
	{
		var whSlide = 'slide' + i;
		var whButton = 'slideshow_more_button' + i;
		var whNav = 'nav_container' + i;
		document.getElementById(whSlide).style.display = 'none';
		document.getElementById(whButton).style.display = 'none';
		document.getElementById(whNav).style.display = 'none';
	}
	var whSlide = 'slide' + whId;
	var whButton = 'slideshow_more_button' + whId;
	var whNav = 'nav_container' + whId;
	document.getElementById(whSlide).style.display = 'block';
	document.getElementById(whButton).style.display = 'block';
	document.getElementById(whNav).style.display = 'block';
	document.getElementById(whSlide).style.opacity = 100;
	document.getElementById(whButton).style.opacity = 100;
	document.getElementById(whNav).style.opacity = 100;
    document.getElementById(whSlide).style.filter  	= "alpha(opacity=" + 100 + ")";
    document.getElementById(whButton).style.filter  = "alpha(opacity=" + 100 + ")";
    document.getElementById(whNav).style.filter  	= "alpha(opacity=" + 100 + ")";
}

imagePath = "/images/"
function rollover(whButton, whState) {
	document.images[whButton].src = imagePath + whButton + whState
} 

function SetOpacity(elem, opacityAsInt)
{
	var whSlide = 'slide' + elem;
	var whButton = 'slideshow_more_button' + elem;
	var whNav = 'nav_container' + elem;
	
    var opacityAsDecimal = opacityAsInt;
    
    if (opacityAsInt > 100)
        opacityAsInt = opacityAsDecimal = 100; 
    else if (opacityAsInt < 0)
        opacityAsInt = opacityAsDecimal = 0; 
    
    opacityAsDecimal /= 100;
    if (opacityAsInt < 1)
        opacityAsInt = 1; // IE7 bug, text smoothing cuts out if 0
    
    document.getElementById(whSlide).style.opacity 	= (opacityAsDecimal);
    document.getElementById(whSlide).style.filter  	= "alpha(opacity=" + opacityAsInt + ")";
    document.getElementById(whButton).style.opacity = (opacityAsDecimal);
    document.getElementById(whButton).style.filter  = "alpha(opacity=" + opacityAsInt + ")";
    document.getElementById(whNav).style.opacity 	= (opacityAsDecimal);
    document.getElementById(whNav).style.filter  	= "alpha(opacity=" + opacityAsInt + ")";
}

var time = 1000;
var fps = 10;

function FadeIn(itemId, itemTotal)
{
	whId = itemId
	whTotal = itemTotal
	// show item
	var whItem = 'slide' + whId;
	document.getElementById(whItem).style.display='block';
	var whButton = 'slideshow_more_button' + whId;
	document.getElementById(whButton).style.display='block';
	var whNav = 'nav_container' + whId;
	document.getElementById(whNav).style.display='block';
	// alert('in: ' + whId + ',' + whTotal);
	// setup fade variables
	var steps = Math.ceil(fps * (time / 1000));
	var delta = (100 - 0) / steps;
	
	FadeInStep(whId, whTotal, 0, steps, 0, delta, (time / steps));
}

function FadeInStep(itemId, itemTotal, stepNum, steps, fromOpacity, delta, timePerStep)
{
	whId = itemId
	whTotal = itemTotal
	whItem = 'slide' + whId
	SetOpacity(whId, Math.round(parseInt(fromOpacity) + (delta * stepNum)));
	if (stepNum < steps)
	{
		t=setTimeout("FadeInStep(" + whId + ", " + whTotal + ", " + (stepNum+1) + ", " + steps + ", " + fromOpacity + ", " + delta + ", " + timePerStep + ")", timePerStep);
	}
	else
	{
		t=setTimeout("FadeOut("+whId+","+whTotal+")", 3000)
	}
}

function FadeOut(itemId,itemTotal)
{
	whId = itemId
	whTotal = itemTotal
	// alert('out: '+whId + ',' + whTotal);
	// setup fade variables
	var steps = Math.ceil(fps * (time / 1000));
	var delta = (0 - 100) / steps;
	
	FadeOutStep(whId, whTotal, 0, steps, 100, delta, (time / steps) );
}

function FadeOutStep(itemId, itemTotal, stepNum, steps, fromOpacity, delta, timePerStep)
{
	var whId = itemId
	var whTotal = itemTotal
	var whItem = 'slide' + whId
	var whButton = 'slideshow_more_button' + whId;
	var whNav = 'nav_container' + whId;
	SetOpacity(whId, Math.round(parseInt(fromOpacity) + (delta * stepNum)));
	if (stepNum < steps)
	{
		t=setTimeout("FadeOutStep(" + whId + ", " + whTotal + ", " + (stepNum+1) + ", " + steps + ", " + fromOpacity + ", " + delta + ", " + timePerStep + ")", timePerStep);
	}
	else
	{
		// hide item to prevent links from working
		document.getElementById(whItem).style.display='none';
		document.getElementById(whButton).style.display='none';
		document.getElementById(whNav).style.display='none';
		//calculate next item
		nextId = parseInt(whId) + 1
		if (nextId > whTotal) { nextId=1 }
		// alert('next: '+nextId + ',' + whTotal);
		t=setTimeout("FadeIn("+nextId+","+whTotal+")", 1)
	}
}
/*-- end slideshow functions --*/

function activatePageMenu(submenuId)
{
	if(activePageMenu != null) deactivatePageMenu();

	var element = document.getElementById(submenuId);
	if(element == null){ return; } //If submenu has no sub-submenu
	
	if(detectBrowser() == "Microsoft Internet Explorer")
	{
		element.style.display = "block";
	}
	else
	{
		element.style.setProperty("display","block","");
	}
	
	onPage = true;
	activePageMenu = element;
}

function activateSectionMenu(submenuId)
{
	//debug("activate section: " + submenuId);	
	if(activeSectionMenu != null) deactivateSectionMenu();
	
	var element = document.getElementById(submenuId);
	if(element == null){ return; } //If menu has no submenu
	
	if(detectBrowser() == "Microsoft Internet Explorer")
	{
		element.style.display = "block";
	}
	else
	{
		element.style.setProperty("display","block","");
	}
	
	onSection = true;
	activeSectionMenu = element;
}
	
/* adds a function to the onload event handler */
function addLoadEvent(func)
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function')
	{
		window.onload = func;
	}
	else
	{
		window.onload = function()
		{
			oldonload();
			func();
		}
	}
}

function adjustColumn()
{
	var column1 = document.getElementById("column1");
	var column2 = document.getElementById("column2");
	var column3 = document.getElementById("column3");
	if(column1.scrollHeight >= column2.scrollHeight)
	{
		whHeight = column1.scrollHeight
	}
	else
	{
		whHeight = column2.scrollHeight
	};
	if(column3.scrollHeight >= whHeight)
	{
		whHeight = column3.scrollHeight
	}
	

	if(detectBrowser() == "Microsoft Internet Explorer")
	{
		column1.style.height = whHeight+"px";
		column2.style.height = whHeight+"px";
		column3.style.height = whHeight+"px";
	}
	else
	{
		column1.style.setProperty("height",whHeight+"px","");
		column2.style.setProperty("height",whHeight+"px","");
		column3.style.setProperty("height",whHeight+"px","");
	}
}
	
function adjustWrapperMain()
{
	var wrapper = document.getElementById("wrapper");
	var availHeight = wrapper.scrollHeight;
	
	//var content = document.getElementById("contentArea");
	//var contentHeight = content.scrollHeight;
	if(detectBrowser() == "Microsoft Internet Explorer")
	{
		wrapper.style.height = availHeight+20+"px";
		//content.style.height = contentHeight+20+"px";
	}
	else
	{
		wrapper.style.setProperty("height",availHeight+20+"px","");
		//content.style.setProperty("height",contentHeight+20+"px","");
	}
}

function adminOpen(whPage,whID) {
	var url = '/connect5' + whPage + '?mode=edit&id=' + whID
	adminWindow = window.open(url,'connect5','');
	adminWindow.focus();
}

function changeClass(element,class_name)
{
	
	//Accept objects and id's of objects
	if(typeof(element) != "object")
		element = document.getElementById(element);
	
	element.className = class_name;
}

function deactivatePageMenu()
{
	if(detectBrowser() == "Microsoft Internet Explorer")
	{
		if(activePageMenu != null){activePageMenu.style.display = "none";}
	}
	else
	{
		if(activePageMenu != null){activePageMenu.style.setProperty("display","none","");}
	}
}

function deactivateSectionMenu()
{

	if(detectBrowser() == "Microsoft Internet Explorer")
	{
		if(activeSectionMenu != null) activeSectionMenu.style.display = "none";
	}
	else
	{
		if(activeSectionMenu != null) activeSectionMenu.style.setProperty("display","none","");
	}
}

/*	Detects the browser */
function detectBrowser()
{
	var browser = navigator.appName;
	return browser;
}

function doMarginBottom(marginBottom)
{
	var wrapper = document.getElementById("wrapper");
	
	if(detectBrowser() == "Microsoft Internet Explorer")
	{
		wrapper.style.marginBottom = marginBottom+"px";
	}
	else
	{
		wrapper.style.setProperty("margin-bottom",marginBottom+"px","");
	}
}

function fixHeight()
{
	var wrapper = document.getElementById("wrapper");
	var container = document.getElementById("container");
	var h = container.scrollHeight;
	
	if(detectBrowser() == "Microsoft Internet Explorer")
	{
		wrapper.style.height = h+"px";
	}
	else
	{
		wrapper.style.setProperty("height",h+"px","");
	}
}

/* hides a visibility layer onmouseEvent */
function hideDetail(whItem)
{
	document.getElementById(whItem).style.visibility="hidden";
}

function leftSection()
{
	onSection = false;
}

function leftPage()
{
	onPage = false;
}

/* --- Menu Cleaner ---*/
var activeSectionMenu = null;
var activePageMenu = null;
var onSection = false;
var onPage = false;

setInterval("menuCleaner()",500);

function menuCleaner()
{
	if(onSection == false) deactivateSectionMenu();
	if(onPage == false) deactivatePageMenu();
}
	
function overPage()
{
	onPage = true;
}

function overSection()
{
	onSection = true;
}

/* redirect script used with main nav panels */
function redirect(whPage,whTable,whValue) {
	document.location.href=whPage+"?"+whTable+"="+whValue;
}

/* shows message about session expiring */
function sessionWarning() {
	window.open('session_warning.cfm','warning','width=300,height=300');
}

/* shows a visibility layer onclick */
function showDetail(whItem)
{
	document.getElementById(whItem).style.visibility="visible";
}

/* hides/shows a specific dig onChange */
function toggleDiv(whDiv,whValue)
{
	if (whValue == 1)
	{
		document.getElementById(whDiv).style.display = 'none';
	}
	else
	{
		document.getElementById(whDiv).style.display = 'block';
	}
}

