/*************************************************
*	General GMTR Javascript Functions        *
*	By Steven Wathen			 *
*	01/06/2009				 *
**************************************************/

/*Open a tags with 'rel=external' attribute in a new window*/
/* Using 'target=_blank" is not standard compiant*/

  window.onload = function() {
    var links = document.getElementsByTagName("a");
    for (var i = 0; i < links.length; i++) {
      var rels = links[i].getAttribute("rel");
      if (rels) {
        var testpattern = new RegExp("external");
        if (testpattern.test(rels)) {
          links[i].onclick = function() {
            return !window.open(this.href);  
          }
        }
      }    
    }
  }
  
  
  this.tooltip = function(){
  	/* CONFIG */
  	var xOffset = 10;
  	var yOffset = 20;
  	//these 2 variable determine popup's distance from the cursor
  	// you might want to adjust to get the right result
  	/* END CONFIG */
  	
  	$(".jqtooltip").hover(function(e){
  		$(this).css('cursor','help');
  	},
  	function(){
  		$(this).css('cursor','default');
  		$("#tooltip").remove();
  	});
  	
  	$(".jqtooltip").click(function(e){
  		this.t = $(this).attr('toolTipText');
  		this.title = "";
  		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
  		$("#tooltip")
  			.css("top",(e.pageY - xOffset) + "px")
  			.css("left",(e.pageX + yOffset) + "px")
  			.fadeIn("fast");
      });
  	
  	$(".jqtooltip").mousemove(function(e){
  		if($("#tooltip").length>0){
  			$("#tooltip").css("top",(e.pageY - xOffset) + "px");
  			$("#tooltip").css("left",(e.pageX + yOffset) + "px");
  		}
  	});
  };
  
  
  function getPageSizeWithScroll(){
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
	}
	//if(window.outerHeight > yWithScroll){
	//	yWithScroll = window.outerHeight;
	//}
	arrayPageSizeWithScroll = yWithScroll;
	//alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
	return arrayPageSizeWithScroll;
   }


  // starting the script on page load
  $(document).ready(function(){
  	//Set the body height so that the #page div always fills the screen height;
  	//$("body").height(getPageSizeWithScroll());
  	tooltip();
});