/*
    Scrolling the MAP
*/
var oldfn = window.onload;
if(typeof window.onload != 'function')
{
	window.onload = loadMap;
} else {
	window.onload = function()
	{
		oldfn();
		loadMap();
	};
}
function loadMap(){
    document.body.onmouseup = function(){mouseup(event, this);}
    loadedFlag = true;
}
// initial setup
loadedFlag = false;

clickposx = 0;
clickposy = 0;

scrollstartleft = 0;
scrollstarttop = 0;

ismousedown = false;

maxleft = 0;
maxtop = 0;

function setClickPos(event, targetDiv) {

clickposx = event.screenX;
clickposy = event.screenY;

scrollstartleft = parseInt(targetDiv.style.left);
scrollstarttop = parseInt(targetDiv.style.top);

var framingDiv = document.getElementById("map");

maxleft = parseInt(targetDiv.style.width) - parseInt(framingDiv.style.width);
maxtop = parseInt(targetDiv.style.height) - parseInt(framingDiv.style.height);

ismousedown = true;
}

function mouseup(event, target) {

ismousedown = false;
}

function moveTarget(event, target) {

if (ismousedown == true) {
  var newposx = event.screenX;
  var newposy = event.screenY;
  
  var difx = newposx - clickposx;
  var dify = newposy - clickposy;

  var newleft = scrollstartleft + difx;
  if (newleft > 0) { newleft = 0; }
  if (newleft < (0 - maxleft)) { newleft = (0 - maxleft); }

  var newtop = scrollstarttop + dify;
  if (newtop > 0) { newtop = 0; }
  if (newtop < (0 - maxtop)) { newtop = (0 - maxtop); }

  moveToPosition(target, newleft, newtop);
}
}
function moveToPosition(target, x, y) {
    target.style.left = "" + x + "px";
    target.style.top = "" + y + "px";
}
function moveTo(x,y)
{
    var map = document.getElementById("scrolling-section");
    map.style.left = "" + x + "px";
    map.style.top = "" + y + "px";
}