sfEnabled = true;
var sfClearHoverDelay = 2000;

if (!((document.all)&&(navigator.appVersion.indexOf("MSIE 6.")!=-1))) {
	sfClearHoverDelay = 20;
}

function register_onload(generic) {
	//setup onload function
	if(typeof window.addEventListener != 'undefined')
		{
			//.. gecko, safari, konqueror and standard
			//window.addEventListener('load', generic, false);
		}
		else 
		if(typeof document.addEventListener != 'undefined')
		{
			//.. opera 7
			//document.addEventListener('load', generic, false);
		}
		else if(typeof window.attachEvent != 'undefined')
	{
		//.. win/ie
		window.attachEvent('onload', generic);
	}
	
	//** remove this condition to degrade older browsers
	else
	{
		//.. mac/ie5 and anything else that gets this far
		
		//if there's an existing onload function
		if(typeof window.onload == 'function')
		{
			//store it
			var existing = onload;
			
			//add new onload handler
			window.onload = function()
			{
				//call existing onload function
				existing();
				
				//call generic onload function
				generic();
			};
		}
		else
		{
			//setup onload function
			window.onload = generic;
		}
	}
}

var sfEls = null;

function initSuckerfish(type, tag, parentId) {
	if (sfEnabled) {
		sfEls = (parentId==null)?document.getElementsByTagName(tag):document.getElementById(parentId).getElementsByTagName(tag);
		type(sfEls);
	}
}

function suckerfish(type, tag, parentId) {
	register_onload(
		function() {
			var sfEls = (parentId==null)?document.getElementsByTagName(tag):document.getElementById(parentId).getElementsByTagName(tag);
			type(sfEls);
		});
}

var sfClearHoversCB = null;

function sfClearHovers() {
// alert('sfClearHovers');
	for (var i=0; i<sfEls.length; i++) {
		sfHoverOut(sfEls[i]);
	}
}

function sfResetClearHovers() {
	if (sfClearHoversCB) clearTimeout(sfClearHoversCB);
	sfClearHoversCB = setTimeout('sfClearHovers()', sfClearHoverDelay);
}	
	

var sfHoverRegExp = new RegExp(" sfhover\\b");

sfHover = function(sfEls) {
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			sfHoverOver(this);
		}
		sfEls[i].onmouseout=function() {
			sfHoverOut(this);
		}
	}
}


sfHoverOver = function(sfEl) {
	sfResetClearHovers();

	sfEl.className+=" sfhover";
	if (hideFormsEnabled) hideForms();
}

sfHoverOut = function(sfEl) {
	sfEl.className=sfEl.className.replace(sfHoverRegExp, "");
	if (hideFormsEnabled) showForms();

	sfResetClearHovers();

}

sfHoverOverForm = function(sfEls) {
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].innerHTML = ('<iframe src="about:blank" scrolling="no" frameborder="0"></iframe>' + sfEls[i].innerHTML);
		var ieMat = sfEls[i].firstChild;
		ieMat.style.width=sfEls[i].offsetWidth+"px";
		ieMat.style.height=sfEls[i].offsetHeight+"px";	
		sfEls[i].style.zIndex="99";
	}
}

sfFocus = function(sfEls) {
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onfocus=function() {
			this.className+=" sffocus";
		}
		sfEls[i].onblur=function() {
			this.className=this.className.replace(new RegExp(" sffocus\\b"), "");
		}
	}
}

sfActive = function(sfEls) {
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmousedown=function() {
			this.className+=" sfactive";
		}
		sfEls[i].onmouseup=function() {
			this.className=this.className.replace(new RegExp(" sfactive\\b"), "");
		}
	}
}

sfTarget = function(sfEls) {
	var aEls = document.getElementsByTagName("A");
	document.lastTarget = null;
	for (var i=0; i<sfEls.length; i++) {
		if (sfEls[i].id) {
			if (location.hash==("#" + sfEls[i].id)) {
				sfEls[i].className+=" sftarget";
				document.lastTarget=sfEls[i];
			}
			for (var j=0; j<aEls.length; j++) {
				if (aEls[j].hash==("#" + sfEls[i].id)) aEls[j].targetEl = sfEls[i];
				aEls[j].onclick = function() {
					if (document.lastTarget) document.lastTarget.className = document.lastTarget.className.replace(new RegExp(" sftarget\\b"), "");
					if (this.targetEl) this.targetEl.className+=" sftarget";
					document.lastTarget=this.targetEl;
					return true;
				}
			}
		}
	}
}

function hasFormDHTMLBug() {
	ret = false;
	
	// all versions of IE less than 7 have Form DHTML Bug
	if (navigator.appVersion.indexOf("MSIE")!=-1){
		temp=navigator.appVersion.split("MSIE");
		version=parseFloat(temp[1]);
		
		ret = (version<8);
	}
	
	return ret;
}

var formEls = null;
var hideFormsEnabled = false;

function initFormElList() {
	formEls = new Array();

	if (hasFormDHTMLBug()) {
		formEls = appendNodeListToArray(formEls, document.getElementsByTagName('input'));
		formEls = appendNodeListToArray(formEls, document.getElementsByTagName('select'));
		formEls = appendNodeListToArray(formEls, document.getElementsByTagName('textarea'));
		
		hideFormsEnabled = true;
	}

	
}

function appendNodeListToArray(nodeArray, nodeList) {
	nodeListLength = nodeList.length;
	for (i=0; i<nodeListLength; i++) {
		nodeArray[nodeArray.length] = nodeList[i];
	}
	
	return nodeArray;
}


function hideForms() {
	formElsLength = formEls.length;
	for (i=0; i<formElsLength; i++) {
		formEls[i].style.visibility='hidden';
	}
}

function showForms() {
	formElsLength = formEls.length;
	for (i=0; i<formElsLength; i++) {
		formEls[i].style.visibility='visible';
	}
}
