



//////////////////////////////////////////////////////////////////
//FILE LOAD INDICATOR! DO NOT REMOVE
//////////////////////////////////////////////////////////////////
$iTXT.js.loader["$iTXT.core.Util"] = true;
//////////////////////////////////////////////////////////////////


//Loader Function
$iTXT.core.Util_Load = function(){
	
	//Speed up access to undefined
	var undefined;


	
    
    $iTXT.core.Util = 
	{
		
		
		args: function(args)
		{
			var rA = [];
			for (var i=0; i<args.length;i++)
			{
				rA[i] = args[i];
			}
			return rA;
		},
		
		
		extend: function(dest, src)
		{
			for (var p in src)
			{
			    if (undefined != src[p])
			    {
				dest[p] = src[p];
			}
			}
			return dest;
		},
		
		
        		
		isElement: function(object) 
		{
			return !!(object && object.nodeType == 1);
		},
		
        
        isFunc: function(object)
		{
            return typeof object === "function";
        },
        
        
        isArray: function(object)
		{
            return this.getClass(object) === "Array";
        },
		
 		
        isString: function(object)
		{
            return this.getClass(object) === "String";
        },		
        
		
 		
        isNumber: function(object)
		{
            return this.getClass(object) === "Number";
        },	
		
		
        isObject: function(object)
		{
            return this.getClass(object) === "Object";
        },	
        		
		
        isUndefined: function(object)
		{
            return typeof object === undefined;
        },
		
		
        
        getClass: function(object)
		{
            return Object.prototype.toString.call(object).match(/^\[object\s(.*)\]$/)[1];
        },
        
        
        dropScript: function(src)
        {
            if('string'!=typeof src||!src.match(/^http/)){return;}
            try
            {
                var e=document.createElement('script');
                e.src=src;
                e.type='text/javascript';
                var b=document.getElementsByTagName('body')[0];
                b.insertBefore(e, b.firstChild);
            }
            catch (e)
            {                
            }
        },
        
        
        getQueryParams: function(srcUrl)
        {
            //If the url does not have a query string, return an empty object
            if (srcUrl.indexOf('?')==-1)
            {
                return {};
            }    
            var params = {};
            //Get the query string
            var qs = srcUrl.substring(srcUrl.indexOf('?')+1);    
            //get an array of the key=value pairs
            var pairs = qs.split('&');
            for (var i=0;i<pairs.length;i++)
            {
                //split the keypair into its key and value
                var keyPair = pairs[i].split('=');
                if (keyPair.length==2)
                {
                    //If there is a key and a value add to return object
                    params[keyPair[0]] = unescape(keyPair[1]);
                }
            }    
            //return the parameter object
            return params;            
        },
        
        
        getScriptBySrc: function(srcUrl)
        {
            var scripts = document.getElementsByTagName("script");
            for (var i=0;i<scripts.length;i++)
            {
                var s = scripts[i];
                if (s.src.indexOf(srcUrl)!=-1)
                {
                    return s;         
                }
            }               
        }      
    }
}







//////////////////////////////////////////////////////////////////
// FILE LOAD INDICATOR! DO NOT REMOVE
//////////////////////////////////////////////////////////////////
$iTXT.js.loader["$iTXT.core.Builder"] = true;
//////////////////////////////////////////////////////////////////

//Loader Function
$iTXT.core.Builder_Load = function(){
	
	//Speed up access to undefined
	var undefined;


	
    
    $iTXT.core.Builder = 
	{
		NODEMAP: {
	    AREA: 'map',
	    CAPTION: 'table',
	    COL: 'table',
	    COLGROUP: 'table',
	    LEGEND: 'fieldset',
	    OPTGROUP: 'select',
	    OPTION: 'select',
	    PARAM: 'object',
	    TBODY: 'table',
	    TD: 'table',
	    TFOOT: 'table',
	    TH: 'table',
	    THEAD: 'table',
	    TR: 'table'
	  	},
  	
		
		make: function(tagName, attributes, children)
		{
			var tagName = tagName.toUpperCase();
			
			var parentTagName = this.NODEMAP[tagName] || 'div';
			var parentTag = document.createElement(parentTagName);
			try {
				parentTag.innerHTML = "<" + tagName + "></" + tagName + ">";
			} catch (e) {}
			//get the first child of the parent tag, i.e. the element
			var element = parentTag.firstChild || null;
			
			//check to make sure element was not wrapped
			if(element && (element.tagName.toUpperCase() != tagName))
      			element = element.getElementsByTagName(tagName)[0];
				
			//if all failed, try a normal createelement approach
			if (!element) element = document.createElement(tagName);
			
			//if still failed, bomb out
			if (!element) return;
			
			if (attributes)
			{
				var attrs = this._attributes(attributes);               
                if (attrs.length) {
                    try {
                        parentTag.innerHTML = "<" + tagName + " " + attrs + "></" + tagName + ">";
                    } 
                    catch (e) {
                    }
                    element = parentTag.firstChild || null;
                    // workaround firefox 1.0.X bug
                    if (!element) {
                        element = document.createElement(tagName);
                        for (attr in attributes) 
                            element[attr] = attributes[attr];
                    }
                    if (element.tagName.toUpperCase() != tagName) 
                        element = parentTag.getElementsByTagName(tagName)[0];
                }
			}
			
			if (children)
			{
				this._children(element, children);
			}
			
			return $iTXT.core.$(element);
		},
		
		//is string or number tester
		_isSorN: function(param)
		{
			return $iTXT.core.Util.isString(param) || $iTXT.core.Util.isNumber(param);
		},
		
		//add array of child elements to an element
		_children: function(element, children) 
		{
			for (var i=0;i<children.length;i++)
			{
				if (this._isSorN(children[i])) 
				{
					element.appendChild(document.createTextNode(children[i]));
				}
				else
				{
					element.appendChild(children[i]);
				}
			}		      
		},
 
 		//return the attributes as an html string.
		_attributes: function(attributes) 
		{
			var attrs = [];
			for(attribute in attributes)
			{
				var an = (attribute=="className") ? "class" : attribute;
		  		attrs.push(an + '="' + attributes[attribute] + '"');
			}
			return attrs.join(" ");
		}
    }
}








