function getWidth() {
	winWidth=800;
	var	d=document;
	if (typeof window.innerWidth!='undefined') {
		var winWidth = window.innerWidth;
	} else {
		if (d.documentElement && 
				typeof d.documentElement.clientWidth!='undefined' && 
				d.documentElement.clientWidth!=0) {
			var winWidth = d.documentElement.clientWidth;
		} else {
			if (d.body && 
					typeof d.body.clientWidth!='undefined') {
				var winWidth = d.body.clientWidth;
			}
		}
	}
	return winWidth;
}

mapWidth=255;//getWidth()-25;
mapHeight=Math.floor(255);
function zoom(factor) {
	var diffWidth=mapWidth;
	mapWidth=Math.floor(mapWidth*factor);
	diffWidth-=mapWidth;
	var diffHeight=mapHeight;
	mapHeight=Math.floor(mapHeight*factor);
	diffHeight-=mapHeight;
	var emap=document.getElementById('earthMap');
	emap.style.width=mapWidth+'px';
	emap.style.height=mapHeight+'px';
	var img=document.getElementById('mover');
	img.style.top=(img.offsetTop+Math.floor(diffHeight/2))+'px'
	img.style.left=(img.offsetLeft+Math.floor(diffWidth/2))+'px'
}

function zoomOut() {
	zoom(1/1.2);
}

function zoomIn() {
	zoom(1.2);
}


function getDragParent(el) {
	var oldEl=el;
	while (el) {
		el=el.parentNode;
		if (el.id=="maptable" || el.nodeName.toUpperCase()=='BODY') {
			return oldEl;
		}
		oldEl=el;
	}
}

var offsetX,offsetY,draggingThing;
function startDrag(e) {
	draggingThing=getDragParent(e.srcElement || e.target); 
	offsetX=e.clientX-draggingThing.offsetLeft;
	offsetY=e.clientY-draggingThing.offsetTop;
	document.body.onmousemove=moveDrag;
	document.body.onmouseup=endDrag;
	document.onselectstart=nullFunc;
}

function moveDrag(e) {
	e=e || event;
	if (draggingThing) {
		draggingThing.style.top=(e.clientY-offsetY)+'px';
		draggingThing.style.left=(e.clientX-offsetX)+'px';
		return true;
	}
}
function endDrag(e) {
	draggingThing=null;
	document.body.onmousemove=null;
	document.body.onmouseend=null;
	document.onselectstart=null;
}

function movePan(direction) {
		draggingThing = document.getElementById('mover');
		divtop = parseInt(draggingThing.style.top,10);
		divleft = parseInt(draggingThing.style.left,10);
		if(direction == "U")
			draggingThing.style.top=(divtop - 20)+'px';
		if(direction == "D")
			draggingThing.style.top=(divtop + 20)+'px';	
		if(direction == "L")
			draggingThing.style.left=(divleft - 20)+'px';
		if(direction == "R")
			draggingThing.style.left=(divleft + 20)+'px';			
}
function nullFunc(e) {
	return false;
}
