	// core.js
	function core() {
		this.force_trace = true;
		this.searchInterval = false;
		this.Fields = []; //field name reference [not too clever here]
		this.ActiveFields = []; //maintain data state for inline edits	 
	}//

	core.prototype = {

		//*****************************************
		$:function() { // returns object reference || array of object references
			var loElements = new Array();
			for (var i = 0; i < arguments.length; i++) {
				var loElement = arguments[i];
				if (typeof(loElement) == 'string') {
					loElement = (document.getElementById(loElement)||false);
				}
				if (arguments.length==1) {
					return loElement;
				}
				loElements.push(loElement);
			}
			return loElements;
		},

		//*****************************************
		insertAfter:function (oInsertThisElement,oAfterThisElement) { //why is there no DOM.insertAfter?
			if(oAfterThisElement.nextSibling) {
				return (oAfterThisElement.parentNode.insertBefore(oInsertThisElement,oAfterThisElement.nextSibling));
			} else {
				return (oAfterThisElement.parentNode.appendChild(oInsertThisElement));
			}
		},
		
		//*****************************************
		repeat:function (sFunction, iTime) { //used for list filter...
			clearInterval(this.interval);
			this.interval = setInterval(sFunction, iTime); //fire whatever function
			this.remove_interval = setTimeout('core.clearRepeat('+this.interval+')',iTime); //clear after firing
			return this.interval; 
		},

		//*****************************************
		clearRepeat:function (interval) {
			if(!interval) {return;}
			trace("clearing::"+ interval);
			clearInterval(interval);
		},
		
		bigLeagueChew:function (liKey, loElement, lsPrimary, lsRelation, liPrimaryID, liRelationID, liStatusID, lsOperation, parameters) {  //When ur in the BigLeague Chew http://www.youtube.com/watch?v=0GyEkvqtHPs
			if (!lsPrimary){return;}
			if (lsOperation=='update') {
				this.YURI='/corespin/pattern_update_relation/'; //
			} else {
				this.YURI='/corespin/pattern_insert_relation/'; //
			}
			var params = (parameters)?(parameters):("");
			lsRequest='?_key='+liKey;
			lsRequest+='&_primary='+lsPrimary;
			lsRequest+='&_relation='+lsRelation;
			lsRequest+='&_primary_id='+liPrimaryID;
			lsRequest+='&_relation_id='+liRelationID;
			lsRequest+='&_status_id='+liStatusID;
			this.YURI+=lsRequest + params;
			ajaxEvent(this.YURI,loElement,false,true); //callback, replace contents, synchronous.
		},
		//*****************************************

		spacer:function (loContainer) { //returns a reference to a spacer object (used frequently in drag and drop routines as a UI trigger)
			var loSpacer = loContainer.nextSibling;
			if(loSpacer=='[object Text]') { //while?
				loSpacer = loContainer.nextSibling.nextSibling;
				if(loSpacer=='[object Text]') { //screw it
					loSpacer = loContainer.nextSibling.nextSibling.nextSibling;
				}
			} else {
				loSpacer = loContainer.nextSibling;
			}
			if (ClassFX.hasClass(loSpacer,'spacer')) {
				return loSpacer;
			}
			return false; //no spacer where in places where it should be.
		},
		
		//*****************************************
		RID:function () { //Scrappy Random ID Generator, Interstitial Dependency
			var result, i, j;
			result = '';
			for(j=0; j<32; j++) {
			if( j == 8 || j == 12|| j == 16|| j == 20)
				result = result + '-';
				i = Math.floor(Math.random()*16).toString(16).toUpperCase();
				result = result + i;
			}
			return result;
		},

		//*****************************************
		functionBroker:function () { //used for brokering function requests (development)
 			if(typeof(this[arguments[0]])=='function') {
				var loArguments = arguments[0];
				for (var a=1;a<arguments.length;a++ ) { //ditch first arg as function name, start from first argument if any.
					loArguments += ',' + arguments[a];
				}
				this[arguments[0]](loArguments);
			}
		},

		//*****************************************
		updateFileName:function (oElement) { //auto populate elements for files...
			aStore = [];
			aFields = [];
			aValues = []
			sValue = this.justStemAndExtension(oElement.value);

			aFields.push( this.$('name') );
			aStore.push('value');
			aValues.push(sValue);

			aFields.push( this.$('slug') );
			aStore.push('value');
			aValues.push(this.recordURL(sValue.toLowerCase()));

			aFields.push( this.$('meta_keywords') );
			aStore.push('value');
			aValues.push(sValue);

			aFields.push( this.$('meta_description') );
			aStore.push('value');
			aValues.push(sValue);

			aFields.push( this.$('title') );
			aStore.push('value');
			aValues.push(sValue);

			aFields.push( this.$('intro') );
			aStore.push('value');
			aValues.push(sValue);

			for (a=0;a<aFields.length;a++) { 	
				aFields[a][aStore[a]] = aValues[a];
			}
		},

		//*****************************************
		justStemAndExtension:function (lsFileName) { //filename sans path
			lsFileName=(lsFileName.substring(lsFileName.lastIndexOf('/')+1));
			lsFileName=(lsFileName.substring(lsFileName.lastIndexOf('\\')+1));
			return lsFileName;
		},

		//*****************************************
		escapeSearch:function (lsValue) { //meh.
			lsValue=lsValue.replace(/\'/g," ");
			lsValue=lsValue.replace(/\"/g," ");
  			return lsValue;
		},

		//*****************************************
		recordURL:function (lsValue) { //meh.
			if (typeof(lsValue) == 'string') {
				lsValue = lsValue.replace(/\//g,"");
				lsValue = lsValue.replace(/\s/g,"-");
				lsValue=lsValue.replace(/\'/g,"''");
				lsValue=lsValue.replace(/\"/g,"");
				lsValue = encodeRE(lsValue);
			}
			return lsValue.toLowerCase();
		},

		//*****************************************
		encodeRE:function (lsValue) {//hmmm, meh.
			lsValue=lsValue.replace(/\s/g,"");
			lsValue=lsValue.replace(/\'/g,"");
			lsValue=lsValue.replace(/\"/g,"");
  			lsValue = lsValue.replace(/[^a-zA-Z0-9\.\-\_\\]/g,'');
  			return lsValue; //.replace(/([~`@#%*^&*=!+?^${}()|[\]\/\\])/g,'');
		},
		
		//*****************************************
		updateSingleField:function (loElement,lsContext,lsID,lsField,luValue,llCallBack,sFunction) { //Single Field Edit
			if (!lsContext){return;}
			if (!lsID){return;}
			if (!lsField){return;}
			this.UpdateURI='update_single_field';
			lsRequest='?_context='+lsContext;
			lsRequest+='&_id='+lsID;
			lsRequest+='&_field='+lsField;
			lsRequest+='&_value='+PrepValue(luValue);
			this.UpdateURI+=lsRequest;
			var lsFunction='';
			var lsArguments='';
			if (loElement) {
				if(loElement.id){
				}
			}
			if(sFunction!='') {
				lsFunction = sFunction;
			}
			llQueued=false;
			ajaxEvent(this.UpdateURI,loElement,false,llQueued,lsFunction,lsArguments); //callback, replace contents, synchronous.
			return true;
		},
		
		//*****************************************
		byTag:function () { //returns object reference //still working on this one... bad use of memory, quick way to get body tag really...
			var loElements = document.getElementsByTagName(arguments[0]);
			//var loElement = loElements[0]; //mostly just want to get the first element in the list
			return loElements;
		},

		//*****************************************
		getElementsByTagAndClass:function  (sTag,sClass) { // a little faster than getElementsByClassName, limit by tag name as well
			//still working on this one...
			var oElements = document.getElementsByTagName(sTag);
			iElements = oElements.length;
			oCollection = [];
			for (var a=0; a<iElements; a++) {
				if(ClassFX.hasClass(oElements[a],sClass)) {
					oCollection.push(oElements[a]);
				}
			}
			return oCollection;
		}
		//*****************************************
		
	}
