/*

	# -------------------------------------------------------------------------------------------- #
	#																			#
	# DC.Layer.class.js																#
	#																			#
	# DC.Layer Class																#
	# Copyright 2011 Thommy Morgan													#
	# All Rights Reserved															#
	#																			#
	# -------------------------------------------------------------------------------------------- #
	
		
*/



/*
# ----------------------------------------------------------------------------- #
# DC.Layer class constructor										 	#
# ----------------------------------------------------------------------------- #*/


DC.Layer = function(returnObject) {

	this.obj = new Object();

	this.superClass = DC.Object;
	this.superClass();

	var isTag = false;

	var validTags = 
	[
		"html", "head", "body",
		"script", "link", "base",
		"div", "button", "img", 
		"a", "span", "em", "strong", "u", "b", 
		"table", "tr", "td", "th",  
		"h1", "h2", "h3", "h4", "h5", "h6", 
		"iframe", "frame", 
		"form", "input", "select", "option", "textarea" 
	];

	if(!returnObject) {
		this.obj = document.createElement("div");
		isTag= true;
	}
	else
	if(typeof returnObject == "string") {
		var temp = returnObject.toLowerCase();
		for(var i = 0; i < validTags.length; i++) if(temp == validTags[i]) isTag = true;
		if(isTag == true) this.obj = document.createElement(temp);
	}
	
	if(isTag == false) {
		this.obj = $(returnObject);
		if(typeof this.obj != "object") this.obj = document.createElement("div");
	}
	
	// Deliminator constants
	this.animationCoefficient = 16;
	this.graceCoefficient= 5;
	this.delegate = null;
	this.obj.topLayer = this;
		
}
DC.Layer.prototype = new DC.Object;


DC.Layer.prototype.setDelegate = function(returnObject) {
	this.delegate = returnObject;
}


DC.Layer.prototype.reset = function(keepidentifiers) {
	this.setHTML("");
	if(!keepidentifiers) {
		this.setID(null);
		this.setName(null);
		this.setClass(null);
	}
}


/* ------------------------------------------------------------- */
/* Set object information 								*/
/* ------------------------------------------------------------- */


DC.Layer.prototype.setID = function(id) {
	this.obj.setID(id);
}


DC.Layer.prototype.setClass = function(cls) {
	this.obj.setClass(cls);
}


DC.Layer.prototype.setName = function(nm) {
	this.obj.setName(nm);
}


DC.Layer.prototype.setType = function(type) {
	this.obj.setType(type);
}


DC.Layer.prototype.setValue = function(val) {
	this.obj.setValue(val);
}


/* -------------------------------------------------------- */
/* Request object information							*/
/* -------------------------------------------------------- */


DC.Layer.prototype.getID = function() {
	return this.obj.getID();
}


DC.Layer.prototype.getClass = function() {
	return this.obj.getClass();
}


DC.Layer.prototype.getName = function() {
	return this.obj.getName();
}


DC.Layer.prototype.getType = function() {
	return this.obj.getType();
}


DC.Layer.prototype.getValue = function() {
	return this.obj.getValue();
}


/* -------------------------------------------------------- */
/* Accomodate For Styling 							*/
/* -------------------------------------------------------- */


DC.Layer.prototype.setAttribute = function(attr, val) {
	this.obj.setAttribute(attr, val);
}


DC.Layer.prototype.removeAttribute = function(attr) {
	this.obj.removeAttribute(attr);
}


DC.Layer.prototype.getAttribute = function(attr) {
	return this.obj.getAttribute(attr);
}


DC.Layer.prototype.getStyle = function(attr) {
	this.obj.getStyle(attr);
}


DC.Layer.prototype.setStyle = function(attr, val) {
	this.obj.setStyle(attr, val);
}


/* -------------------------------------------------------- */
/* Event handling		 							*/
/* -------------------------------------------------------- */


DC.Layer.prototype.addEventTo = function(type, func, capture) {
	this.obj.addEventTo(type, func, capture);
}


