// DOM ROLLOVER SCRIPT
// http://www.onlinetools.org/articles/unobtrusivejavascript/chapter2.html
//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\//

function initRollovers() {

	// declare variables
	var imgs;
	var i;
	
	// loop through all images, check if they contain the class roll
	imgs=document.getElementsByTagName('img');
	for(i=0; i<imgs.length;i++) {
		if(/roll/.test(imgs[i].className)) {
			// add the function roll to the parent Element of the image
			imgs[i].parentNode.onmouseover=function(){roll(this);};
			imgs[i].parentNode.onmouseout=function(){roll(this);};
			imgs[i].parentNode.onfocus=function(){roll(this);};
			imgs[i].parentNode.onblur=function(){roll(this);};}
		}
	}
	
	function roll(o) {
	
		// declare variables
		var i;
		var isnode;
		var src;
		var ftype;
		var newsrc;
		var nownode;

		// loop through all childNodes
		for (i=0;i<o.childNodes.length;i++) {
  			nownode=o.childNodes[i];
			// if the node is an element and an IMG set the variable and exit the loop
			if(nownode.nodeType==1 && /img/i.test(nownode.nodeName)) {
   				isnode=i;
   				break;
  			}
 		}
		// check src and do the rollover
 		src = o.childNodes[isnode].src;
 		ftype = src.substring(src.lastIndexOf('.'), src.length);
 		if(/-over/.test(src)) {
  			newsrc = src.replace('-over','');
 		}else{
  			newsrc = src.replace(ftype, '-over'+ftype);
 		}
 	o.childNodes[isnode].src=newsrc;
}





// DOM IMAGE REPLACEMENT
// http://www.quirksmode.org/dom/fir.html
//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\//

function initImageHeaders() {
	var W3CDOM = (document.createElement && document.getElementsByTagName);
	if (W3CDOM) {
		replaceThem(document.getElementsByTagName('h1'));
	}
}

function replaceThem(x) {
	var replace = document.createElement('img');
	for (var i=0;i<x.length;i++) {
		if (x[i].id) {
			var y = replace.cloneNode(true);
			y.src = '../images/' + x[i].id + '.gif';
			y.alt = x[i].firstChild.nodeValue;
			x[i].replaceChild(y,x[i].firstChild);
		}
	}
}





// TABLE RULER
// http://www.alistapart.com/articles/tableruler/
//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\//

	function initTableRuler() {
   var tables=document.getElementsByTagName('table');
   for (var i=0;i<tables.length;i++) {
		trClasss = tables[i].className.split(' ');
			for (x = 0, trClasss; trClass = trClasss[x]; x++) {
				if(trClass=='ruler') {
		     		var trs=tables[i].getElementsByTagName('tr');
     				for(var j=0;j<trs.length;j++) {
      					if(trs[j].parentNode.nodeName=='TBODY' && trs[j].parentNode.nodeName!='TFOOT') {
       						trs[j].onmouseover=function(){this.className='ruled';return false}
       						trs[j].onmouseout=function(){this.className='';return false}
			}
     }
    }
   }
  }
}





// OO DROPDOWNS
//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\//

function initDropdowns() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("nav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}





// SUCKERFISH :FOCUS EMULATION FOR IE
//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\//

function initFormFocus() {

	// declare variables
	var inputs;
	var selects;
	var textareas;
	var i;
	
	// loop through all inputs, check if they contain the class formField
	inputs = document.getElementsByTagName("input");
	for (i=0; i<inputs.length; i++) {
		if(/formField/.test(inputs[i].className)) {
			// change class to formFieldFocus
			inputs[i].onfocus=function() {
				this.className=this.className.replace("formField", "formFieldFocus");
			}
			// else change class back to formField
			inputs[i].onblur=function() {
				this.className=this.className.replace("formFieldFocus", "formField");
			}
		}
	}
	
	// loop through all selects, check if they contain the class formField
	selects = document.getElementsByTagName("select");
	for (i=0; i<selects.length; i++) {
		// change class to formFieldFocus
		selects[i].onfocus=function() {
			this.className=this.className.replace("formField", "formFieldFocus");
		}
		// else change class back to formField
		selects[i].onblur=function() {
			this.className=this.className.replace("formFieldFocus", "formField");
		}
	}
	
	// loop through all textareas, check if they contain the class formField
	textareas = document.getElementsByTagName("textarea");
	for (i=0; i<textareas.length; i++) {
		// change class to formFieldFocus
		textareas[i].onfocus=function() {
			this.className=this.className.replace("formField", "formFieldFocus");
		}
		// else change class back to formField
		textareas[i].onblur=function() {
			this.className=this.className.replace("formFieldFocus", "formField");
		}
	}

}





// UNOBTRUSIVE SIZED POPUPS
// http://www.multiblah.com
//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\//

// declare variables
var aLinks;
var i;
var url;

function initPopups() {
	if (!document.getElementById) return
	aLinks = document.getElementsByTagName('a');
	for (i = 0; i < aLinks.length; i++) {
		// use multiple classes here for windows with different properties
		if (aLinks[i].className == 'popup') {
			aLinks[i].onclick = function() {
				url = this.href;
				// call different functions here for windows with different properties
				openPopup(url);
				return false;
			}	
		}
	}
}

// popupWindow functions
function openPopup(url) {
	window.open(url, 'popupwindow', 'width=375,height=350,scrollbars=no,status');
	return false;
}
function openMov(url) {
	window.open(url, 'popupwindow', 'width=450,height=400,scrollbars=no,status');
//	return false;
}
function openRM(url) {
	window.open(url, 'popupwindow', 'width=640,height=600,scrollbars=no,status,resizable=yes');
	return false;
}





// UNOBTRUSIVE NEW WINDOWS
// Found on http://www.simplebits.com/notebook/2004/05/06/sq.html - Comment #1 by Bacman (http://www.bacman.net/)
//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\//
function externalLinks() {
  if (!document.getElementsByTagName) return;
  var anchors = document.getElementsByTagName("a");
  for (var i=0; i<anchors.length; i++) {
    var anchor = anchors[i];
    if (anchor.getAttribute("href") &&
      anchor.getAttribute("rel") == "external")
      anchor.target = "_blank";
    }
}




