var newsitems;
var curritem=0;
$(document).ready(function(){
	if (document.all) {
		$("ul#nav ul li:last-child").addClass("lastChild");
		$("ul#focalNav li:last-child").addClass("lastChild");
		$("ul#nav>li").hoverClass("hovering");
	}
	
	$("span.email").each(function(){
		$(this).html("<a href=\"mailto:" + $(this).html().replace(/( \[at\] )/g, "@").replace(/( \[(dot|period)\] )/g, ".").replace(/( \[dash\] )/g, "-") + "\" title=\"Send an email\">" + $(this).html().replace(/( \[at\] )/g, "@").replace(/( \[(dot|period)\] )/g, ".").replace(/( \[dash\] )/g, "-") + "<\/a>");
	});
	$("a[@rel=external]").not("[@onclick]")
		.click(function(){
			window.open(this.getAttribute("href"));
			return false;
		})
		.each(function(){ this.title += ((this.title.length > 0) ? "" : this.innerHTML) + " (opens in a new window)"; }
	);
	
	if ($("#ticker li").get(0)) {
		newsitems = $("#ticker li").hide().size();
		$("#ticker li:eq("+curritem+")").fadeIn();
		setInterval(ticknews,4000); //time in milliseconds
	}
});

function ticknews() {
	$("#ticker li:eq("+curritem+")").fadeOut();
	curritem = ++curritem%newsitems;
	$("#ticker li:eq("+curritem+")").fadeIn();
}

$.fn.hoverClass = function(c) {
    return this.each(function(){
        $(this).hover( 
            function() { $(this).addClass(c);  },
            function() { $(this).removeClass(c); }
        );
    });
};  

var IE = document.all?true:false
var tempX = 0
var tempY = 0

function getMouseXY(e) {
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.documentElement.scrollLeft
    tempY = event.clientY + document.documentElement.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }

  cHeight = $("div#tooltip").get(0).scrollHeight;
  if ((cHeight + tempY + 10 - document.documentElement.scrollTop) > myHeight) {
  	tempY = myHeight - cHeight - 10 + document.documentElement.scrollTop;
  }
  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  $("div#tooltip").css(
  	{
			left: tempX + 10 + "px", 
			top: tempY + 3 + "px"
		}
	);
	return true
}	

