﻿// JScript File
function addArticleHistoryPoint(articleId, pageNum)
{
//	Sys.Application.get_history().addHistoryPoint(
//	{
//		"Reader": 
//		{
//			"PageType": "Article",
//			"ArticleId": articleId,
//			"PageNumber":pageNum
//		}		
//	});
}

function addSectionHistoryPoint(sectionId, subsectionId)
{
//	Sys.Application.get_history().addHistoryPoint(
//	{
//		"Reader":
//		{
//			"PageType": "Section",
//			"Section": sectionId,
//			"SubSection": subsectionId
//		}
//	});
}

//function pageNavigate(sender, args)
//{
//	var reader = args.get_state()["Reader"];
//	
//	if(reader)
//	{
//		if(reader.PageType == "Article")
//		{
//			ArticleTypeHistory(reader.ArticleId, reader.PageNumber);
//		}
//		else
//		{
//			if(reader.PageType == "Section")
//				{
//					SectionTypeHistory(reader.Section, reader.SubSection);
//				}
//		}
//	}	
//}

//Copied from MS library.js and altered slightly to fit author hover over requirements
var info = new info();
var tipFadeTimeout = new Array();
var tipFadeColors = "#ffff99,#ffffc0,#ffffd9,#ffffe7";
var tipFadeInit = false;
var tipInitX, tipInitY, tipCurX, tipCurY;
var tipObjCur;
var tipObjCurSrcElement;
var tipFadeLast;