//////////////////////////////////////////////////////////////////
//FILE LOAD INDICATOR! DO NOT REMOVE
//////////////////////////////////////////////////////////////////
$iTXT.js.loader["$iTXT.core.Class"] = true;
//////////////////////////////////////////////////////////////////


//Loader Function
$iTXT.core.Class_Load = function(){
	
	//Speed up access to undefined
	var undefined;


	
    
    $iTXT.core.Class = 
	{
		
		create: function()
		{
			//set parent to null
			var parent = null;
			//set properties to first argument
			var properties = arguments[0];
			//If first argument is a function
			//then it is a super class to inherit from
			if ($iTXT.core.Util.isFunc(properties))
			{
				//set parent to first argument
				parent = properties;
				//set properties to second argument
				properties = arguments[1];
			}
			
			//define the return function for 
			//creating the object prototype
			function _newClass()
			{
				this.init.apply(this, arguments);
			}
			
			//if the parent is not null, then 
			//copy the new classes prototype
			//from the parent
			if (null != parent)
			{
				//copy the parent prototype
				//base on prototypejs method
				//to get over recursion errors with 
				//inheritance
				var parentClass = function() {};
				parentClass.prototype = parent.prototype
				_newClass.prototype = new parentClass;
			}
			
			//add all methods from properties to the
			//newClass prototype
			for (p in properties)
			{
				//call _addProperty to add the property 
				//to the _newClass prototype
				this._addProperty(_newClass, p, properties[p], parent);
			}
			
			//return the _newClass function.
			return _newClass;
		},
		
		
		_addProperty: function(_class, _property, _value, _parent)
		{
			//If the property value is a function, and it also occurs in the
			//classes super class, then add a special wrapper to pass the 
			//superclass function as the final argument
			if ($iTXT.core.Util.isFunc(_value) && _parent && undefined != _parent.prototype[_property])
			{
				//store old function value
				var _oldValue = _value;
				//define new function value
				_value = function()
				{
					//get the class instance from the current
					//function
					var _instance = this;
					//convert the arguments into an array
					var _newArgs = $iTXT.core.Util.args(arguments);
					//define the superclass function
					var _super = function()
					{
						//apply the superclasses method
						_parent.prototype[_property].apply(_instance, arguments);
					}
					//add the superclass function to the arguments array
					_newArgs.push(_super)
					//apply the original function, with the new arguments
					_oldValue.apply(this, _newArgs);
				}
			}
			//set the classes prototype property
			_class.prototype[_property] = _value;
		}
		
		
	}
}






//////////////////////////////////////////////////////////////////
//FILE LOAD INDICATOR! DO NOT REMOVE
//////////////////////////////////////////////////////////////////
$iTXT.js.loader["$iTXT.core.Dom"] = true;
//////////////////////////////////////////////////////////////////


