/*
 * Michi Kono
 * michikono.com
 * Created July 22, 2006
 * Last revised: July 25, 2006
 *
 *  CleanCSS is released under the MIT license. For more information, visit michikono.com.
 *	The library is by no means complete.
 */

var CleanCSS = {
	version: 0.1,
	
	/*
	 * apply an object or value to elements all of one type of class
	 *
	 * @param	the name of the class to effect
	 * @param	the element of matching nodes that will be overwritten (such as 'onclick', 'href', etc)
	 * @param	the new value that will be assigned to the element
	 */
	byClass: function(className, elementValue, newObject) {
		document.getElementsByClassName(className).each(function(element) {
			eval('element.' + elementValue + ' = ' + newObject);
		})
		
	},
	
	/*
	 * apply an object or value to elements all of one type of tag
	 *
	 * @param	the type of tag to be effect
	 * @param	the element of matching nodes that will be overwritten (such as 'onclick', 'href', etc)
	 * @param	the new value that will be assigned to the element
	 */
	byTag: function(tagName, elementValue, newObject) {
		document.getElementsByTagName(tagName).each(function(element) {
			eval('element.' + elementValue + ' = ' + newObject);
		})
	},

	/*
	 * apply an object or value to a given ID
	 *
	 * @param	the ID to be effect
	 * @param	the element of matching nodes that will be overwritten (such as 'onclick', 'href', etc)
	 * @param	the new value that will be assigned to the element
	 */
	byID: function(idName, elementValue, newObject) {
		eval('$(\'' + idName + '\').' + elementValue + ' = ' + newObject);
	},
	
	
	/*
	 * Make any object with the class name into a CleanCSS email link. To make customized versions
	 * of this method, simply copy and modify the middle part. The # symbol is a good delimiter because
	 * browsers will not try to visit the link if Javascript is off. I chose the ID as the front part 
	 * of the because it's the part least likely to be repeated in another section of the page.
	 *
	 * @param	the name of the class to effect
	 */
	email: function(className) {
		document.getElementsByClassName(className).each(function(element) {
			element.onmouseover = function() {
				if(this.href.indexOf('mailto') == -1) { // so this replacement only fires once
					this.innerHTML = this.id + '@' + this.href.split('#').last();
					this.href = 'mailto:' + this.id + '@' + this.href.split('#').last();
				}
			};
		});
	}
}