function info () {
    this.showTip = showTip;
    this.tipMouseOut = tipMouseOut; 
    this.tipMouseOn = tipMouseOn;  
    this.mouseMove = mouseMove; 
    this.hideTip = hideTip; 
    this.showStatus = showStatus;  
    this.doShowBio = doShowBio;
   
	function doShowBio(obj, text, evt)
	{
		info.showTip(obj, text);
		var ttip = document.getElementById(obj.id + "_tip");
		if (ttip != null)
		{
		    browser = browserUtility.getBrowser();
    		
		    ttip.style.left = (browser == "ie") ? (window.event.x) : evt.pageX;
		    ttip.style.top = (browser == "ie") ? (window.event.y) : evt.pageY;
		}
		
	}

    function showStatus(obj, text) {
       info.showTip(obj, "searching...");
       if (obj)
       if (obj.style != undefined)
       obj.style.color = "#ccc";
       obj.style.cursor = "wait";
    }     
   
     this.setMouseMoveHandler = setMouseMoveHandler;
     
    function  setMouseMoveHandler() {
        if (browserUtility.getBrowser() == "ie") {
            document.onmousemove = info.mouseMove;
       } else {
            window.captureEvents(Event.MOUSEMOVE);
	        window.onmousemove = info.mouseMove;
	   } 
    }    
   
    this.cancelMouseMoveHandler = cancelMouseMoveHandler;
   
  function cancelMouseMoveHandler() {
       
       if (browserUtility.getBrowser() == "ie") {
            document.onmousemove = "void";
       } else {
            window.captureEvents(Event.MOUSEMOVE);
	        window.onmousemove = "void";
	   } 
	     tipInitX = "";
         tipInitY = "";
    }      
   
    function showTip(obj, text) {
    
        if (text != null)
        {
            var objChange = (tipObjCurSrcElement = obj) ? false: true;
            tipObjCurSrcElement = obj; 
           
            var tip = document.createElement("span");
            tip.id = obj.id + "_tip"; 
            tip.className = "info"; 
            
           var close =  '<div title="Close" class="info_close" onclick="info.hideTip(document.getElementById(\'' + obj.id + '\'));"/>'; 
           var closeChild = document.createElement("div");
            closeChild.innerHTML = close;
           
            if (text.style != undefined || text.className != undefined) {//if obj w/ html instead of just text
                
                if (text.style.width) tip.style.width = text.style.width;
                if (text.style.height) tip.style.height = text.style.height;
                
                if (text.style.position) {
                    tip.style.position = text.style.position;
                   if (text.style.left)  tip.style.left = text.style.left;
                   if (text.style.top)  tip.style.top = text.style.top;
                }
                tip.innerHTML += text.innerHTML;
                var firstNode = xmlUtility.getFirstComplexChild(tip);
                firstNode.insertBefore(closeChild,firstNode.childNodes[0]);
                tip.style.display = 'block'; 
           } else {
                tip.innerHTML += close;
                tip.innerHTML += '<div class="info_text">' + text + '</div>'; 
            } 
           
           
           
          
           var nextSibling = domNav.returnNextSibling(obj);
           if (nextSibling) {
                if (nextSibling.id != tip.id) {
                        obj.parentNode.insertBefore(tip,nextSibling);
                } else {
                        tip = document.getElementById(obj.id + "_tip");
                        tip.style.display = 'block'; 
                } 
          } else {
             obj.parentNode.appendChild(tip);
         } 
         
         tipObjCur = tip; 
         setMouseMoveHandler();//sets global tipInitX, tipInitY, etc vars
     }
   }    
  
    function mouseMove(e) {
		var browser = browserUtility.getBrowser();
		
        var x = (browser == "ie") ? (event.x - 40) : e.pageX;
        var y = (browser == "ie") ? (event.y + document.body.scrollTop): e.pageY; 
       if (!tipInitX) {
            tipInitX = parseInt(x);
            tipInitY = parseInt(y);
       } else {
            tipCurX = parseInt(x);
            tipCurY = parseInt(y);
            
            
            var tipObjX = parseInt(tipObjCur.offsetWidth);
            var tipObjY = parseInt(tipObjCur.offsetHeight);
            
            var outOfBoundsX = (tipCurX > Math.min((tipInitX + tipObjX + 5),400) || tipCurX < (tipInitX - 5)) ? true : false;
            var outOfBoundsY = (tipCurY > Math.min((tipInitY + tipObjY + 5),400) || tipCurY < (tipInitY - 5)) ? true : false;
            
            //window.status = " current x: " + x + " current y: " + y + " bounds x:  " + (tipInitX - 5) + " to " + Math.min((tipInitX + tipObjX + 5),400) + " bounds y: " + (tipInitY - 5) + " to " + Math.min((tipInitY + tipObjY + 5),400);
            
            if ((outOfBoundsX || outOfBoundsY) && tipFadeLast != "out") tipMouseOut(tipObjCur.id);
            if (!outOfBoundsX && !outOfBoundsY && tipFadeLast != "in") tipMouseOn(tipObjCur.id);
            
       }
     }   
  
    function tipMouseOut (id) {
        tipFadeLast = "out"; 
        clearFade();
        tipFade(id,true,250,250);
      }    
     
      function tipMouseOn (id) {
       tipFadeLast = "in"; 
       clearFade();
       tipFade(id,false,10,50);
     }   
     
     function tipFade(id,boolForward, fadeWait, fadeInterval) {
         var colorArray = (boolForward) ? tipFadeColors.split(",") : tipFadeColors.split(",").reverse();   
         var display = (boolForward) ? "none": "block";
         var setMouseHandler = (boolForward) ? "info.cancelMouseMoveHandler()" : "info.setMouseMoveHandler()"; 
         
          for (i=0;i<colorArray.length;i++) {
               tipFadeTimeout[i] = window.setTimeout("document.getElementById('" + id + "').style.backgroundColor = '" + colorArray[i] + "';",fadeWait);
               fadeWait += fadeInterval; 
          }
          tipFadeTimeout[i+1] = window.setTimeout("document.getElementById('" + id + "').style.display = '" + display + "';eval(" + setMouseHandler + ");",fadeWait +fadeInterval);
     }
     
     function clearFade() {
        for (i=0;i<tipFadeTimeout.length;i++) {
            if (tipFadeTimeout[i] != "") window.clearTimeout(tipFadeTimeout[i]);
        } 
     }
   
    function hideTip(obj) {
        var tip = document.getElementById(obj.id + "_tip"); 
        if (tip != undefined) tip.style.display = 'none'; 
    }      
   
         
}