

function setSize(e, w, h)
{
    e.style.width = Math.floor(w) + "px";
    e.style.height = Math.floor(h) + "px";	
}

function setPosition(e, px, py)
{
    e.style.left = Math.floor(px) + "px";
    e.style.top = Math.floor(py) + "px";    
}

function setZIndex(e, z)
{
    e.style.zIndex = z;
}		

function getWidth(e) { return $(e).width(); }
		
function getHeight(e) { return $(e).height(); }
	


var Asteroid = function(domName, baseWidth, baseHeight, initphase, freq, orbitx, orbity, depthx, depthy)
{
	this._dom = document.getElementById(domName);
	this._baseWidth = baseWidth;
	this._baseHeight = baseHeight;
	this._phase = initphase;
	this._freq = freq;
	this._orbitx = orbitx;
	this._orbity = orbity;
	this._depthx = depthx;
	this._depthy = depthy;
	this._src1 = 'img/' + domName + '.png';
	this._src2 = 'img/' + domName + '_hilight.png';
	this._hilighted = false;
	
	this._dist = 1.0 + this._depthx * Math.cos(this._phase) + this._depthy * Math.sin(this._phase);
	this._oldDist = this._dist;
	if (this._phase < Math.PI) 
	    setZIndex(this._dom, 4);
	    
	if (this._phase > Math.PI) 
	    setZIndex(this._dom, 6);
	    
};

Asteroid.prototype = {
    

	progress : function (dt, bx, by)
	{
		this._phase = this._phase + dt * Math.PI * 2.0 * this._freq;			
		if (this._phase > Math.PI * 2.0) 
		{
    		this._phase -= Math.PI * 2.0;
		}
		
		var dom = this._dom;
		
		this._oldDist = this._dist;
		this._dist = 1.0 + this._depthx * Math.cos(this._phase) + this._depthy * Math.sin(this._phase);
		var w = this._baseWidth / this._dist;
		var h = this._baseHeight / this._dist;
		
		if ((this._dist <= 1.0) && (this._oldDist > 1.0)) 
		    setZIndex(dom, 6);			
		if ((this._dist > 1.0) && (this._oldDist <= 1.0)) 
		    setZIndex(dom, 4);
		
		setSize(dom, w / this._dist, h / this._dist); 
		
		this._posx = bx + (this._orbitx * Math.cos(this._phase) / this._dist);
		this._posy = by + (this._orbity * Math.sin(this._phase) / this._dist);
		
		setPosition(dom, this._posx - w * 0.5 / this._dist, this._posy - h * 0.5 / this._dist);
	}
};


var Icon = function(n)
{
    this._dom = document.getElementById("icon_" + n);
};

Icon.prototype = {

    setPos : function(x, y)    
    {
        setPosition(this._dom, x - 30, y - 30);
    }
};
