sfHover = function() {
	var sfEls = $("#nav li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
		if (ifOutsideWindow(sfEls[i],null)) {
			
			$(".navbox",sfEls[i]).css("right","0px");
			
		} else {
			$(".navbox",sfEls[i]).css("left","0px");
		}
	}
}

sfHoverMultiple = function() {
	var sfEls = $(".nav li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}

function windowSize() {
	var a=new Array();
	if ($.browser.mozilla) {
			a["width"] = window.innerWidth-16;
			a["height"] = window.innerHeight-16;
	}	
	if ($.browser.msie) {
		a["width"] = document.body.offsetWidth-20;
		a["height"] = document.body.offsetHeight-20;
		}
		
	return a;
}

function ifOutsideWindow(el,w) {
	var wsize=windowSize();
	
	var a=$(el).offset();	
	
	if (w==null) {
		var els=$("table",el);
		if (els.length>0) 
			w=parseInt(els[0].width);
	}
	if (w!=null) {	
		if (a.left + w > wsize.width) {
			return true;
		}
	}
	return false;
}

function setPosition(obj,x,y) {
	obj.style.left=x + "px";
	obj.style.top=y + "px";
}

//if (window.attachEvent) 
$(document).ready(sfHover);

//window.attachEvent("onload", sfHover);
