//-------------------------------
// * Xythe Studios *
// * Coded by Rob Kleffner (Cyborg) *
// * Started: 3/12/2010 *
// * Last updated: 4/13/2010 *
//-------------------------------
// This file contains a useful class for]
// modifying general css things. In order
// to make it easier for the JS programmers
// on Xythe.
//-------------------------------

//-------------------------------
// * CSSMod *
//-------------------------------
// This class contains various methods that make
// the modification of css code by javascript
// easier more automatic.
//-------------------------------
var CSSMod = new Object();

//-------------------------------
// * ImplementsClass(element, className) *
//-------------------------------
// Checks to see if a specified element implements
// a specified css class. Returns true if so,
// returns false if not!
//-------------------------------
CSSMod.ImplementsClass = function(element, className)
{
	var pattern = new RegExp(className);

	if (pattern.test(element.className))
	{
		return true;
	}
	
	return false;
}

//-------------------------------
// * AddClass(element, className) *
//-------------------------------
// Adds a specificied class to the list of
// css classes that modifies a certain element.
//-------------------------------
CSSMod.AddClass = function(element, className)
{
	//check to make sure that class isn't already specified
	if (!CSSMod.ImplementsClass(element, className))
	{
		//check if there aren't any other classes
		if (element.className == "")
		{
			element.className = className;
		}
		else
		{
			element.className += " " + className;
		}
	}
}

//-------------------------------
// * RemoveClass(element, className) *
//-------------------------------
// Removes the specified class from the list
// of classes that modify a specific element.
//-------------------------------
CSSMod.RemoveClass = function(element, className)
{
	var pattern = new RegExp("(^| )" + className + "( |$)");
	
	element.className = element.className.replace(pattern, "$1");
	element.className = element.className.replace(/ $/, "");
}

//-------------------------------
// * SetOpacity(element, alpha) *
//-------------------------------
// Sets the opacity property of a
// specific html element. Works
// across different browsers. Alpha
// must be a value between 1 and 0.
//-------------------------------
CSSMod.SetOpacity = function(element, alpha)
{
	element.style.opacity = alpha;
	//IE compatibility
	element.style.filter = 'alpha(opacity = ' + (alpha * 100) + ')';
}
