//SW: Koordinaten
function oCoord(x,y) {
	if(arguments.length==3) {
		var mapName= arguments[2];
		this.x= parseInt(x*refCoordSystem.width/aMaps[mapName].width);
		this.y= parseInt(y*refCoordSystem.height/aMaps[mapName].height);
	} else {
		this.x= x;
		this.y= y;
	}

	this.convertToMap= function(mapName) {
		return new oCoord( parseInt(this.x*aMaps[mapName].width/refCoordSystem.width), parseInt(this.y*aMaps[mapName]/refCoordSystem.height) );
	}
}

//SW: Gauss-Krüger Koordinaten
function oGkCoord(degree,minutes,seconds) {

	this.value= degree*3600+minutes*60+seconds;
	
	this.getDegree= function() {
		return parseInt(this.value/3600);
	}
	this.getMinutes= function() {
		return parseInt((this.value%3600)/60);
	}
	this.getSeconds= function() {
		return parseInt(this.value%60);
	}

	this.getGkCoord= function() {
		return this.getDegree()+"°"+this.getMinutes()+"'"+this.getSeconds()+"\"";
	}
}

//SW: eine Karte
function oCitymap(width, height, offsetX, offsetY, imagePrefix, imagePostfix, widthPiece, heightPiece, measureWidth, measureText, imageXStartNum, imageYStartNum) {
	this.width= width;
	this.height= height;
	this.offsetX= offsetX;
	this.offsetY= offsetY;

	this.imagePrefix= imagePrefix;
	this.imagePostfix= imagePostfix;
	this.widthPiece= widthPiece;
	this.heightPiece= heightPiece;
	
	//SW: Schnelle Lösung, muss durch Berechnung aus Koordinaten noch ersetzt werden
	this.measureWidth= measureWidth;
	this.measureText= measureText;
	
	this.imageXStartNum= imageXStartNum;
	this.imageYStartNum= imageYStartNum;
	
	
	this.getPositionInGk= function(Coord) {
		var gkCoord= new oCoord(new oGkCoord(0,0,0), new oGkCoord(0,0,0));
		gkCoord.x.value= parseInt( (Coord.x/this.width)*(refCoordSystem.gkRight.value-refCoordSystem.gkLeft.value)+refCoordSystem.gkLeft.value ); 
		gkCoord.y.value= parseInt( (Coord.y/this.height)*(refCoordSystem.gkBottom.value-refCoordSystem.gkTop.value)+refCoordSystem.gkTop.value );
		
		return gkCoord;
	}
}

var oSmoothScrolling= {
	startPos:new oCoord(0,0),
	endPos:new oCoord(0,0),
	diffX:0,
	diffY:0,
	handler:"",
	counter:0,
	init:function(startPos, endPos) {

		if(oSmoothScrolling.handler=="") {
			oSmoothScrolling.startPos.x= startPos.x;
			oSmoothScrolling.startPos.y= startPos.y;
			oSmoothScrolling.endPos.x= endPos.x;
			oSmoothScrolling.endPos.y= endPos.y;
			oSmoothScrolling.counter= 0.0;
			oSmoothScrolling.handler= window.setInterval("oSmoothScrolling.move()", 50);
			oSmoothScrolling.diffX= oSmoothScrolling.endPos.x-oSmoothScrolling.startPos.x;
			oSmoothScrolling.diffY= oSmoothScrolling.endPos.y-oSmoothScrolling.startPos.y;
		}
	},
	move:function() {
		
		var tSin= Math.sin(2*Math.PI*oSmoothScrolling.counter/360.0);
		actPos.x= parseInt(oSmoothScrolling.startPos.x+tSin*oSmoothScrolling.diffX);
		actPos.y= parseInt(oSmoothScrolling.startPos.y+tSin*oSmoothScrolling.diffY);
		
//		if(this.counter==20) {
//	 		alert('startPos.x: '+oSmoothScrolling.startPos.x+'endPos.x: '+oSmoothScrolling.endPos.x+" Math.ceil: "+Math.ceil(oSmoothScrolling.startPos.x+tSin*oSmoothScrolling.diffX));
//	 	}
				// alert('startPos.x: '+this.startPos.x+' diffX: '+diffX+' counter: '+this.counter+" actPos.x:"+actPos.x);
		oSmoothScrolling.counter+=2;
		if(oSmoothScrolling.counter>90) {
			window.clearInterval(oSmoothScrolling.handler);
			oSmoothScrolling.handler= "";
			zoomerPos= new oCoord(oSmoothScrolling.endPos.x, oSmoothScrolling.endPos.y);
	 		updateMarker();
		}
		drawMap();

	}
};
