window.onresize = function() {
	if (navArrow.resetButton) navArrow.set(navArrow.resetButton);
}

var navArrow = new function() {
	this.resetX = null;
	this.effect = null;
	this.resetButton = null;

	this.to = function(button) {
		var currX = parseInt($('nav_arrow').offsetLeft);
		if (!this.resetX) {
			this.resetX = currX;
		}
		var newX = this.getX(button);
		var diffX = newX - currX;
		var transition = Effect.Transitions.sinoidal;
		var duration = Math.abs(diffX)/500;
		if (this.effect) { this.effect.cancel(); }
		else {
			$('nav_arrow').onmouseover=function() { navArrow.effect.cancel(); };
			$('nav_arrow').onmouseout=function() { navArrow.reset(); };
			if (document.all || navigator.vendor.match('Apple')) {
				/* IE Glitch Fix */
				$('nav_arrow').style.top = '142px';
				$('nav_arrow').style.left = ($('content').offsetLeft+12)+'px';
			}
		}
		this.effect = new Effect.Move('nav_arrow', { 
		  duration: duration,
		  transition: transition,
		  x: diffX
		});
	}
	
	this.getX = function(elem) {
		var x = parseInt(elem.offsetLeft)+12;
		while (elem.offsetParent) {
			x += elem.offsetParent.offsetLeft;
			elem = elem.offsetParent;
		}
		return x;
	}
	
	this.reset = function() {
		if (this.effect) this.effect.cancel();
		var currX = parseInt($('nav_arrow').offsetLeft);
		var diffX = this.resetX-currX;
		var transition = Effect.Transitions.sinoidal;
		var duration = Math.abs(diffX)/500;
		this.effect = new Effect.Move('nav_arrow', { 
		  duration: duration,
		  transition: transition,
		  x: diffX
		});
	}
	
	this.set = function(button) {
		this.resetX = this.getX(button);
		this.resetButton = button;
		this.to(button);
	}
}
var navMenu = new function() {
	this.hideTO = [];
	this.showTO = [];
	this.shown = null;
	this.effect = null;
	this.button = null;
	
	this.show = function(button,menuid) {
	
		if (button) {
			if (this.button) this.button.style.backgroundImage = '';
			this.button = button;
		}
		navArrow.to(this.button);
		this.button.style.backgroundImage = 'url(/images/common/nav_bg_on.gif)'; 
		
		if (menuid) { // has menu
			if (menuid == this.shown || !button) {
				if (this.hideTO[menuid]) {
					clearTimeout(this.hideTO[menuid]);
					delete this.hideTO[menuid];
				}
				return;
			}
			var newX = button.offsetLeft;
			var elem = button;
			while (elem.offsetParent) {
				newX += elem.offsetParent.offsetLeft;
				elem = elem.offsetParent;
			}
			$(menuid).setStyle({'left':newX+'px'});
			if (!this.showTO[menuid])
				this.showTO[menuid] = setTimeout("navMenu.reveal('"+menuid+"');",400);
		} else { // no menu
			if (this.shown && this.shown!=menuid)
				this.conceal(this.shown,true);
		}
		
		button.onmouseout = function() {
			if (menuid) {
				navMenu.hide(menuid);
			} else {
				navArrow.reset();
				this.style.background = '';
			}
		};
	}
	
	this.hide = function(menuid) {
		if (this.showTO[menuid]) {
			clearTimeout(this.showTO[menuid]);
			delete this.showTO[menuid];
		}
		if (menuid != this.shown) return;
		if (!this.hideTO[menuid])
			this.hideTO[menuid] = setTimeout("navMenu.conceal('"+menuid+"');",600);	//important! hideTO > showTO interval
	}
	
	this.reveal = function(menuid) {
		if (this.shown && this.shown!=menuid)
			this.conceal(this.shown,true);
		$(menuid).onmouseover = function() { navMenu.show(this.button,menuid); }
		$(menuid).onmouseout = function() { navMenu.hide(menuid); }
		this.effect = new Effect.SlideDown(menuid, {'duration':0.4});
		delete this.showTO[menuid];
		this.shown = menuid;
	}
	
	this.conceal = function(menuid,forced) {
		if (!forced) {
			navArrow.reset();
			this.button.style.backgroundImage = '';
		}
		this.effect = new Effect.SlideUp(menuid, {'duration':0.4});
		if (this.hideTO[menuid]) {
			clearTimeout(this.hideTO[menuid]);
			delete this.hideTO[menuid];
		}
		this.shown = null;
	}
}

function getFlashMovie(movieName) {
  var isIE = navigator.appName.indexOf("Microsoft") != -1;
  return (isIE) ? window[movieName] : document[movieName];
}
