/*-- 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 = 2500;
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 --*/


/*-- project slideshow functions --*/
function pmanual(whId,itemTotal){

	// stop slideshow
	clearTimeout(t);
	//hide images
	for (i=1;i<=itemTotal;i++)
	{
		var whSlide = 'pslide' + i;
		var whButton = 'pslideshow_more_button' + i;
		var whNav = 'pnav_container' + i;
		document.getElementById(whSlide).style.display = 'none';
		document.getElementById(whButton).style.display = 'none';
		document.getElementById(whNav).style.display = 'none';
	}
	var whSlide = 'pslide' + whId;
	var whButton = 'pslideshow_more_button' + whId;
	var whNav = 'pnav_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 + ")";
}

function pSetOpacity(elem, opacityAsInt)
{
	var whSlide = 'pslide' + elem;
	var whButton = 'pslideshow_more_button' + elem;
	var whNav = 'pnav_container' + elem;
	
    var opacityAsDecimal = opacityAsInt;
    
    if (opacityAsInt == 100) {
		document.getElementById(whSlide).style.display 	=  'block';
		document.getElementById(whButton).style.display =  'block';
		document.getElementById(whNav).style.display 	=  'block';
	}
    else if (opacityAsInt == 0) {
		document.getElementById(whSlide).style.display 	=  'none';
		document.getElementById(whButton).style.display =  'none';
		document.getElementById(whNav).style.display 	=  'none';
	}
    
}

var ptime = 1000;
var pfps = 1;

function pslideshow(itemId, itemTotal)
{
	whId = itemId
	whTotal = itemTotal
	// alert('in: ' + whId + ',' + whTotal);
	// setup fade variables
	pshow(whId, whTotal);
}

function pFadeIn(itemId, itemTotal)
{
	whId = itemId
	whTotal = itemTotal
	// show item
	var whItem = 'pslide' + whId;
	document.getElementById(whItem).style.display='block';
	var whButton = 'pslideshow_more_button' + whId;
	document.getElementById(whButton).style.display='block';
	var whNav = 'pnav_container' + whId;
	document.getElementById(whNav).style.display='block';
	// alert('in: ' + whId + ',' + whTotal);
	// setup fade variables
	var steps = Math.ceil(pfps * (ptime / 1000));
	var delta = (100 - 0) / steps;
	
	pFadeInStep(whId, whTotal, 0, steps, 0, delta, 1);
}

function pshow(elem, itemTotal)
{
	var whSlide = 'pslide' + elem;
	var whButton = 'pslideshow_more_button' + elem;
	var whNav = 'pnav_container' + elem;
	document.getElementById(whSlide).style.display 	=  'block';
	document.getElementById(whButton).style.display =  'block';
	document.getElementById(whNav).style.display 	=  'block';
	t=setTimeout("phide(" + elem + ", " + whTotal + ")", 7000);
}

function phide(elem, itemTotal)
{
	var whSlide = 'pslide' + elem;
	var whButton = 'pslideshow_more_button' + elem;
	var whNav = 'pnav_container' + elem;
	document.getElementById(whSlide).style.display 	=  'none';
	document.getElementById(whButton).style.display =  'none';
	document.getElementById(whNav).style.display 	=  'none';
	elem = elem + 1
	if (elem == whTotal) {
		elem = 1;	
	}
	pslideshow(elem, whTotal);
}

function pFadeInStep(itemId, itemTotal, stepNum, steps, fromOpacity, delta, timePerStep)
{
	whId = itemId
	whTotal = itemTotal
	whItem = 'pslide' + whId
	pSetOpacity(whId, Math.round(parseInt(fromOpacity) + (delta * stepNum)));
	if (stepNum < steps)
	{
		t=setTimeout("pFadeInStep(" + whId + ", " + whTotal + ", " + (stepNum+1) + ", " + steps + ", " + fromOpacity + ", " + delta + ", " + timePerStep + ")", timePerStep);
	}
	else
	{
		t=setTimeout("pFadeOut("+whId+","+whTotal+")", 7000)
	}
}

function pFadeOut(itemId,itemTotal)
{
	whId = itemId
	whTotal = itemTotal
	// alert('out: '+whId + ',' + whTotal);
	// setup fade variables
	var steps = Math.ceil(pfps * (ptime / 1000));
	var delta = (0 - 100) / steps;
	
	pFadeOutStep(whId, whTotal, 0, steps, 100, delta, (ptime / steps) );
}

