window.addEvent('domready', function() {
	$('headerMenu').getElements('li').each( function( elem ){
		var list = elem.getElement('ul.subMenu');
		var wrapperEle = elem.getElement('div.subMenuContainer');
		if(list) {
			wrapperEle.setStyle('display','block');
			var myFx = new Fx.Slide(list);
			myFx.hide();
			elem.addEvents({
				'mouseenter' : function(){
					myFx.cancel();
					myFx.slideIn();
				},
				'mouseleave' : function(){
					myFx.cancel();
					myFx.slideOut();
				}
			});
		}
	});
	$$('ul.subMenu li').addEvents({
			'click': function(e) {
				if(this.getElement("a").get("target") && this.getElement("a").get("target").toUpperCase()=="_BLANK") {
					e.stop();
					window.open(this.getElement("a").get('href'),"newWin");
				} else {
					e.stop();
					location.href = this.getElement("a").get('href');
				}
			},
			'mouseenter' : function(){
				this.className = 'hover';
			},
			'mouseleave' : function(){
				this.className = '';
			}
	});

	$$('.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;
	});
	
	$('printTool').addEvent('click', function() {
		print();
		return false;
	});
});

function getNodeText(node) {
	if(!node.text) 
		return node.textContent;
	else 
		return node.text;
	
}