//Loader Function
$iTXT.core.Dom_Load = function(){
	
	//Speed up access to undefined
	var undefined;


	
    
    $iTXT.core.$ = function(elmt, dontExt)
	{    	
    	
		if ($iTXT.core.Util.isString(elmt))
		{
			elmt = document.getElementById(elmt);
		}
		
		if (!elmt)
    		return null;
		
				
		if (dontExt || (elmt.itxt && elmt.itxt.domExtended))
		{
			return elmt;
		}
		else
		{
			elmt = $iTXT.core.Util.extend(elmt, $iTXT.core.Dom);
			//set the domExtended flag.
			//this needs to be in an itxt object
			//incase the innerHTML string of the elements parent is used
			//as that would keep a top level parameter as an attribute in the
			//string, but it does not convert objects in the same way
			elmt.itxt = {};
			elmt.itxt.domExtended = true;
			return elmt;
		}		
    }
	
	
	$iTXT.core.Dom = 
	{
		//variable to indicate the html element has been extended
		iTXTDOMExtended: true, 
			
		
	
		
		//hash for storing intellitxt events on
		//the object
		iTXTEvents: {},
		
		//Event methods
		itxtFire: function(type, data)
		{
			$iTXT.core.Event.fire(this, type, data);
			return this;
		},
		
		itxtSubscribe: function(type, handler)
		{
			$iTXT.core.Event.subscribe(this, type, handler);
			return this;
		},
		
		itxtUnSubscribe: function(type, handler)
		{
			$iTXT.core.Event.unsubscribe(this, type, handler);
			return this;
		},
		
		
		itxtAddClass: function(addClass, removeClass)
		{
			if (this.className) 
			{
				var cNs = this.className.split(' ');
				var newCNs = [];
				
				for (var i=0;i<cNs.length;i++)
				{
					var cn = cNs[i];
					if (cn!=removeClass && cn!=addClass)
					{
						newCNs.push(cn);
					}
				}
				newCNs.push(addClass);
				this.className = newCNs.join(' ');
			}
			else
			{
				this.className = addClass;	
			}
			return this;
		},
		
		
		itxtSetStyle: function(styles)
		{				
			if ($iTXT.core.Util.isString(styles))
			{
				return this.style.cssText += ";" + styles;
			}
			for (s in styles)
			{
				this.style[s] = styles[s];
			}
			
			return this;
		},
		
		itxtSetAttribute: function(atts)
		{
		    for (attribute in atts)
		    {		      		   
		        this[attribute] = atts[attribute];
		    }
		}
	
	}
	
	
	
}







//////////////////////////////////////////////////////////////////
//FILE LOAD INDICATOR! DO NOT REMOVE
//////////////////////////////////////////////////////////////////
$iTXT.js.loader["$iTXT.core.Event"] = true;
//////////////////////////////////////////////////////////////////


//Loader Function
$iTXT.core.Event_Load = function(){
	
	//Speed up access to undefined
	var undefined;


	
    
    $iTXT.core.Event = 
	{
	
		bind: function(source, name)
		{
			return function()
			{
				name.apply(source, arguments);
			}
		},		
		
		nsUID: 0,
		
		subscribe: function(elmt, type, handler)
		{
			//extend the element
			elmt = $iTXT.core.$(elmt);
			
			var eventName = type;
			var eventUID = type;
			if (type.indexOf('.')!=-1)
			{
				var splt = type.split('.');
				eventName = splt.pop();
			}
			else
			{
				eventUID = "evt" + this.nsUID++ + "." + eventName;
			}
			
			var custom = eventName.charAt(0)=='$';
				
			if (custom)
			{
			}
			else
			{
				if (elmt.addEventListener)
					elmt.addEventListener(eventName, handler, false);
				else if (elmt.attachEvent)
					elmt.attachEvent("on" + eventName, handler);
			}
			
			this._addEvt(elmt, eventName, eventUID, handler);
			
		},
		
		_addEvt: function(elmt, eventName, eventUID, handler)
		{
			var handlers = elmt.iTXTEvents[eventName] || {};
			handlers[eventUID] = handler;
			elmt.iTXTEvents[eventName] = handlers;
		},
		
		_removeEvt: function(elmt, eventName, eventUID)
		{
			var handlers = elmt.iTXTEvents[eventName] || {};
			var newHandlers = {};
			for (handler in handlers)
			{
				if (handler!=eventUID)
				{
					newHandlers[handler] = handlers[handler];
				}
			}
			elmt.iTXTEvents[eventName] = newHandlers;
		},
		
		unsubscribe: function(elmt, eventUID, handler)
		{
			//extend the element
			elmt = $iTXT.core.$(elmt);
			
			var eventName = eventUID;
			if (eventUID.indexOf('.')!=-1)
			{
				var splt = eventUID.split('.');
				eventName = splt.pop();
			}
			
			var custom = eventName.charAt(0)=='$';
			
			this._removeEvt(elmt, eventName, eventUID);
		},
		
		fire: function(elmt, eventName, data)
		{
			elmt = $iTXT.core.$(elmt);
			var custom = eventName.charAt(0)=='$';
			var handlers = elmt.iTXTEvents[eventName] || {};
			var event = {
					data: data || {}
			}
			for (handler in handlers)
			{
				handlers[handler].apply(elmt, [event]);
			}
		}
	
    }
}





