// Javascript DHTML Image Pan
// Sebastian Ross Oakwood Creative 2006


var clipTop = 445;
var clipWidth = 1655;
var clipBottom = 853;
var clipLeft = 1076;
var topper = -428;
var lefter = -1062;
var lyrheight = 0, lyrwidth = 0;
var time,amount,theTime,theHeight,DHTML,theLayer, isScrolling = false, _mapIsInit = false;;


function initMapScroll() {
	DHTML = (document.getElementById || document.all || document.layers);
	if (!DHTML) return;
	
	if (document.getElementById) {
		theLayer = document.getElementById("mapcontent");
	}
	else if (document.all) {
		theLayer = document.all["mapcontent"];
	}
	
	if (document.getElementById || document.all){
		lyrheight = theLayer.offsetHeight;	
		lyrwidth = (browser.indexOf("ie") > -1) ? theLayer.offsetWidth : theLayer.offsetWidth + 2057; //FF fix
	}
	_mapIsInit = true;
	centerMap();
}

/*
 * Load the big pictures. Call the rest of the map setup when picture is fully loaded 
 */
function intiMapPicture() {
	var map = new Image();
	map.onabort = onAbort;
	map.onerror = onError;
	map.onload = showMap;
	map.src = "_pict/_map/karta.gif";
	
	function showMap() {
		if (document.getElementById) {
			document.getElementById("themap").src = map.src;
			document.getElementById("loadtext").style.display = 'none';
		}
		else if (document.all) {
			document.all["themap"].src = map.src;
			document.all["loadtext"].style.display = 'none';
		}
		
		initMapScroll();
	}
	
	function onAbort() {
	  alert("Abort: Laddning av bilden avbryten.");
	}
			
	function onError() {
		alert("Error: Fel vid laddning av bilden.\n Kontakta sajtens ägare.");          
	}	
}

function centerMap() {
	theLayer.style.clip = 'rect('+clipTop+'px,'+clipWidth+'px,'+clipBottom+'px,' + clipLeft + 'px)';
	theLayer.style.top = topper + 'px';
	theLayer.style.left = lefter + 'px';
}
function mapScroll(direction,am, dist) {
	if (!_mapIsInit) return;
	if (!DHTML || !theLayer || isScrolling) return;

	theTime = (browser.indexOf("firefox") > -1) ? 40 : 30;
	var x = 0.024, inc_x;
	
	if (direction == 'up' || direction == 'down')
		inc_x = (browser.indexOf("firefox") > -1) ? 0.009 : 0.027;
	else
		inc_x = (browser.indexOf("firefox") > -1) ? 0.009 : 0.019;  
		
	
	var scrolledAmount = 0;
	
	isScrolling = true;
	
	var scrollid = window.setInterval(moveLayer,theTime)
	function moveLayer() {
		if (!DHTML) return;
		
		amount = Math.exp(-x) *10;
		
		if (am < 0)
			amount = -amount;
		
		x += inc_x;
		
		if (scrolledAmount >= dist) 
			stopScroll(scrollid);
		
		if (direction == 'up' || direction == 'down') {
			clipTop += amount;
			clipBottom += amount;
			topper -= amount;		
		}
		else {
			clipLeft += amount;
			clipWidth += amount;
			lefter -= amount;
		}
		//alert(clipTop + ":" + clipBottom + ":" + topper);
		if (clipTop < 18 || clipBottom > lyrheight) {
			clipTop -= amount;
			clipBottom -= amount;
			topper += amount;
			stopScroll(scrollid);
		}
		else if (clipLeft < 14 || clipWidth > lyrwidth) {
			clipLeft -= amount;
			clipWidth -= amount;
			lefter += amount;
			
			stopScroll(scrollid);
		}
			
		if (document.getElementById || document.all){
			clipstring = 'rect('+clipTop+'px,'+clipWidth+'px,'+clipBottom+'px,' + clipLeft + 'px)';
			theLayer.style.clip = clipstring;
			
			if (direction == 'up' || direction == 'down')
				theLayer.style.top = topper + 'px';
			else 
				theLayer.style.left = lefter + 'px';
		}
		scrolledAmount += (amount < 0) ? -amount : amount;
	}
}

function stopScroll(id) {
	isScrolling = false;
	window.clearInterval(id);
}