function showBenzin() // 1 visible, 0 hidden
{
    showLayer('carmodel_choose_gas', 0);
    showLayer('carmodel_choose_diesel', 0);
    showLayer('carmodel_choose_benzin', 1);
}

function showDiesel() // 1 visible, 0 hidden
{
    showLayer('carmodel_choose_gas', 0);
    showLayer('carmodel_choose_benzin', 0);
    showLayer('carmodel_choose_diesel', 1);
}

function showGas() // 1 visible, 0 hidden
{
    showLayer('carmodel_choose_benzin', 0);
    showLayer('carmodel_choose_diesel', 0);
    showLayer('carmodel_choose_gas', 1);
}

function showLayer(divID, iState, win) // 1 visible, 0 hidden
{
	var obj = getObj(divID, win);
	obj.style.visibility = iState ? "visible" : "hidden";
}

function showMenuLayer(divID,iState) // 1 visible, 0 hidden
{
	var obj = getObj(divID);
	//obj.style.visibility = iState ? "visible" : "hidden";
	obj.style.display = iState;
}

function writeLayer(divID, text, win)
{   win = (win) ? win : 0;
	var x = getObj(divID, win);
	x.innerHTML = '';
	x.innerHTML = text;

	showLayer(divID, 1, win);
}

function appendLayer(divID, text)
{
	var x = getObj(divID);
	x.innerHTML += text;
}

function moveLayerToCursor(divID)
{
	var layerPos = new layerPosition(divID);

	layerPos.start();
}


function getObj(name, win)
{
  var doc = (win) ? win.opener.document : document;
  if (doc.getElementById)
  {
  	return doc.getElementById(name);
  }
  else if (doc.all)
  {
	return doc.all[name];
  }
  else if (doc.layers)
  {
   	return doc.layers[name];
  }
}
//sets the layer with name = id to x, y
function setLayerPosition(id, x, y) {
	var obj = getObj(id);

	obj.style.left = x;
	obj.style.top  = y;

	//show the layer:
	showLayer(id,1);
}

//sets the layer with name = id to near the cursor
function layerPosition(id) {

	this.inheritFrom = mousePosition;
  	this.inheritFrom();

	var obj = getObj(id);
	
	var size = getSreenSize();

	doAction = function(x, y) {

	    if(x < size[0]/2) {
			obj.style.right = 30;
		} else {
		    obj.style.right = 30;
		}
		obj.style.top  = y;
	}
}

//inherit from that function and overwite the doAction method, take a look at layerPosition
function mousePosition() {
	var isIE = document.all?true:false;

	this.getMousePosition = function(e) {
		var x;
		var y;

		if (!isIE) {
			x = e.pageX;
			y = e.pageY;
		}
		if (isIE) {
			x = event.clientX + (document.body.scrollLeft);
			y = event.clientY + (document.body.scrollTop);
		}

		doAction(x, y);

		return true;
	}

	doAction = function(x, y) {
	}

	this.start = function() {

		if (!isIE) document.captureEvents(Event.MOUSEMOVE);
		document.onmousemove = this.getMousePosition;

		//and stop soon after we started to move the layer to the mouse position
		if (!isIE) {
			setTimeout("document.releaseEvents(Event.MOUSEMOVE); document.onmousemove = '';", 1000);
		}else {
            setTimeout("document.onmousemove = '';", 1);
		}
	}

	this.stop =  function() {
		if (!isIE) document.releaseEvents(Event.MOUSEMOVE);
		document.onmousemove = '';
	}
}

//returns the size of the window
function getSreenSize() {
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement &&
		( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}

	return new Array(myWidth, myHeight);
}


