/**
 * mouseoverPopup.js used to create a popup box on an event
 * @author: Ryan Winger
 */

// for mouse coordinates
var mousex;
var mousey;

var hideTime;

/**
 * Displays a popup message where the mouse is
 */
function showTip()
{
  clearTimeout(hideTime);
	
  var popupBck = document.getElementById("popupBck");
  var popupTxt = document.getElementById("popupTxt");
  var text = "";
	  
  switch(this.id)
  {
    case "Ph121":
	  text = "&nbsp;Principles of Physics I&nbsp;<br />&nbsp;Prerequisite: Math 112&nbsp;<br />&nbsp;Offered: F,W,S&nbsp;";
	  break;
	case "Ph127":
      text = "&nbsp;Descriptive Astronomy&nbsp;<br />&nbsp;Prerequisite: Math level: High School Algebra.&nbsp;<br />&nbsp;Offered: F&nbsp;";
	  break;
    case "FDMAT112":
      text = "&nbsp;Calculus I&nbsp;<br />&nbsp;Prerequisite: Math 110 and Math 111 or equivalent &nbsp;<br />&nbsp;Offered: F,W,S&nbsp;";
	  break;
    case "Ph123":
      text = "&nbsp;Principles of Physics II&nbsp;<br />&nbsp;Prerequisite: PH 121 or ME 204. Concurrent Registration or completion of Math 113 or Math 215&nbsp;<br />&nbsp;Offered: F,W,S&nbsp;";
	  break;
    case "Ma113":
      text = "&nbsp;Calculus II&nbsp;<br />&nbsp;Prerequisite: Math 112 or the equivalent&nbsp;<br />&nbsp;Offered: F,W,S&nbsp;";
	  break;
	  case "Ph150":
      text = "&nbsp;Beginning Physics Lab&nbsp;<br />&nbsp;Prerequisite: Completion of or concurrent enrollment in Physics 121&nbsp;<br />&nbsp;Offered: F,W,S&nbsp;";
	  break;
	case "ED200":
      text = "&nbsp;History and Philosophy of Education&nbsp;<br />&nbsp;Prerequisite: None&nbsp;<br />&nbsp;Offered: F,W,S&nbsp;";
	  break;
    case "Ph220":
      text = "&nbsp;Principles of Physics III&nbsp;<br />&nbsp;Prerequisite: Physics 121 or ME 204 Concurrent Registration or completion of Math 113 or Math 215&nbsp;<br />&nbsp;Offered: F,W,S&nbsp;";
	  break;
    case "Ph250":
      text = "&nbsp;Intermediate Physics Lab&nbsp;<br />&nbsp;Prerequisite: Math 112, Physics 150. Completion of or concurrent enrollment in Physics 220&nbsp;<br />&nbsp;Offered: F,W&nbsp;";
	  break;
   case "SPED360":
      text = "&nbsp;Exceptional Students (6th-12th grade)&nbsp;<br />&nbsp;Prerequisite: Ed 200 &nbsp;<br />&nbsp;Offered: F,W,S&nbsp;";
	  break;
    case "Ph279":
      text = "&nbsp;Modern Physics&nbsp;<br />&nbsp;Prerequisite: Math 113 or Math 215. Physics 121, 123.Completion of or concurrent enrollment in Physics 220&nbsp;<br />&nbsp;Offered: W,S&nbsp;";
	  break;
    case "ED304":
      text = "&nbsp;Educational Psychology&nbsp;<br />&nbsp;Prerequisite: ED 200&nbsp;<br />&nbsp;Offered: F,W,S&nbsp;";
	  break;
    case "Ph311":
      text = "&nbsp;Physics by Inquiry I&nbsp;<br />&nbsp;Prerequisite: Junior level standing or permission of the instructor.&nbsp;<br />&nbsp;Offered: F&nbsp;";
	  break;
    case "ED361":
      text = "&nbsp;Secondary Education Principles of Teaching&nbsp;<br />&nbsp;Prerequisite: ED 200, ED 304 (Ed 304 can be taken concurrently)&nbsp;<br />&nbsp;Offered: F,W,S&nbsp;";
	  break;
    case "Ph314":
      text = "&nbsp;History/Philosphy of Science&nbsp;<br />&nbsp;Prerequisite: None&nbsp;<br />&nbsp;Offered: F,W&nbsp;";
	  break;
	case "Ph403":
      text = "&nbsp;Methods of Physics Teaching&nbsp;<br />&nbsp;Prerequisite:PH 279 and PH 314&nbsp;<br />&nbsp;Offered: F&nbsp;";
	  break;
    case "Ph411":
      text = "&nbsp;Physics by Inquiry II&nbsp;<br />&nbsp;Prerequisite: PH 311&nbsp;<br />&nbsp;Offered: F&nbsp;";
	  break;
    case "ED461":
      text = "&nbsp;Reading in the Content Area&nbsp;<br />&nbsp;Prerequisite: Concurrent enrollment on PH 403&nbsp;<br />&nbsp;Offered: F&nbsp;";
	  break;
    case "ED492":
      text = "&nbsp;Student Teaching in the Public Schools&nbsp;<br />&nbsp;Prerequisite:All coursework completed&nbsp;<br />&nbsp;Offered: F,W,S&nbsp;";
	  break;
	default:
	  text="&nbsp;No info available&nbsp;";
  }
  
  popupTxt.innerHTML = text;
  popupBck.style.width = popupTxt.offsetWidth + 'px';
  popupBck.style.height = popupTxt.offsetHeight + 'px';
  
  popupTxt.style.top = mousey + 'px';
  popupTxt.style.left = mousex + 'px';
  popupBck.style.top = popupTxt.style.top;
  popupBck.style.left = popupTxt.style.left;
  
  popupBck.style.visibility="visible";
  popupTxt.style.visibility="visible";
}

