
document.write('<link rel="stylesheet" type="text/css" href="/var/css/engine.css" media="screen" />');


jQuery(document).ready(function(){
		
		$('li.headlink:last-child').hover(
			function() {
					$(this).children('ul').addClass('add_pos');
			},
			function() { 
					$(this).children('ul').removeClass('add_pos');
			}
		)
		
		$('li.headlink:last-child a').focus(
			function() {
					$('li.headlink:last-child ul').addClass('add_pos');
			},
			function() { 
					$('li.headlink:last-child ul').removeClass('add_pos');
			}
		)
		
		/*
		$('div#top_menu li.headlink ul li a ').hover(
			function() {
					$(this).parent().parent().parent().children('a').css(
					  { 'background-position':'0 -37px'}
					);
			},
			function() { 
					$(this).parent().parent().parent().children('a').css(
					  { 'background-position':auto}
					);
			}
		)
		*/
});

/*
var engine = {
	start: function() {
		this.top_menu_maganer();
	},
	top_menu_maganer: function () {
		$('div#top_menu ul ul').css('visibility', 'hidden');
		$('div#top_menu ul ul').css('display', 'none');
		$('div#top_menu ul ul').css('position', 'absolute');
		$('div#top_menu ul ul').css('top', '100%');
		$('div#top_menu ul ul').css('left', '0');
		$('div#top_menu ul ul a').removeClass('over');
					

		$('div#top_menu li.headlink').hover(
			function() {
					var x = $(this).position().left;
					var y = $(this).position().top;
					$('a', this).addClass('over');
					if ($('div#main').width() < (x+$('ul', this).width())) {
						var d = (x+$('ul', this).width()) - $('div#main').width()+20;
						x = x-d;
					}
					$('ul', this).css('left', x);
					$('ul', this).css('top', y+37);
					$('ul', this).css('visibility', 'visible');
					$('ul', this).css('display', 'block');
			},
			function() { 
					$('ul', this).css('visibility', 'hidden');
					$('ul', this).css('display', 'none');
					$('a', this).removeClass('over');
			}
		)

	}
};

jQuery(document).ready(function(){
	engine.start();
});
*/


/**
 * Adds and removes classes to a list of links to allow keyboard accessibility
 *
 * @param string dropDownId
 * @param string hoverClass
 * @param int mouseOffDelay
 */
function dropdown(dropdownId, hoverClass, mouseOffDelay) {
	if(dropdown = document.getElementById(dropdownId)) {
		var listItems = dropdown.getElementsByTagName('li');
		for(var i = 0; i < listItems.length; i++) {
			listItems[i].onmouseover = function() { this.className = addClass(this); }
			listItems[i].onmouseout = function() {
				var that = this;
				setTimeout(function() { that.className = removeClass(that); }, mouseOffDelay);
				this.className = that.className;
			}
			
			var anchor = listItems[i].getElementsByTagName('a');
			anchor = anchor[0];
			anchor.onfocus = function() { tabOn(this.parentNode); }
			anchor.onblur = function() { tabOff(this.parentNode); }
		}
	}
	
	function tabOn(li) {
		if(li.nodeName == 'LI') {
			li.className = addClass(li);
			tabOn(li.parentNode.parentNode);
		}
	}
	
	function tabOff(li) {
		if(li.nodeName == 'LI') {
			li.className = removeClass(li);
			tabOff(li.parentNode.parentNode);
		}
	}
	
	function addClass(li) { return li.className + ' ' + hoverClass; }
	function removeClass(li) { return li.className.replace(hoverClass, ""); }
}
