var button_div = function()
{
	var id, left, top, width, height, backDown, backUp;
	var isPlaying;
	var new_obj;
	
	var pressed = false;
	
	var me = null;
	var callback = null;
	
	this.start = function( node )
	{
		isPlaying = false;
		me = this;
		
		id = node.getAttribute('id');
		left = parseInt(node.getAttribute('left'));
		top = parseInt(node.getAttribute('top'));
		width = parseInt(node.getAttribute('width'));
		height = parseInt(node.getAttribute('height'));
		backDown = node.getAttribute('back_down');
		backUp = node.getAttribute('back_up');
		
		if( backUp != "" )
		{
			var preload = new Image();
			if( backDown != "" )
				preload.onload = me.loadDown;
			else
				preload.onload = makeNextObject;
			preload.src = backUp;
		}
		else makeNextObject();
	}
	
	this.loadDown = function()
	{
		var preload = new Image();
		preload.onload = makeNextObject;
		preload.src = backDown;
	}
	
	this.makeStyle = function( node )
	{
		node.style.top = top + "px";
		node.style.left = left + "px";
		node.style.width = width + "px";
		node.style.height = height + "px";
		if( backUp != "" )
			node.style.background = "url('" + backUp + "')";
		node.style.position = "absolute";
		node.style.backgroundRepeat = "no-repeat";
	}
	
	this.setCallBack = function( cb )
	{
		callback = cb;
	}
	
	this.getId = function()
	{
		return id;
	}
	
	this.getPressed = function()
	{
		return pressed;
	}
	
	this.setPressed = function(state)
	{
		pressed = state;
		if( state )
		{
			if( backDown == "" )
				new_obj.style.background = "";
			else
				new_obj.style.background = "url('" + backDown + "')";
		}
		else
		{
			if( backUp == "" )
				new_obj.style.background = "";
			else
				new_obj.style.background = "url('" + backUp + "')";
		}
	}

	this.play = function( parent )
	{	
		if( isPlaying == false )
		{
			new_obj = document.createElement("div");

			new_obj.setAttribute("id", id);

			this.makeStyle( new_obj );
			
			new_obj.style.cursor = "pointer";
			new_obj.onclick = function()
			{
				if( pressed )
				{
					pressed = false;
					if( backUp == "" )
						new_obj.style.background = "";
					else
						new_obj.style.background = "url('" + backUp + "')";
				}
				else
				{
					pressed = true;
					if( backDown == "" )
						new_obj.style.background = "";
					else
						new_obj.style.background = "url('" + backDown + "')";
				}
				
				if( callback != null )
					callback( me );
			}

			parent.appendChild(new_obj);

			if( parent == document.getElementById('map_contained') )redimMapContained( left, top, width, height );

			isPlaying = true;
		}
	}
	
	this.stop = function()
	{
		if( isPlaying == true )
		{
			new_obj.parentNode.removeChild( new_obj );
			isPlaying = false;
		}
	}
}