/*sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("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 (window.attachEvent) window.attachEvent("onload", sfHover);
*/




sfHover = function () {

    //window.document.title = "";

    var sfEls = $("#nav li.mainli");
    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, .navbox-1", sfEls[i]).css("right", "0px");

        } else {
             $(".navbox, .navbox-1", sfEls[i]).css("left", "0px");
        }
    }
    $("#nav #nav1 .first-sub").bind("mouseover", function () {
        window.lastCont = null;
        window.clearTimeout(window.inter);

        //window.document.title += "1";

    });

    $("#nav #nav1 .first-sub").bind("mouseout", function () {

        //window.document.title += "2";

        window.lastCont = this.parentNode;
        window.inter = window.setTimeout(function () { if (window.lastCont != null) $("div.first-sub", window.lastCont).hide();  }, 500);
        //$(this).hide();
    });

    $("#nav #nav1 .subnav li.mainli1").each(function () {

        $(this).bind("mouseover", function () {

            //window.document.title += "3";

            $("div.first-sub").hide();

            $("div.first-sub", this).show();

        });

        $(this).bind("mouseout", function () {

            //window.document.title += "4";

            window.lastCont = this;
            window.inter = window.setTimeout(function () { if (window.lastCont != null) $("div.first-sub", window.lastCont).hide(); }, 500);

        });

    });

}

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);
