/*
Script: jo.js[ Javascript Objects]
License: MIT-style license.
Egraffitics Copyright:copyright (c) 2008 Nikhil D, <http://www.egraffitics.com>
Credits:
	- Some functions are inspired by those found in MOOTOOLS <http://www.mootools.net/>, MIT-style license
	- Documentation by ND.
*/

var JO = {version: '0.2'};
var $extend = function(){
	var args = arguments;
	if (!args[1]) args = [this, args[0]];
	for (var property in args[1]) args[0][property] = args[1][property];
	return args[0];
};


var Abstract = function(obj){
	obj = obj || {};
	obj.extend = $extend;
	return obj;
};


var DOMElement ={
	extend: function(name,fn){
		if(!document.all){
			eval("HTMLElement.prototype." + name + " = fn");
		}else{
			//	IE doesn't allow access to HTMLElement, so we need to override document.createElement, document.getElementById, document.getElementsByTagName

			//take a copy of
			//document.createElement
			var _createElement = document.createElement;

			//override document.createElement
			document.createElement = function(tag){
				var _elem = _createElement(tag);
				eval("_elem." + name + " = fn");
				return _elem;
			};

			//take copy of document.getElementById
			//
			var _getElementById = document.getElementById;

			//override document.getElementById
			document.getElementById = function(id){	

				
				var _elem = _getElementById(id);
				if(_elem){
					eval("_elem." + name + " = fn");
					return _elem;
				}else{return false; }
			};

			//take copy of document.getElementsByTagName
			var _getElementsByTagName = document.getElementsByTagName;

			//override document.getElementsByTagName
			document.getElementsByTagName = function(tag){
				var _arr = _getElementsByTagName(tag);
				for(var _elem=0;_elem<_arr.length;_elem++){
					eval("_arr[_elem]." + name + " = fn");
				}
				return _arr;
			};
		}
	}
};

/* HTMLElement functions */
var $ = function(id){
	if(document.getElementById(id)){
		return document.getElementById(id);
	}
};
function $defined(obj){
	return (obj != undefined);
};

DOMElement.extend("whoAmI",function(){return this.id;});
DOMElement.extend("getOffsets",function(){
		var el = this, left = 0, top = 0;
		do {
			left += el.offsetLeft || 0;
			top += el.offsetTop || 0;
			el = el.offsetParent;
		} while (el);
		return {'x': left, 'y': top};
});
DOMElement.extend("getSize",function(){
		var el = this, w = 0, h = 0;
			w = el.offsetWidth || 0;
			h = el.offsetHeight || 0;
		return {'w': w, 'h': h};
});
DOMElement.extend("getCenteredOffsets",function(){
		var el = this, left = 0, top = 0;
		left = (Window.getWidth() - this.getSize().w)/2 + parseInt(Window.getXScroll());
		top = (Window.getHeight() - this.getSize().h)/2 + parseInt(Window.getYScroll());
		return {'x': left, 'y': top};
});



DOMElement.extend("about","DOMElement v0.1");


/* window functions */

var Window = new Abstract(window);
Window.extend({
	getXScroll: function(){
		var xScroll;
		if (self.pageXOffset) {
			xScroll = self.pageXOffset;
		} else if (document.documentElement && document.documentElement.scrollLeft){	 // Explorer 6 Strict
			xScroll = document.documentElement.scrollLeft;
		} else if (document.body) {// all other Explorers
			xScroll = document.body.scrollLeft;
		}
		return xScroll;
	},			  
	getYScroll: function(){
		var yScroll;
		if (self.pageYOffset) {
			yScroll = self.pageYOffset;
		} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
			yScroll = document.documentElement.scrollTop;
		} else if (document.body) {// all other Explorers
			yScroll = document.body.scrollTop;
		}
		return yScroll;
	},
	getHeight: function(){
		xheight = 0;
		if (window.innerHeight) xheight = window.innerHeight - 18;
		else if (document.documentElement && document.documentElement.clientHeight) 
			xheight = document.documentElement.clientHeight;
		else if (document.body && document.body.clientHeight) 
			xheight = document.body.clientHeight;
		return xheight;
	},
	getWidth: function(){
		xwidth = 0;
		if (window.innerWidth) xwidth = window.innerWidth - 18;
		else if (document.documentElement && document.documentElement.clientWidth) 
			xwidth = document.documentElement.clientWidth;
		else if (document.body && document.body.clientWidth) 
			xwidth = document.body.clientWidth;
		return xwidth;
	}
});

/* Document functions */
var Document = new Abstract(document);
Document.extend({
	getHeight: function(){
		doc = this;
			var docHt = 0, sh, oh;
			if (doc.height) docHt = doc.height;
			else if (doc.body) {
				if (doc.body.scrollHeight) docHt = sh = doc.body.scrollHeight;
				if (doc.body.offsetHeight) docHt = oh = doc.body.offsetHeight;
				if (sh && oh) docHt = Math.max(sh, oh);
			}
		 return docHt;
	}
});




/*
function setIframeHeight(iframeName) {
  var iframeWin = window.frames[iframeName];
  var iframeEl = document.getElementById? document.getElementById(iframeName): document.all? document.all[iframeName]: null;
  if ( iframeEl && iframeWin ){
    iframeEl.style.height = "auto"; // helps resize (for some) if new doc shorter than previous  
    var docHt = getDocHeight(iframeWin.document);
    // need to add to height to be sure it will all show
    if (docHt) iframeEl.style.height = docHt + "px";
  }
}
*/




/* DOM Functions */

/** Node CSS-Class Manipulation Functions */
function hasClass(ele,cls){return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));}
function addClass(ele,cls){if(!this.hasClass(ele,cls)){ ele.className += " "+cls;}}
function replaceClass(ele,cls){if(!this.hasClass(ele,cls)){ ele.className = cls;}}
function removeClass(ele,cls){
	if(hasClass(ele,cls)){
	var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
	ele.className=ele.className.replace(reg,' ');}
}

function show(id){if($(id))$(id).style.display="block";}
function hide(id){if($(id))$(id).style.display="none";}

/**Native Elements */
String.prototype.trim=function(str) {
  str = this != window? this : str;
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

Array.prototype.removeItem=function(str) {
  	for(i=0; i<this.length ; i++){
	  if(escape(this[i]).match(escape(str.trim()))){
		  	this.splice(i, 1);  break;
		  }
	}
  return this;
}

/* Common Scripts for TCLASS only */

function clearMessage(){transitAlert('msg'); window.setTimeout("hide('msg')",10000);}
/* Transitional Error */
var countr = 00; 
var countg = 255; 
var countb = 255; 

var count =255;
function transitAlert(msgarea){
	countr =countr-3; 
	countg =countg+1; 	
	countb =countb-1;	
	count= count-5;
	//status= "rgb("+countr+","+ countg + "," + countb +")";
	//document.getElementById(msgarea).style.backgroundColor = "rgb("+countr+","+ countg + "," + countb +")";
	document.getElementById(msgarea).style.color = "rgb("+count+","+count + "," + count+")";	
	if (countr <= 0){
	 	Id = eval('window.setTimeout("transitAlert(\''+ msgarea +'\')",50)'); 
	}
} 
