mapWidth=680;
mapHeight=300;

imgWidth=1624;
imgHeight=1364;


var offsetX,offsetY,draggingThing;



function latToScale(lat,offset) {
	return (-1*((lat-90)/180))*mapHeight-offset;
}

function zoom(factor) {
	var diffWidth=imgWidth;
	imgWidth=Math.floor(imgWidth*factor);
	diffWidth-=imgWidth;

	var diffHeight=imgHeight;
	imgHeight=Math.floor(imgHeight*factor);
	diffHeight-=imgHeight;

	var emap=document.getElementById('earthMap');
	emap.style.width=imgWidth+'px';
	emap.style.height=imgHeight+'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'

	var img=document.getElementById('object1');
	img.style.top=Math.floor(65*factor)+'px'
	img.style.left=Math.floor(55*factor)+'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;
	}
}

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 nullFunc(e) {
	return false;
}
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 sizer() {
	var mt=document.getElementById('maptable').style;
	mt.height=mapHeight+"px";
	mt.width=mapWidth+"px";
	mt.clip="rect(0px "+mapHeight+"px "+mapWidth+"px 0px)";
}
function initial() {
	// sizer();
	document.getElementById('maptable').style.display="block";
}

function repeatStr(str,n) {
	var out=[];
	for (i=0;i<n;i++) {
		out.push(str);
	}
	return out.join("");
}

window.onload=initial;