$(function(){
	$('ul.rollover li').rollovers().swapNav();
});

/**
 * $().swapNav();
 */
jQuery.fn.swapNav = function(){
	$.swapNav(this);
	return this;
};

jQuery.swapNav = function(el){
	$(el).each(function(){
		$('a',this)
			.each(function(){
				this.props = this.rel.split(',');
				$('ul#sub_'+this.props[0]).left(this.props[1]+'px');
			})
			.mouseover(function(){
				$('div.subnav ul').hide();
				$('ul#sub_'+this.props[0]).show();
			});
	});
}

/**
 * $().rollovers();
 */
jQuery.fn.rollovers = function(){
	$.rollovers(this);
	return this;
};

jQuery.rollovers = function(el){
	$(el).each(
		function(){
			$('img[@src *= "_off."]',this)
				.each(
					function(){
						//$('self::ancestor::li',this).each(function(){alert(this);})
						// preload on states
						el = this;
						// using Image objects for both so IE will preload correctly.
						el.overObj = new Image();
						el.outObj = new Image();
						el.outObj.src = el.src;
						el.overObj.src = el.src.replace(/_off\.([a-z]{3,4})$/i,"_on.$1");
					}
				)
				.mouseover(
					// mouseover
					function(e){
						$('img[@src *= "_on."]',getParent(this,'ul')).each(function(){
							this.src = this.outObj.src;
						});
						this.src = this.overObj.src;
						//e.stopPropagation();
					}
				);
		}
	);
};


	
function getParent(el,tag){
	while(el != document.body && el.nodeName.toLowerCase() != tag.toLowerCase())
		el = el.parentNode;
	
	if(el.nodeName.toLowerCase() != tag.toLowerCase())
		return null;
		
	return el;
}