// Mobile class (Mobile base)
// Fixes shortcomings of IE mobile 4 (based on IE4.5)
// V 0.1
// Copyright: Derek den Haas

function Mobile()
{
	// -- variables
	this.width = 0;
	this.height = 0;
	this.resizes = new Array();
	
	// -- functions
	this.initiate = initiate;
	this.addResize = addResize;
	
	function initiate()
	{
		// Screen can't be larger than 320px (else you can just visit the normal page)
		this.width = screen.width > 320 ? 320 : screen.width;
		this.height = screen.height > 320 ? 320 : screen.height;
		
		this.width = 240;
		this.height = 320;
		
		this.fullWidth = this.width - 30;
		this.fullHeight = this.height - 140;
		
		// Resize things:
		for(var x in this.resizes)
		{
			var object = document.getElementById(this.resizes[x].object);
			
			// Border box model (joepie!)
			if(this.resizes[x].width)
				object.style.width = this.fullWidth * (this.resizes[x].width / 100) - this.resizes[x].border + "px";
			
			if(this.resizes[x].height)
				object.style.height = (this.fullHeight * (this.resizes[x].height / 100) - this.resizes[x].border) + "px";
		}
	}
	
	function addResize(object, widthPercentage, heightPercentage, border)
	{
		border = border > 0 ? border : 0;
		this.resizes.push({"object" : object, "width" : widthPercentage, "height" : heightPercentage, "border" : border});
	}
}

// Navigator class (Mobile Navigator)
// V 0.1
// Copyright: Derek den Haas
function Navigator(latitude, longitude, object)
{
	this.latitude = latitude;
	this.longitude = longitude;
	this.zoom = 14;
	this.tableObject = object;
	
	this.key = "";
	this.maptype = "";
	this.markers = "";
	
	// -- Declare functions
	this.goUp = goUp;
	this.goDown = goDown;
	this.goLeft = goLeft;
	this.goRight = goRight;
	
	this.zoomIn = zoomIn;
	this.zoomOut = zoomOut;
	
	this.initiate = initiate;
	this.redraw = redraw;
	
	
	function initiate()
	{
		this.tableObject = document.getElementById(this.tableObject);
		this.redraw();
	}
	
	function goUp()
	{
		this.latitude += 20 / Math.pow(2,this.zoom - 1);
		this.redraw();
	}
	function goDown()
	{
		this.latitude -= 20 / Math.pow(2,this.zoom - 1);
		this.redraw();
	}
	function goLeft()
	{
		this.longitude -= 20 / Math.pow(2,this.zoom - 2);
		this.redraw();
	}
	function goRight()
	{
		this.longitude += 20 / Math.pow(2,this.zoom - 2);
		this.redraw();
	}
	function zoomIn()
	{
		this.zoom = this.zoom < 17 ? this.zoom + 1 : 17;
		this.redraw();
	}
	function zoomOut()
	{
		this.zoom = this.zoom > 1 ? this.zoom - 1 : 1;
		this.redraw();
	}
	
	function redraw()
	{
		this.tableObject.style.backgroundImage = "url(http://maps.google.com/staticmap?center="+this.latitude+","+this.longitude+"&key="+this.key+"&size="+mob.fullWidth+"x"+mob.fullHeight+"&zoom="+this.zoom+"&maptype="+this.maptype+"&markers="+this.markers+")";
		//this.tableObject.style.backgroundImage = "url(getmap.php?lat="+this.latitude+"&lng="+this.longitude+"&width="+mob.fullWidth+"&height="+mob.fullHeight+"&zoom="+this.zoom+")";
	}
}
var mob = new Mobile();

mob.addResize("table_navigator", 100, 100);
mob.addResize("table_zoom", 100, 0);
mob.addResize("zoom_in", 50, 0, 4);
mob.addResize("zoom_out", 50, 0, 4);

window.onload = function()
{
	mob.initiate();
	navi.initiate();
}
