/** History Functions **/

/** Track Mouse Location **/
//http://www.js-examples.com/page/javascripts__example.html?view=362
var isIE = document.all?true:false;
var mouse_x,mouse_y, timeoutID, currentCountry;
var historyTimeout = false;

var _GET = getSearchAsArray();

function loadHistory(){
    if (_GET["country"]){
        showPopup(_GET["country"],_GET["country"]);
        if (!_GET["page"]){
            eval(_GET["country"]+'_showIntro();');
        }
        else{
            eval(_GET["country"]+'_show'+ _GET["page"] +'();');
        }
    }
}
if (!isIE) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = getMousePosition;
function getMousePosition(e) {
  var _x;
  var _y;
  if (!isIE) {
    _x = e.pageX;
    _y = e.pageY;
  }
  if (isIE) {
    _x = event.clientX + document.body.scrollLeft;
    _y = event.clientY + document.body.scrollTop;
  }
  mouse_x = _x;
  mouse_y = _y;
  
  if (historyTimeout != false){
    updateHover(historyTimeout);
    //timeoutID = window.setTimeout("updateHover('"+historyTimeout+"');",1000);
  }
  return true;
}

function hoverCountry(country){
    if (country != currentCountry && currentCountry != null){
        get_itm("tip_"+currentCountry).style.display = "none";
    }
    if (timeoutID != null){
        window.clearTimeout(timeoutID);
    }
    currentCountry = country;
    var itm = get_itm("tip_"+country);
    itm.style.display = "block";
    itm.style.position = "absolute";
    itm.style.left = mouse_x + "px";
    itm.style.top = mouse_y + "px";
    historyTimeout = country;
}
function unHoverCountry(country){
    if (timeoutID != null){
        window.clearTimeout(timeoutID);
    }
    historyTimeout = false;
    //Get Hover Div
    timeoutID = window.setTimeout('get_itm("tip_'+country+'").style.display = "none"',100);
}
function updateHover(country){
    //Get Hover Div
    var itm = get_itm("tip_"+country);
    if (Math.abs(parseInt(itm.style.left) - mouse_x) > 10 || Math.abs(parseInt(itm.style.top) - mouse_y) > 10){
        var pos_x = mouse_x + 4;
        var pos_y = mouse_y + 4;
        itm.style.left = pos_x + "px";
        itm.style.top = pos_y + "px";
    }
}
function showPopup(country,countryName){
    get_itm("worldmap_popup").style.display = "block";
    get_itm("worldmap_popup_content").innerHTML = get_itm(country+"_content").innerHTML;
    changeTitle(countryName);
}
function changeTitle(txt){
    get_itm("worldmap_popup_title").innerHTML = txt;
}

function closeBox(){
    get_itm("worldmap_popup").style.display = "none";
}

/** China **/
function china_showIntro(){
    changeTitle("China - Introduction");
    
    get_itm("china_intro").style.display = "block";
    get_itm("china_gougu").style.display = "none";
    get_itm("china_nine").style.display = "none";
}
function china_showGougu(){
    changeTitle("China - Gougu Theorem");
    
    get_itm("china_intro").style.display = "none";
    get_itm("china_gougu").style.display = "block";
    get_itm("china_nine").style.display = "none";
}
function china_showNine(){
    changeTitle("China - Nine Chapters on the Mathematics Arts");
    
    get_itm("china_intro").style.display = "none";
    get_itm("china_gougu").style.display = "none";
    get_itm("china_nine").style.display = "block";
}

/** Babylonia **/
function babylonia_showIntro(){
    changeTitle("Ancient Babylonia - Introduction");
    
    get_itm("babylonia_intro").style.display = "block";
    get_itm("babylonia_nos").style.display = "none";
}
function babylonia_showNos(){
    changeTitle("Ancient Babylonia - Babylonian Numerals");
    
    get_itm("babylonia_intro").style.display = "none";
    get_itm("babylonia_nos").style.display = "block";
}

/** Arabia **/
function arabia_showIntro(){
    changeTitle("Arabia - Introduction");
    
    get_itm("arabia_intro").style.display = "block";
    get_itm("arabia_nos").style.display = "none";
    get_itm("arabia_algebra").style.display = "none";

}

function arabia_showNos(){
    changeTitle("Arabia - Arabic Numerals");
    
    get_itm("arabia_intro").style.display = "none";
    get_itm("arabia_nos").style.display = "block";
    get_itm("arabia_algebra").style.display = "none";

}

function arabia_showAlgebra(){
    changeTitle("Arabia - Developments in Algebra");
    
    get_itm("arabia_intro").style.display = "none";
    get_itm("arabia_nos").style.display = "none";
    get_itm("arabia_algebra").style.display = "block";

}

/* Egypt */
function egypt_showIntro(){
    changeTitle("Egypt - Introduction");
    
    get_itm("egypt_intro").style.display = "block";
    get_itm("egypt_nos").style.display = "none";
    get_itm("egypt_fraction").style.display = "none";

}
function egypt_showNos(){
    changeTitle("Egypt - Ancient Egyptian Numerals");
    
    get_itm("egypt_intro").style.display = "none";
    get_itm("egypt_nos").style.display = "block";
    get_itm("egypt_fraction").style.display = "none";

}
function egypt_showFraction(){
    changeTitle("Egypt - Ancient Egyptian Fractions");
    
    get_itm("egypt_intro").style.display = "none";
    get_itm("egypt_nos").style.display = "none";
    get_itm("egypt_fraction").style.display = "block";

}

/* Greece */
function greece_showIntro(){
    changeTitle("Greece - Introduction");
    
    get_itm("greece_intro").style.display = "block";
    get_itm("greece_contrib").style.display = "none";
    get_itm("greece_elements").style.display = "none";

}
function greece_showContrib(){
    changeTitle("Greece's contribution to Mathematics");
    
    get_itm("greece_intro").style.display = "none";
    get_itm("greece_contrib").style.display = "block";
    get_itm("greece_elements").style.display = "none";

}
function greece_showElements(){
    changeTitle("Euclid's Elements");
    
    get_itm("greece_intro").style.display = "none";
    get_itm("greece_contrib").style.display = "none";
    get_itm("greece_elements").style.display = "block";

}
