/*
	Asmor's Graphics Engine v0.1
	Copyright 2006 Ian Toltz
	http://www.asmor.com
	itoltz@gmail.com
*/

AGEVersion=0.1

//This will be incremented each time a new element is created, to ensure unique names.
currentElementId=0

//Will serve as parent to all divs
//Div won't "exist" unless something's inside it. A space doesn't work, so I used a <br>
document.write("<div id='topDiv'><br></div>")

function _setContents(newContents) {
	this.contents=newContents
	this.refresh()
}

function _refresh() {
	document.getElementById(this.elementId).innerHTML = this.topWrapper + this.contents + this.bottomWrapper
}


function _show() {
	document.getElementById(this.elementId).style.visibility="visible"
}

function _hide() {
	document.getElementById(this.elementId).style.visibility="hidden"
}

function _putAt(x, y) {
	this.x=x
	this.y=y
	document.getElementById(this.elementId).style.top=y
	document.getElementById(this.elementId).style.left=x
}

function _setX(x) {
	this.x=x
	this.putAt(x, this.y)
}

function _setY(y) {
	this.y=y
	this.putAt(this.x, y)
}

function _setStyle(att, style) {
	eval("document.getElementById(this.elementId).style."+att+"=\""+style+"\"")
}

function _setTopWrapper(bleh) {
	this.topWrapper=bleh
	this.refresh()
}

function _setBottomWrapper(bleh) {
	this.bottomWrapper=bleh
	this.refresh()
}


function AGEElement() {
	this.elementId="AGE"+currentElementId
	currentElementId++
	this.x=0
	this.y=0
	this.topWrapper=""
	this.bottomWrapper=""
	this.contents=""

	this.hide=_hide
	this.putAt=_putAt
	this.refresh=_refresh
	this.setBottomWrapper=_setBottomWrapper
	this.setContents=_setContents
	this.setStyle=_setStyle
	this.setTopWrapper=_setTopWrapper
	this.setX=_setX
	this.setY=_setY
	this.show=_show

	newDiv=document.createElement('div')
	newDiv.setAttribute('id', this.elementId)
	parent=document.getElementById("topDiv")
	parent.appendChild(newDiv)
	newDiv.style.position="absolute"
	newDiv.style.top=this.y
	newDiv.style.left=this.x

	//Start off with it hidden
	this.hide()
}