// reset the baseline frames per second so that faster browsers calculate animation times better
YAHOO.util.AnimMgr.fps = 500;

// ---------------------------------------------------
var $D = YAHOO.util.Dom;
var $E = YAHOO.util.Event;
var $A = YAHOO.util.Anim;
var $Ease = YAHOO.util.Easing;
var $ = $D.get;

YAHOO.chanhassen = function() {
	return {
		init : function() {
			var droppers = $D.getElementsByClassName('dropdown', 'li', 'nav');
			$E.on(droppers, 'mouseover', this.dropdown);
			$E.on(droppers, 'mouseout', this.dropup);
			
			$E.on(document.body, 'mouseover', function(e) {
				var xPos = $E.getPageX(e);
				var yPos = $E.getPageY(e);
				for(j = 0; j < droppers.length; j++) {
					if(
						yPos > (droppers[j].offsetHeight+$D.getY(droppers[j])) || yPos < $D.getY(droppers[j]) ||
						xPos > (droppers[j].offsetWidth+$D.getX(droppers[j])) || xPos < $D.getX(droppers[j])
					) {
						var numItems = $D.getElementsByClassName('nested', 'ul', droppers[j])[0].getElementsByTagName('li');
						var time = droppers[j].oHeight/3500;
						var drop = new $A(droppers[j], {height: {to: 30}}, time);
						drop.animate();
					}
				}
			});
			$E.on(document.body, 'contextmenu', function(e) {
				$E.stopEvent(e);
			});
			if ($D.getElementsByClassName('main', 'div').length > 0) {
        var links = $D.getElementsByClassName('main', 'div')[0].getElementsByTagName('a');      
        for(var i = 0; i < links.length; i++) {
          if(links[i].href.indexOf('chanhassentheatres.com') == -1) {
            $E.on(links[i], 'click', this.newWindow);
          }
        }
      }
		},
		
		// ---------------------------------------------------
		
		// dropdown/dropup for the internal pages, Sales Support, Tech Support, Leads, Products
		dropdown : function() {
			var that = this;
			var dropped = $D.getElementsByClassName('dropped', 'li', 'nav');			
			var numItems = $D.getElementsByClassName('nested', 'ul', this)[0].getElementsByTagName('li');

			// find the necessary height. IE is kind of a jerk about this.
			var time = this.oHeight/2000;
			var drop = new $A(this, {height: {to: this.oHeight}}, time);
			drop.animate();
		},
		dropup : function(e) {
			var that = this;
			var xPos = $E.getPageX(e);
			var yPos = $E.getPageY(e);
			if(
				yPos > (that.offsetHeight+$D.getY(that)) || yPos < $D.getY(that) ||
				xPos > (that.offsetWidth+$D.getX(that)) || xPos < $D.getX(that)
			) {
				var numItems = $D.getElementsByClassName('nested', 'ul', that)[0].getElementsByTagName('li');
				var time = that.oHeight/2500;
				var drop = new $A(that, {height: {to: 30}}, time);
				drop.animate();
			}

		},
		
		newWindow : function(e) {
			$E.stopEvent(e);
			window.open(this.href, 'blank');
		}
	}
}();
YAHOO.util.Event.onAvailable('nav', YAHOO.chanhassen.init, YAHOO.chanhassen, true);		
