var GIApp = {};
var POTHApp = {};

function $(elm) {
	return document.getElementById(elm);
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

String.prototype.trim = function() {
	return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');	
}

function getElementsByClassName(strClass, strTag, objContElm) {
	strTag = strTag || "*";
	objContElm = objContElm || document;    
	var objColl = objContElm.getElementsByTagName(strTag);
	if (!objColl.length &&  strTag == "*" &&  objContElm.all)
		objColl = objContElm.all;
	var arr = new Array();                              
	var delim = strClass.indexOf('|') != -1  ? '|' : ' ';   
	var arrClass = strClass.split(delim);    
	for (var i = 0, j = objColl.length; i < j; i++) {                         
		var arrObjClass = objColl[i].className.split(' ');   
		if (delim == ' ' && arrClass.length > arrObjClass.length) continue;
		var c = 0;
		comparisonLoop:
		for (var k = 0, l = arrObjClass.length; k < l; k++) {
			for (var m = 0, n = arrClass.length; m < n; m++) {
				if (arrClass[m] == arrObjClass[k])
					c++;
				if ((delim == '|' && c == 1) || (delim == ' ' && c == arrClass.length)) {
					arr.push(objColl[i]); 
					break comparisonLoop;
				}
			}
		}
	}
	return arr; 
}

//function to fix the IE rollover 
function fixIE6flicker(fix) {
	try {
		document.execCommand("BackgroundImageCache", false, fix);
	}
	catch(err) { }
}

fixIE6flicker(true);

var sfHover = function() {
	var sf01;

	if (document.getElementById("nav")) {
		sf01=document.getElementById("nav").getElementsByTagName("LI");
	}

	if (sf01) {
		for (var i=0; i<sf01.length; i++) {
			sf01[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sf01[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
}

addLoadEvent(function() {
	if (window.attachEvent) window.attachEvent("onload", sfHover);

	var gss = $("site_search_input");
	if (gss) {
		gss.onfocus = function() {
			if (this.value == "Search Get Involved") {
				this.value = "";
				this.style.color = "#000000";
			}
		}
		gss.onblur = function() {
			if (this.value.toString().trim() == "") {
				this.style.color = "#C8C6B7";
				this.value = "Search Get Involved";
			}
		}
	}

});

String.prototype.trim = function() {
  return this.replace(/^\s+|\s+$/g, "");
}

addLoadEvent(function() {
	var fbs = $("fbs_link");
	if (fbs) {
		fbs.onclick = fbs_click;
	}
});

function fbs_click() {
	u=location.href;
	t=document.title;
	window.open(
			'http://www.facebook.com/sharer.php?u='+encodeURIComponent(u),
			'sharer',
			'toolbar=0,status=0,width=626,height=436'
		);
	return false;
}

addLoadEvent(function() {
	if (window.reg) {
		GIApp.tvoSlide = { inProgress: false, isOpen: false };

		window.reg.hover('#tvo_nav_slide',
			function() {
				if (!GIApp.tvoSlide.inProgress && !GIApp.tvoSlide.isOpen) {
					GIApp.tvoSlide.inProgress = true;
					GIApp.tvoSlide.isOpen = true;
					$("tvo_nav_slide").className = "on"
					slide($("tvo_nav_slide"), -570, 0);		
				}
			},
			function() {
				if (!GIApp.tvoSlide.inProgress) {
					GIApp.tvoSlide.inProgress = true;
					GIApp.tvoSlide.isOpen = false;
					$("tvo_nav_slide").className = "off"
					slide($("tvo_nav_slide"), 0, -570);		
				}
			}
		);	
	}
});

function slide(el, startPos, stopPos) {
	var pos = startPos;
	var wait = 1;
	
	function f() {
		if (startPos < stopPos) {
			el.style.left = (pos +=  19) + "px";
			if (pos < stopPos)
				setTimeout(f, wait);
			else 
				GIApp.tvoSlide.inProgress = false;
		} else {
			el.style.left = (pos -= 19) + "px";
			if (pos > stopPos)
				setTimeout(f, wait);
			else 
				GIApp.tvoSlide.inProgress = false;
		}
	};
	f();
}