/**
 * Displays more iinformation in the mousover popup
 */
function showMore(myId)
{
  document.getElementById("323Txt").style.display = "none";
  document.getElementById("324Txt").style.display = "none";
  document.getElementById("374Txt").style.display = "none";
  document.getElementById("375Txt").style.display = "none";
  
  switch(myId)
  {
    case "Ph323":
	  document.getElementById("323Txt").style.display = "inline";
	  break;
	case "Ph324":
	  document.getElementById("324Txt").style.display = "inline";
	  break;
	case "Ph374":
	  document.getElementById("374Txt").style.display = "inline";
	  break;
	case "Ph375":
	  document.getElementById("375Txt").style.display = "inline";
	  break;
  }
  var popupBck = document.getElementById("popupBck");
  var popupTxt = document.getElementById("popupTxt");
  popupBck.style.width = popupTxt.offsetWidth + 'px';
  popupBck.style.height = popupTxt.offsetHeight + 'px';
}

/**
 * Retrieves the mouse coordinates
 */
function getMouseXY(e)
{
  if (!e)
  {
    e = window.event;
  }
  if (e.pageX || e.pageY) 	
  {
	mousex = e.pageX;
    mousey = e.pageY;
  }
  else if (e.clientX || e.clientY) 	
  {
    mousex = e.clientX + document.body.scrollLeft
		   + document.documentElement.scrollLeft;
	mousey = e.clientY + document.body.scrollTop
		   + document.documentElement.scrollTop;
  }
}

/**
 * Hides the popup if desired
 */
function hideTip()
{
  if (this.id == "PhElective")
  {
    hideTime = setInterval("checkHideTip()", 1000);
  }
  else
  {
  	reallyHideTip();
  }
}

/**
 * Checks to see if the mouse is still on the popup
 */
function checkHideTip()
{
  var popback = document.getElementById("popupBck");
  var popx = popback.offsetLeft;
  var popy = popback.offsetTop;
  var popxx = popx + popback.clientWidth;
  var popyy = popy + popback.clientHeight;
  if (mousex < popx || mousex > popxx || mousey < popy || mousey > popyy)
  {
    reallyHideTip();
	clearInterval(hideTime);
  }
}

/**
 * Hides the popup
 */
function reallyHideTip()
{
  document.getElementById("popupBck").style.visibility="hidden";
  document.getElementById("popupTxt").style.visibility="hidden";
}

//event handler registration in mouseRegistration.js