
//--------------------------------------------------------------------------------------------------------------------

Background.prototype = new Layer();
Background.prototype.constructor = Background;
Background.superclass = Layer.prototype;

function Background(id, image, sizeOfScreen)
{
	//alert("Background::Constructor");
	var elem = document.createElement("div");
	var attr_Id = document.createAttribute("id");
	attr_Id.value = id;
	elem.setAttributeNode(attr_Id);	
	var attr_Style = document.createAttribute("style");
	attr_Style.value = "position:absolute; visibility: hidden";
	elem.setAttributeNode(attr_Style);
	var attr_Align = document.createAttribute("align");
	attr_Align.value = "center";
	elem.setAttributeNode(attr_Align);
	elem.innerHTML = "<img id=\"BackgroundImage\">";
	document.body.appendChild(elem);
	
	this.SetId(id);	
	this._object = elem; //document.getElementById(this.GetId());
	this._imgObj = document.getElementById("BackgroundImage");
	this._image = null;
	this._sizeOfScreen = sizeOfScreen;
	this._keepRatio = false;
		
	this.SetImage(image);
}

//____ Functions_____
Background.prototype.SetKeepRatio = function(keep)
{
	this._keepRatio = keep;
}

Background.prototype.SetImage = function(image)
{	
	if (image == null)
	{
		alert(this.GetId() + ": SetImage: Background image null");
		return;
	}
	
	this._image = image;	
	this._imgObj.src = image.src;
	
	this.SetWidth(image.width);	
	this.SetHeight(image.height);
	this.SetZIndex(1);
}

Background.prototype.OnResize = function()
{
	this._imgObj.style.width = (self.innerWidth * this._sizeOfScreen) + "px";
	
	if (this._keepRatio)
		this._imgObj.style.height = (images[imageIndex].image.height/images[imageIndex].image.width * this._imgObj.style.width) + "px";
	else
		this._imgObj.style.height = (self.innerHeight * this._sizeOfScreen) + "px";
	
	this.SetWidth(this._imgObj.style.width);
	this.SetHeight(this._imgObj.style.height);
	this.Center();
	this.CenterVert();
}
