

	isIE6 = /msie|MSIE 6/.test(navigator.userAgent);
	isIE8 = /MSIE 8/.test(navigator.userAgent);
	var isIE = /MSIE/.test(navigator.userAgent);
	
	if (!isIE8)
	{
		if (!window.Prototype)
			{
			   var head = document.getElementsByTagName('head')[0];
			   var script = document.createElement('script');
			   script.type = 'text/javascript';
			   script.src= '/js/prototype/prototype.js';
			   script.defer = 'defer';
			   //window.attachEvent("onload",  function() { alert('aaa'); }); 
			  
			   script.onload = function() {
				startObserver();
			   }
			   head.appendChild(script);
		} else {
			startObserver();
		}
	}
	
	
	
	function login()
	{
		$('login_form').submit();
	}
	function belongsToChild(element, event)  {
		  var target = event.element();
		  if (target === element)
			  target = event.relatedTarget;
		  return (target && target.descendantOf(element));
	}
	
	var login_timer = false;
	function resetTimer()
	{
		clearTimeout(window.login_timer);
	}
	function startObserver() {
	Event.observe(window, 'load', function() {
			var login_form = 
			'<div class="login-form">' +
			'<form id="login_form" method="post" action="https://www.siteground.com/ua_files/login.php">' +
		 		'<label for="username" class="uname">Username:</label>' +
				'<input type="text" name="username" id="login_username" onkeydown="resetTimer()" />' +
            	'<label for="password" class="pass" onkeydown="resetTimer()">Password:</label>' +
				'<input type="password" name="passwd" id="login_password" />' +
		  		'<a href="pass_lookup.htm" class="fyp">Forgot your password?</a>' +
		  		'<a href="javascript:login()" class="login-btn">Login</a>' +
		  		'<input type="submit" style="display: none" />' +
			'</form>' +
			'</div>'
			;
			if (!isIE6)
			{
				document.observe('mouseover',function(event){
			    	if (belongsToChild($$('#top_menu ul li').last(), event)) 
			    	{
			    		clearTimeout(window.login_timer);
			    	} else {
			    		if ($$('#top_menu ul li').last().down('a').hasClassName('show') ) {

			    			if ($('login_username').value.length == 0 && $('login_password').value.length == 0)
			    			{
					    		window.login_timer = window.setTimeout(function() {
					    			if ($('login_username').value.length == 0 && $('login_password').value.length == 0)
					    			{
							    		$$('.login-form').first().setStyle({display:"none"});
							    		$$('#top_menu ul li').last().down('a').removeClassName('show');
										$$('#top_menu ul li').last().down('a').removeClassName('login-form-link');
										if ($$('#top_menu ul li').last().hasClassName('current'))
											$$('#top_menu ul li').last().removeClassName('current');
									}
					    		}, 1000);
			    			}
			    		}
			    	}
				});
				
				
				$$('#top_menu ul li').last().setStyle({position:"relative"}).innerHTML += login_form;
				$$('#top_menu ul li').last().down('a').observe('click', function(event) {
					
					if (typeof disablePopup == 'function')
						disablePopup();
					
					event.stop();
					if ($$('#top_menu ul li').last().hasClassName('current'))
						$$('#top_menu ul li').last().removeClassName('current');
					if (!this.hasClassName('show') ) {
						this.addClassName('show');
						$$('#top_menu ul li').last().down('a').addClassName('login-form-link');
						$$('.login-form').first().setStyle({display:"block"});
					} else {
						this.removeClassName('show');
						$$('#top_menu ul li').last().down('a').removeClassName('login-form-link');
						$$('.login-form').first().setStyle({display:"none"});
					}
					$('login_username').focus();
					if (isIE)
						return false;
				});
				$$('#top_menu ul li').last().down('a').onclick = function() {return false;};
			}
		});
	}