DC.Layer.prototype.removeEventFrom = function(type, func, capture) {
	this.obj.removeEventFrom(type, func, capture);
}


/* -------------------------------------------------------- */
/* Accomodate For Styling 							*/
/* -------------------------------------------------------- */


DC.Layer.prototype.setHTML = function(html) {
	this.obj.innerHTML = html;
}


/* -------------------------------------------------------- */
/* Request style information 							*/
/* -------------------------------------------------------- */


DC.Layer.prototype.getAttr = function(attribute) {
	return this.obj.getAttr(attribute);
}


DC.Layer.prototype.getHTML = function(html) {
	return this.obj.innerHTML.toString();
}


DC.Layer.prototype.getWidth = function() {
	return this.obj.getWidth();
}


DC.Layer.prototype.getHeight = function() {
	return this.obj.getHeight();
}


DC.Layer.prototype.getLeft = function() {
	return this.obj.getLeft();
}


DC.Layer.prototype.getTop = function() {
	return this.obj.getTop();
}


/* -------------------------------------------------------- */
/* Animation functions								*/
/* -------------------------------------------------------- */


DC.Layer.prototype.anchorExact = function() {
	this.moveTo(this.getLeft(), this.getTop());
}


DC.Layer.prototype.makeAbsolute = function() {
	this.setStyle("position", "absolute");
}


DC.Layer.prototype.makeRelative = function() {
	this.setStyle("position", "relative");
}


DC.Layer.prototype.moveToX = function(x) {
	this.obj.moveToX(x);
}


DC.Layer.prototype.moveToY = function(y) {
	this.obj.moveToY(y);
}


DC.Layer.prototype.moveTo = function(x, y) {
	this.moveToX(x);
	this.moveToY(y);
}


DC.Layer.prototype.setWidth = function(w) {
	this.obj.setWidth(w);
}


DC.Layer.prototype.setHeight = function(h) {
	this.obj.setHeight(h);
}


DC.Layer.prototype.setSize = function(w, h) {
	this.obj.setSize(w, h);
}


DC.Layer.prototype.setOpacity = function(alpha) {
	this.obj.setOpacity(alpha);
}


/* -------------------------------------------------------- */
/* Parent-Child Functions For Object Class				*/
/* -------------------------------------------------------- */


// Accomodate for layers
Object.prototype.addChild = function(child, index) {
	if(!index) {
		if(child.obj) this.appendChild(child.obj);
		else this.appendChild(child);
	}
	else
	if(typeof index == "number") {
		if(child.obj)
			this.insertBefore(child.obj, this.children[index]);
		else
		this.insertBefore(child, this.children[index]);
	}
	else
	if(typeof index == "object") {
		if(child.obj) {
			if(index.obj)
			this.insertBefore(child.obj, index.obj);
			else
			this.insertBefore(child.obj, index);
		}
		else {
			if(index.obj)
			this.insertBefore(child, index.obj);
			else
			this.insertBefore(child, index);
		}
	}
	else
	return false;
}


Object.prototype.dropChild = function(child) {
	if(child.obj) 	this.removeChild(child.obj);
	else 		this.removeChild(child);
}


Object.prototype.killself = function() {
	tryout( function() { this.offsetParent.dropChild(this); });
}


/* -------------------------------------------------------- */
/* Parent-Child Functions For DC.Layer Class				*/
/* -------------------------------------------------------- */


DC.Layer.prototype.children = function() {
	return this.obj.children;
}


DC.Layer.prototype.numberOfChildren = function() {
	return this.obj.children.length;	
}


DC.Layer.prototype.addChild = function(child, index) {
	if(!index)
	this.obj.addChild(child);
	else
	this.obj.addChild(child, index);
}


DC.Layer.prototype.dropChild = function(child) {
	this.obj.dropChild(child);
}


DC.Layer.prototype.killself = function() {
	this.obj.killself();
}
