/****************************************************/
// Javascript Framer
// @copyright Fonqi, 13. may 2009
/****************************************************/

if(typeof Base != "function")
	throw("Base.js must be included before Framer.js!");
	
Framer.prototype.CornerWidth = "";
Framer.prototype.CornerHeight = "";
Framer.prototype.CornerBGColor = "";
Framer.prototype.Corner1Img = "";
Framer.prototype.Corner2Img = "";
Framer.prototype.Corner3Img = "";
Framer.prototype.Corner4Img = "";
Framer.prototype.Identifier = "";
Framer.prototype.Offset = "0";
Framer.prototype.Frames = [];

function Framer(){}

Framer.prototype.Frame = function()
{
	this.LoadImages();
	var useImages = !this.IsBGColorSet();
	if(this.Identifier == "")
		this.Identifier = "fBordered";
	
	for(i = 0; i < this.Frames.length; i++)
	{
		var currentFrame = this.Frames[i];
		
		if(currentFrame.className.indexOf(this.Identifier) >= 0)
		{
			currentFrame.style.zIndex = "0";
			currentFrame.style.float = "left";
			currentFrame.style.position = "relative";
			
			var corner1;
			if(!useImages)
			{
				corner1 = this.CreateCorner("div");
				corner1.style.backgroundColor = this.CornerBGColor;
			}
			else
			{
				corner1 = this.CreateCorner("img");
				corner1.src = this.Corner1Img;
				corner1.alt = this.Corner1Img;
			}
			corner1.style.top = this.Offset;
			corner1.style.left = this.Offset;        
			currentFrame.appendChild(corner1);
			
			var corner2;
			if(!useImages)
			{
				corner2 = this.CreateCorner("div");
				corner2.style.backgroundColor = this.CornerBGColor;
			}
			else
			{
				corner2 = this.CreateCorner("img");
				corner2.src = this.Corner2Img;
				corner2.alt = this.Corner2Img;
			}
			corner2.style.top = this.Offset;
			corner2.style.right = this.Offset;        
			currentFrame.appendChild(corner2);
			
			var corner3;
			if(!useImages)
			{
				corner3 = this.CreateCorner("div");
				corner3.style.backgroundColor = this.CornerBGColor;
			}
			else
			{
				corner3 = this.CreateCorner("img");
				corner3.src = this.Corner3Img;
				corner3.alt = this.Corner3Img;
			}
			corner3.style.bottom = this.Offset;
			corner3.style.right = this.Offset;        
			currentFrame.appendChild(corner3);
			
			var corner4;               
			if(!useImages)
			{
				corner4 = this.CreateCorner("div");
				corner4.style.backgroundColor = this.CornerBGColor;
			}
			else
			{
				corner4 = this.CreateCorner("img");
				corner4.src = this.Corner4Img;
				corner4.alt = this.Corner4Img;            
			}
			corner4.style.bottom = this.Offset;
			corner4.style.left = this.Offset;
			currentFrame.appendChild(corner4);       
		}
	}
}

Framer.prototype.LoadImages = function()
{
	var frames = Base.Get("."+this.Identifier);	
	for(i = 0; i < frames.length; i++)
	{
		this.Frames.push(frames[i]);	
	}
}

Framer.prototype.IsBGColorSet = function()
{
    if(this.CornerBGColor.indexOf('#')>-1)
        return true;   
    else
        return false
}

Framer.prototype.CreateCorner = function(type)
{
	var tempCorner = document.createElement(type);
	tempCorner.style.width = this.CornerWidth;
	tempCorner.style.zIndex = "100";
	tempCorner.style.height = this.CornerHeight;
	tempCorner.style.backgroundRepeat = "no-repeat"
	tempCorner.style.position = "absolute";
	tempCorner.style.border = "none";
	return tempCorner;	
}

Framer.Create = function()
{
	return new Framer();
}

/****************************************************/