ONEHAT.widget.mainMenu = {
	init: function() {
		
		// Animation object
		var oAnim;
		
		
		// "beforeshow" event handler for each submenu of the menu bar
		function onMenuBeforeShow(p_sType, p_sArgs) {
		    var oBody, oShadow, oUL;

			if (this.parent) {
				oShadow = this.element.lastChild;
				oShadow.style.height = "0px";
				if (oAnim && oAnim.isAnimated()) {
					oAnim.stop();
					oAnim = null;
				}
				oBody = this.body;
				oUL = oBody.getElementsByTagName("ul")[0];
				YAHOO.util.Dom.setStyle(oBody, "overflow", "hidden");
				YAHOO.util.Dom.setStyle(oUL, "marginTop", ("-" + oUL.offsetHeight + "px"));		
		    }
		}
		
		function onTween(p_sType, p_aArgs, p_oShadow) {
			if (this.cfg.getProperty("iframe")) {
				this.syncIframe();
			}
			if (p_oShadow) {
				p_oShadow.style.height = this.element.offsetHeight + "px";
			}
		}
		
		function onAnimationComplete(p_sType, p_aArgs, p_oShadow) {
		    var oBody = this.body,
		        oUL = oBody.getElementsByTagName("ul")[0];
		
		    if (p_oShadow) {
				p_oShadow.style.height = this.element.offsetHeight + "px";		    
		    }
		
		    YAHOO.util.Dom.setStyle(oUL, "marginTop", "auto");
		    YAHOO.util.Dom.setStyle(oBody, "overflow", "visible");
		    
		    if (YAHOO.env.ua.ie) {
				YAHOO.util.Dom.setStyle(oBody, "zoom", "1");
		    }
		}
		
		
		// "show" event handler for each submenu of the menu bar
		function onMenuShow(p_sType, p_sArgs) {
		    var oElement, oShadow, oUL;
		
		    if (this.parent) {
		        oElement = this.element;
		        oShadow = oElement.lastChild;
		        oUL = this.body.getElementsByTagName("ul")[0];
				
		        oAnim = new YAHOO.util.Anim(oUL, 
		            { marginTop: { to: 0 } },
		            0.5, YAHOO.util.Easing.easeOut);

				oAnim.onStart.subscribe(function () {
					oShadow.style.height = "100%";
				});
				
		        oAnim.animate();
		
				//Refire the event handler for the "iframe" 
				//configuration property with each tween so that the  
				//size and position of the iframe shim remain in sync 
				//with the menu.
		        if (YAHOO.env.ua.ie) {
					oShadow.style.height = oElement.offsetHeight + "px";
					oAnim.onTween.subscribe(onTween, oShadow, this);
		        }
		
		        oAnim.onComplete.subscribe(onAnimationComplete, oShadow, this);
		    }
		}
		
		// Instantiate and render the menu bar
		var oMenuBar = new YAHOO.widget.MenuBar('mainMenu', {
			autosubmenudisplay: true,
			hidedelay: 750,
			showdelay: 0,
			lazyload: true/*,
			effect: {
				effect: YAHOO.widget.ContainerEffect.FADE,
				duration: 0.35
			}*/
		});
		
		oMenuBar.subscribe('beforeShow', onMenuBeforeShow);
		oMenuBar.subscribe('show', onMenuShow);
		
		oMenuBar.render();            		
		
	}
};

ONEHAT.widget.mainMenu.init();


ONEHAT.widget.loginPanel = {
	init: function() {
		var oThis = this;
		
		this.link = $('loginLink');
		if (YAHOO.util.Dom.hasClass($('loginLink'), 'useSSL')) {
			this.useSSL = true;
		}
		
		// assign event handler
		if (this.link.innerHTML === 'Site Admin') {
			YUE.addListener(this.link, 'click', function(e) {
				YUE.stopEvent(e);
				oThis.show(e);
			});
		}

	},
	
	show: function(e) {
		if (!this.loginPanel) {
			var XY = YUE.getXY(e);
			
			YAHOO.util.Dom.removeClass($('loginPanel'), 'hide'); // starts hidden - otherwise IE draws content lower, then corrects it
			this.loginPanel = new YAHOO.widget.Panel('loginPanel', {
				width: '222px', 
				fixedcenter: false, 
				constraintoviewport: false, 
				underlay: 'none', 
				close: true, 
				visible: false, 
				draggable: true,
				x: XY[0] -111,
				y: XY[1] -150,
				width: '222px',
				zIndex: 500,
				iframe: false
			});
			this.loginPanel.setHeader('Login');

			if (this.useSSL) {
				var formAction = 'https://' + window.location.host + '/login';
			} else {
				var formAction = 'login';
			}

			this.loginPanel.setBody(
				'<form action="' + formAction + '" method="post" name="form1" target="_top" id="form1">' +
	//			'		<fieldset>' +
	//			'			<legend>Please Login</legend>' +
						
				'			<div class="field">' +
				'				<label for="userID" class="fixedWidth">User ID</label>' +
				'				<input class="text short" autocomplete="off" value="" name="userID" id="userID" type="text" />' +
				'			</div>' +
					
				'			<div class="field">' +
				'				<label for="password" class="fixedWidth">Password</label>' +
				'				<input class="password short" autocomplete="off" value="" name="password" id="password" type="password" />' +
				'			</div>' +
					
	//			'		</fieldset>' +
				'		<input class="small" name="submit" id="submit" value="Login" type="submit" />' +
				'		</form>'
			);
			this.loginPanel.setFooter(' ');
			this.loginPanel.render();
			
		}
		
		this.loginPanel.show();		
	}
	
};

ONEHAT.widget.loginPanel.init();
