/* **************	*/
/* CORE CLASSES 	*/
/* **************	*/

// ---------.---------.---------.---------.---------.---------.---------.
/* MAKE PROTOTYPE FOR EXISTING THINGS */
/* THIS WILL JOIN THE ARRAY WITHOUT NULLS */
Array.prototype.joinAndDiscardNulls = function(pJoiner) {
	var arrayTemp = this;
	var tempStr = "";
	
	/* GATHER ALL THOSE WHICH IS NOT NULL */
	for(var rx=0; rx < arrayTemp.length; rx++) {
		if(arrayTemp[rx]!=null && arrayTemp[rx]!="")
			tempStr += 
				(rx!=0 ? " " : "") +
				arrayTemp[rx];
	}
	
	return tempStr;
}


// ---------.---------.---------.---------.---------.---------.---------.
/* GET COMPUTED STYLE:  */
// http://www.robertnyman.com/2006/04/24/get-the-rendered-style-of-an-element/
function getStyle(el, prop) {
	if (document.defaultView && document.defaultView.getComputedStyle) {
		return document.defaultView.getComputedStyle(el, null)[prop];
	} else if (el.currentStyle) {
		return el.currentStyle[prop];
	} else {
		return el.style[prop];
	}
}




// ---------.---------.---------.---------.---------.---------.---------.
/* CORE FUNCTIONS */
/* SWITCHES TOGGLE BETWEEN THE TWO */
function switchToggle01 () {
	/* RECOMMENDED NAMING: swt{pName} */
	this.curSelect = null;
	this.prvSelect = null;
	
	/* SWITCHES TOGGLE TO ANOTHER OBJECT */
	this.switchTo = function (obj) {
		this.prvSelect = this.curSelect;
		this.curSelect = obj;

		/* CLEARS THE Cur CLASS */
		if(this.prvSelect) {
			/* REMOVES THE Cur CLASS */
			var classSplit = this.prvSelect.className.split(" ");
			for(var rx=0; rx<classSplit.length; rx++) {
				if(classSplit[rx]=="Cur") 
					classSplit[rx] = null;
			}
			/* MANUAL JOINING OF TEXT OR THIS WILL IMPOSE PROBLEM IN IE */
			this.prvSelect.className = classSplit.joinAndDiscardNulls(" ");
		}
		this.curSelect.className += " Cur";
	}
}

// ---------.---------.---------.---------.---------.---------.---------.
/* ADJUSTMENTS FOR IE : EVENT LISTENERS -- IE SUCKS*/
function doAddEventListener(pObj, pWhatToDo, pFunction, pT) {
	if (pObj.addEventListener){
		pObj.addEventListener(pWhatToDo, pFunction, pT); 
	} else if (pObj.attachEvent){
		pObj.attachEvent('on' + pWhatToDo, pFunction);
	}
}
function doRemoveEventListener(pObj, pWhatToDo, pFunction, pT) {
	if (pObj.removeEventListener){
		pObj.removeEventListener(pWhatToDo, pFunction, pT); 
	} else if (pObj.detachEvent){
		pObj.detachEvent('on' + pWhatToDo, pFunction);
	}
}





// ---------.--------.---------.---------.---------.---------
// FUNCTION QUEUING... LIST OF FUNCS TO BE RUN AFTER BODY HAS BEEN LOADED.
// ARRAY OF FUNCTION LISTS
var func_queue = new Array();	
// THE FUNCTION. CALL THIS AFTER THE BODY PART
function func_runQueue() {
	for(var i=0; i<func_queue.length; i++) {
		// RUN EACH FUNCTION FROM QUEUE LIST
		try {
			func_queue[i]();
		}
		catch (e) {
		}
	}
	
	// CLEAR THE FUNCTION QUEUE
	func_queue = new Array();
}
