// JavaScript Document
// Credit: codelifter.com
// Mouse position script: http://www.codelifter.com/main/javascript/capturemouseposition1.html


function getContents(city) {
	
	switch(city) {
		
		case "Charlotte": return "<b>Charlotte</b><br>9307-O Monroe Rd.<br>Charlotte, NC 28270<br>Ph: 704-844-0483<br>Fax: 704-272-7098"; 	
		case "Peachland": return "<b>Peachland</b><br>895 E Passiac St.<br>Peachland, NC 28133-8056<br>Ph: 704-272-7068<br>Fax: 704-272-7098"; 
		case "Troy": return "<b>Troy</b><br>219 North Main St.<br>Troy, NC 27371-3015<br>Ph: 910-572-1268<br>Fax: 910-572-1378"; 
		case "Greenville": return "<b>Greenville</b><br>2602 Courtier Dr.<br>Greenville, NC 27858-7818<br>Ph: 252-355-4725<br>Fax: 252-355-0444"; 
		case "Rocky Mount": return "<b>Rocky Mount</b><br>1600 W. Thomas St.<br>Rocky Mount, NC 27804-4337<br>Ph: 252-442-1359<br>Fax: 252-442-5095"; 
		case "Kinston": return "<b>Kinston</b><br>518 Plaza Blvd, Ste 300<br>Kinston, NC 28501-1635<br>Ph: 252-525-4404<br>Fax: 252-208-1120"; 
		case "Fayetteville": return "<b>Fayetteville</b><br>321 Dick St., Ste 104<br>Fayetteville, NC 28301<br>Ph: 910-339-2844<br>Fax: 910-399-2845"; 
		case "Kenansville": return "<b>Kenansville</b><br>Main St. Ste 4<br>Kenansville, NC 28349<br>Ph: 910-296-6244<br>Fax: 910-296-6246"; 
		case "Elizabeth City": return "<b>Elizabeth City</b><br>102 A Medical Dr.<br>Elizabeth City, NC 27909<br>Ph: TBD<br>Fax: TBD"; 
	}
}

function getContainerPos(city) {
	
	var mc=document.getElementById("mapContainer"); 
	var mp=new Array(0,0);
	
	
	
	switch(city) {
		case "Greenville": mp[0]=444; mp[1]=78; break;	
	}
	
	return mp;
}


// Main function to retrieve mouse x-y pos.s
function getMouseXY(e) { 	
	
  if (IE) { // grab the x-y pos.s if browser is IE
 
 	 tempY = event.clientY
	 tempX = event.clientX
 
  	if (document.documentElement && document.documentElement.scrollTop)
		tempY += document.documentElement.scrollTop
	if (document.body && document.body.scrollTop)
    	tempY += document.body.scrollTop
		
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  

  return true; 
}

function killCurrDiv() {
	if (currDiv) {
		document.body.removeChild(currDiv); 
	}	
	currDiv=null;
}

function showMap(city,posX,posY) {
	
	if (currDiv) {
		document.body.removeChild(currDiv); 
	}
	
	rig=tempX;
	bot=tempY;
	
	di = document.createElement("div"); 
    di.style.position="absolute"; 
	
	if (posX!=0 && posY!=0) {
		di.style.left=posX+"px";
		di.style.top=posY+"px"; 
	}
	else {
  		di.style.left=rig-296+"px"; 
    	di.style.top=bot-145+"px";
	}
   
    di.style.width="296px";
    di.style.height="145px"; 
	di.style.className="overlaydiv"; 
    di.style.zIndex=5;
	di.style.backgroundImage="url('/images/overlay_box.png')"; 
	di.style.backgroundPosition="top left"; 
	di.style.backgroundRepeat="no-repeat"; 
	di.innerHTML="<div style='padding:20px;'>"+getContents(city)+"</div>";
	
	currDiv=di; 
	document.body.appendChild(di);
	
}

var currDiv=null;
var tempX = 0
var tempY = 0

var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;
document.onmousedown = killCurrDiv;
