window.addEvent('domready', function() {
	$$('#navMenu li').each( function(ele) {
		if(ele.getElements('ul').length>0) {
			ele.getElement('ul').fade('hide');
			ele.getElement('ul').setStyle('display', 'block');
			ele.addEvent('mouseenter', function() {
				ele.getElement('ul').fade('in');
			});
			ele.addEvent('mouseleave', function() {
				ele.getElement('ul').fade('out');
			});
		}
	});

	if($('loginEmailAddress')) {
		if($('loginEmailAddress').value=="") {
			$('loginEmailAddress').value = "E-mail Address:";
			$('loginEmailAddress').addClass("overText");
			$('loginEmailAddress').addEvent("focus", function() {
				$('loginEmailAddress').removeClass("overText");
				if($('loginEmailAddress').value == "E-mail Address:")
					$('loginEmailAddress').value = "";
			});
		}
		if($('loginPassword').value=="") {
			// If loginPassword has no value, we clone it and create a text field with "Password:" inside it. We then replace
			// the password field with this new one.
			// When it gains focus, we switch out the text field to a password field.
			var newInput = new Element("input", {"type":"text","value":"Password:","class":"overText required","name":"loginPassword","maxlength":"100"});
			newInput.addEvent("focus", function() {
				var newInput2 = new Element("input", {"type":"password","class":"required","name":"loginPassword","maxlength":"100"});
				$('loginPassword').blur();
				$('loginPassword').parentNode.replaceChild(newInput2,$('loginPassword'));
				newInput2.set("id","loginPassword");
				setTimeout('$(\'loginPassword\').focus()',100);	// If I don't set a timeout, than it won't have anything to focus on.
			});
			$('loginPassword').parentNode.replaceChild(newInput,$('loginPassword'));
			newInput.set("id","loginPassword");
		}
	}
	if($('mlEmailAddress')) {
		if($('mlEmailAddress').value=="") {
			$('mlEmailAddress').value = "E-mail Address:";
			$('mlEmailAddress').addClass("overText");
			$('mlEmailAddress').addEvent("focus", function() {
				$('mlEmailAddress').removeClass("overText");
				if($('mlEmailAddress').value == "E-mail Address:")
					$('mlEmailAddress').value = "";
			});
		}
	}
	if($('membersForm')) {
		$('membersForm').addEvent("submit", function(e) {
			if($('loginEmailAddress').value=="" || $('loginEmailAddress').value=="E-mail Address:") {
				alert("Please supply your e-mail address.");
				e.stop();
				$('loginEmailAddress').focus();
				return false;
			}
			if($('loginPassword').value=="" || $('loginPassword').value=="Password:") {
				alert("Please supply your password.");
				e.stop();
				$('loginPassword').focus();
				return false;
			}
		});
	}
	if($('mailinglistForm')) {
		$('mailinglistForm').addEvent("submit", function(e) {
			if($('mlEmailAddress').value=="" || $('mlEmailAddress').value=="E-mail Address:") {
				alert("Please supply your e-mail address.");
				e.stop();
				$('mlEmailAddress').focus();
				return false;
			}
		});
	}

	$$('.mediaPlayer').addEvent('click',function() {
		var width = 500;
		var height = 200;
		
		var regExp = /([a-z]+)\[(\d+),(\d+)\]/i;
		var varArr = regExp.exec(this.get('rel'));
		if(varArr) {
			if(varArr[1]=="video") {
				if(varArr[2]!=0)
					width = parseInt(varArr[2]);
				if(varArr[3]!=0)
					height = parseInt(varArr[3]);
			}
			width+=37;
			height+=95;
			newWin = window.open(this.get('href'),"newWin","width=" + width + ",height=" + height);
			newWin.focus();
		}
		return false;
	});
	
	if($('printTool')) {
		$('printTool').addEvent('click', function() {
			print();
			return false;
		});
	}
});

function getNodeText(node) {
	if(!node.text) 
		return node.textContent;
	else 
		return node.text;
	
}
