/*
	DOMAss: http://www.robertnyman.com/domass
	This module by Robert Nyman, http://www.robertnyman.com
*/
DOMAss.initCSS = function (){
	this.addCSSMethods();
};

DOMAss.addCSSMethods = function (){
	if(typeof HTMLElement == "function"){		
		HTMLElement.prototype.addClass = this.addClass;
		HTMLElement.prototype.removeClass = this.removeClass;
		HTMLElement.prototype.hasClass = this.hasClass;
		HTMLElement.prototype.getStyle = this.getStyle;
	}
	this.methodsToAdd.push(["addClass", this.addClass]);
	this.methodsToAdd.push(["removeClass", this.removeClass]);
	this.methodsToAdd.push(["hasClass", this.hasClass]);
	this.methodsToAdd.push(["getStyle", this.getStyle]);
};

DOMAss.addClass = function (className){
	var currentClass = this.className;
	if(!new RegExp(className, "i").test(currentClass)){
		this.className = currentClass + ((currentClass.length > 0)? " " : "") + className;
	}
	return this.className;
};

DOMAss.removeClass = function (className){
	var classToRemove = new RegExp((className + "\s?"), "i");
	this.className = this.className.replace(classToRemove, "").replace(/^\s?|\s?$/g, "");
	return this.className;
},

DOMAss.hasClass = function (className){
	return new RegExp(("(^|\\s)" + className + "(\\s|$)"), "i").test(this.className);
};

DOMAss.getStyle = function (cssRule){
	var cssVal = "";
	if(document.defaultView && document.defaultView.getComputedStyle){
		cssVal = document.defaultView.getComputedStyle(this, "").getPropertyValue(cssRule);
	}
	else if(this.currentStyle){
		cssVal = cssRule.replace(/\-(\w)/g, function (match, p1){
			return p1.toUpperCase();
		});
		cssVal = this.currentStyle[cssVal];
	}
	return cssVal;
};

DOMAss.initCSS();