function pFadeOutStep(itemId, itemTotal, stepNum, steps, fromOpacity, delta, timePerStep)
{
	var whId = itemId
	var whTotal = itemTotal
	var whItem = 'pslide' + whId
	var whButton = 'pslideshow_more_button' + whId;
	var whNav = 'pnav_container' + whId;
	pSetOpacity(whId, Math.round(parseInt(fromOpacity) + (delta * stepNum)));
	if (stepNum < steps)
	{
		t=setTimeout("pFadeOutStep(" + 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("pFadeIn("+nextId+","+whTotal+")", 1)
	}
}
/*-- end project slideshow functions --*/


/*-- about slideshow functions --*/
function about_manual(whId,itemTotal){

	// stop slideshow
	clearTimeout(t);
	//hide images
	for (i=1;i<=itemTotal;i++)
	{
		var whSlide = 'about_slide' + i;
		document.getElementById(whSlide).style.display = 'none';
	}
	var whSlide = 'about_slide' + whId;
	document.getElementById(whSlide).style.display = 'block';
	document.getElementById(whSlide).style.opacity = 100;
    document.getElementById(whSlide).style.filter  	= "alpha(opacity=" + 100 + ")";
}

function aboutSetOpacity(elem, opacityAsInt)
{
	var whSlide = 'about_slide' + elem;
	
    var opacityAsDecimal = opacityAsInt;
    
    if (opacityAsInt == 100) {
		document.getElementById(whSlide).style.display 	=  'block';
	}
    else if (opacityAsInt == 0) {
		document.getElementById(whSlide).style.display 	=  'none';
	}
    
}

var about_time = 1000;
var about_fps = 1;

function about_slideshow(itemId, itemTotal)
{
	whId = itemId
	whTotal = itemTotal
	// alert('in: ' + whId + ',' + whTotal);
	// setup fade variables
	about_show(whId, whTotal);
}

function aboutFadeIn(itemId, itemTotal)
{
	whId = itemId
	whTotal = itemTotal
	// show item
	var whItem = 'about_slide' + whId;
	document.getElementById(whItem).style.display='block';
	// alert('in: ' + whId + ',' + whTotal);
	// setup fade variables
	var steps = Math.ceil(about_fps * (about_time / 1000));
	var delta = (100 - 0) / steps;
	
	aboutFadeInStep(whId, whTotal, 0, steps, 0, delta, 1);
}

function about_show(elem, itemTotal)
{
	var whSlide = 'about_slide' + elem;
	document.getElementById(whSlide).style.display 	=  'block';
	t=setTimeout("about_hide(" + elem + ", " + whTotal + ")", 3000);
}

function about_hide(elem, itemTotal)
{
	var whSlide = 'about_slide' + elem;
	document.getElementById(whSlide).style.display 	=  'none';
	elem = elem + 1
	if (elem == itemTotal) {
		elem = 1;	
	}
	about_slideshow(elem, itemTotal);
}

function aboutFadeInStep(itemId, itemTotal, stepNum, steps, fromOpacity, delta, timePerStep)
{
	whId = itemId
	whTotal = itemTotal
	whItem = 'pslide' + whId
	aboutSetOpacity(whId, Math.round(parseInt(fromOpacity) + (delta * stepNum)));
	if (stepNum < steps)
	{
		t=setTimeout("aboutFadeInStep(" + whId + ", " + whTotal + ", " + (stepNum+1) + ", " + steps + ", " + fromOpacity + ", " + delta + ", " + timePerStep + ")", timePerStep);
	}
	else
	{
		t=setTimeout("aboutFadeOut("+whId+","+whTotal+")", 3000)
	}
}

function aboutFadeOut(itemId,itemTotal)
{
	whId = itemId
	whTotal = itemTotal
	// alert('out: '+whId + ',' + whTotal);
	// setup fade variables
	var steps = Math.ceil(about_fps * (about_time / 1000));
	var delta = (0 - 100) / steps;
	
	aboutFadeOutStep(whId, whTotal, 0, steps, 100, delta, (about_time / steps) );
}

function aboutFadeOutStep(itemId, itemTotal, stepNum, steps, fromOpacity, delta, timePerStep)
{
	var whId = itemId
	var whTotal = itemTotal
	var whItem = 'about_slide' + whId
	aboutSetOpacity(whId, Math.round(parseInt(fromOpacity) + (delta * stepNum)));
	if (stepNum < steps)
	{
		t=setTimeout("aboutFadeOutStep(" + whId + ", " + whTotal + ", " + (stepNum+1) + ", " + steps + ", " + fromOpacity + ", " + delta + ", " + timePerStep + ")", timePerStep);
	}
	else
	{
		// hide item to prevent links from working
		document.getElementById(whItem).style.display='none';
		//calculate next item
		nextId = parseInt(whId) + 1
		if (nextId > whTotal) { nextId=1 }
		// alert('next: '+nextId + ',' + whTotal);
		t=setTimeout("aboutFadeIn("+nextId+","+whTotal+")", 1)
	}
}
/*-- end about 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)
{
	//alert(detectVersion());
	//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")
	{
		var IE7 = (navigator.appVersion.indexOf("MSIE 7.")==-1) ? false : true;
		if(!IE7)
		{
			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;
}

/*	Detects the version */
function detectVersion()
{
	var version = navigator.appVersion;
	return version;
}

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';
	}
}

