/**
 * @author mpeccini
 */


function zoomToFull(){
	gMap.setCenter(initialExtent, initialZoom);
}

function loadSplash(){
//alert("load")
	//var splashCode='';
	//document.getElementById("splash").innerHTML=splashCode;
	document.getElementById("splash").style.display="block"	
}

function unloadSplash(){
//alert("unload")
	document.getElementById("splash").style.display="none"	
}

function loadDisplayTitle(title){
	if (!title){
		title= "All RC Projects"
	}
	document.getElementById("mapTitle").innerHTML="Map currently displaying: " + title	
}

function setTool(tool){
	activeTool = tool;
	document.getElementById("z1").style.border='1px solid black';
	document.getElementById("z2").style.border='1px solid black';
}


//converts lat long to merc and back

function rad_deg(ang) {
    return ang * (180.0/Math.PI)
}
function deg_rad(ang) {
    return ang * (Math.PI/180.0)
}
function merc_x(lon) {
    var r_major = 6378137.000;
    return r_major * deg_rad(lon);
}
function unmerc_x(lon) {
    var r_major = 6378137.000;
    return rad_deg(lon) / r_major;
}

function unmerc_y(y) {
   var r_major = 6378137.000;
    var r_minor = 6356752.3142;
    var temp = r_minor / r_major;
    var es = 1.0 - (temp * temp);
    var eccent = Math.sqrt(es);
    var eccnth = .5 * eccent;
    var ts = Math.exp(- y / r_major);
    var phi = Math.PI/2 - 2 * Math.atan(ts);
    var i = 0;
    dphi = 1;
    var M_PI_2 = Math.PI/2;
    while(Math.abs(dphi) > 0.000000001 && i < 15) {
      var con = eccent * Math.sin (phi);
      dphi = M_PI_2 - 2. * Math.atan (ts * Math.pow((1. - con) / 
                                            (1. + con), eccnth)) - phi;
      phi += dphi;
      i++;
    } 
    return rad_deg(phi); 
}
function merc_y(lat) {
    if (lat > 89.5)
        lat = 89.5;
    if (lat < -89.5)
        lat = -89.5;
    var r_major = 6378137.000;
    var r_minor = 6356752.3142;
    var temp = r_minor / r_major;
    var es = 1.0 - (temp * temp);
    var eccent = Math.sqrt(es);
    var phi = deg_rad(lat);
    var sinphi = Math.sin(phi);
    var con = eccent * sinphi;
    var com = .5 * eccent; 
    con = Math.pow(((1.0-con)/(1.0+con)), com);
    var ts = Math.tan(.5 * ((Math.PI*0.5) - phi))/con;
    var y = 0 - r_major * Math.log(ts);
    return y;
}
function merc(x,y) {
    return [merc_x(x),merc_y(y)]; 
}

//Everything after here captures the mouse position on mouse move
function setUpMouseMove(){
	if (document.layers) { // Netscape
	    document.captureEvents(Event.MOUSEMOVE);
	    document.onmousemove = captureMousePosition;
	} else if (document.all) { // Internet Explorer
	    document.onmousemove = captureMousePosition;
	} else if (document.getElementById) { // Netcsape 6
	    document.onmousemove = captureMousePosition;
	}
}

// Global variables
var xMousePos = 0; // Horizontal position of the mouse on the screen
var yMousePos = 0; // Vertical position of the mouse on the screen
var xMousePosMax = 0; // Width of the page
var yMousePosMax = 0; // Height of the page

function captureMousePosition(e) {
    if (document.layers) {
        // When the page scrolls in Netscape, the event's mouse position
        // reflects the absolute position on the screen. innerHight/Width
        // is the position from the top/left of the screen that the user is
        // looking at. pageX/YOffset is the amount that the user has
        // scrolled into the page. So the values will be in relation to
        // each other as the total offsets into the page, no matter if
        // the user has scrolled or not.
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.pageYOffset ;
		yMousePosBottom = window.pageYOffset +window.innerHeight;
		//ypageYoffset = window.pageYOffset;
    } else if (document.all) {
        // When the page scrolls in IE, the event's mouse position
        // reflects the position from the top/left of the screen the
        // user is looking at. scrollLeft/Top is the amount the user
        // has scrolled into the page. clientWidth/Height is the height/
        // width of the current page the user is looking at. So, to be
        // consistent with Netscape (above), add the scroll offsets to
        // both so we end up with an absolute value on the page, no
        // matter if the user has scrolled or not.
        xMousePos = window.event.x//+document.body.scrollLeft;
        yMousePos = window.event.y//+document.body.scrollTop;
        xMousePosMax = document.body.clientWidth//+document.body.scrollLeft;
        yMousePosMax = document.body.scrollTop;
		yMousePosBottom = document.body.scrollTop// +document.body.clientHeight;
    } else if (document.getElementById) {
        // Netscape 6 behaves the same as Netscape 4 in this regard
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.pageYOffset;
		yMousePosBottom = window.pageYOffset +window.innerHeight;
    }else{
	}
}

setUpMouseMove()






