window.onload = function() {
	preloadRollovers();
	domRollover($$('.domroll'));
	initMainNav($$('.tab'));
	initDropdowns($$('.dd li'));
	initTextBoxes($$('.highlight-text .text'));
	initTextBoxes($$('.form-section .text'));
}

preloadRollovers = function() {
	var numCSS = cssRollovers.length;
	var totalArgs = 0;
	
	$$('.domroll').each(function(thisel) {
		totalArgs++;
	});
	
	totalArgs += numCSS;	
	
	document.imageArray = new Array(totalArgs);	// create an image array (size = num css rollover images + num JS domroll images
	// will set the src of the images in the array to load them before the rollover occurs
	
	for (var i = 0; i < numCSS; i++) { // add the CSS rollovers to the array
		document.imageArray[i] = new Image;
		document.imageArray[i].src = cssRollovers[i];
	}
	
	var domCounter = numCSS;
	
	$$('.domroll').each(function (thisel2) { // add the JS rollovers to the array
		document.imageArray[domCounter] = new Image;
		document.imageArray[domCounter].src = thisel2.className.match(/domroll (\S+)/)[1];
		domCounter++;
	});	
}


domRollover = function(elements) {
	if (navigator.userAgent.match(/Opera (\S+)/)) {
		var operaVersion = parseInt(navigator.userAgent.match(/Opera (\S+)/)[1]);
	}
	if (!document.getElementById || operaVersion <7) return;
	
	elements.each(function(thisel) {
		thisel.off = thisel.src;
		thisel.over = thisel.className.match(/domroll (\S+)/)[1];
		
		thisel.addEvent('mouseover', function() {thisel.src = thisel.over});
		thisel.addEvent('mouseout', function() {thisel.src = thisel.off});
    }); 
}

initMainNav = function(elements) {		
	elements.each(function(thisel) {
		var whichTab = thisel.id.substring(0,thisel.id.indexOf('-'));
		
		thisel.addEvent('mouseover', function() {
			this.style.background = "url(images/general/nav_over.jpg) no-repeat center center";
			$(whichTab + '-dd').style.display = 'block';
		});
		thisel.addEvent('mouseout', function() {
			this.style.background = "none";
			$(whichTab + '-dd').style.display = 'none';
		});
	});
}

initDropdowns = function(elements) {	
	elements.each(function(thisel) {
			var parent = thisel.parentNode.parentNode;
			var whichTab = parent.id.substring(0,parent.id.indexOf('-'));
			
		thisel.addEvent('mouseover', function() {
			this.style.backgroundColor = "#0c3e9d";
			
			parent.style.display = 'block';
			$(whichTab + '-tab').style.background = "url(images/general/nav_over.jpg) no-repeat center center";
		});
		thisel.addEvent('mouseout', function() {
			this.style.backgroundColor = "#0a2d6f";
			parent.style.display = 'none';
			$(whichTab + '-tab').style.background = "none";
		});	
	});
}	

initTextBoxes = function(elements) {
	elements.each(function(thisel) {
		thisel.addEvent('focus', function() {
			this.style.backgroundColor = "#e8f2f6";
		});
		
		thisel.addEvent('blur', function() {
			this.style.backgroundColor = "#ffffff";
		});
	});
}

function clearTxtField(field, text) {
	if (field.value == text) {
		field.value = '';
	}
}

function fillTxtField(field, text) {
	if (field.value == '') {
		field.value = text;
	}
}

function clearPassField(field) {
	field.value = '';
	document.getElementById('password').innerHTML = "<input type='password' class='text' id='pass-input' onblur='fillPassField(this)' />";
	document.getElementById('pass-input').focus();
}

function fillPassField(field) {
	if (field.value == '') {
		document.getElementById('password').innerHTML = "<input type='text' class='text' value='Password' onclick='clearPassField(this)' />";
	}
}