/*
Plugin Name: WP-Klapp
*/

// Klapptext Functions

function wpKlappToggle(kid, me, txth, txts) {
	if (HasClassName(me,'active')) {
		kid.style.display = 'none';
		me.innerHTML = txth;
		RemoveClassName (me, 'active');
	} else {
		kid.style.display = 'block';
		me.innerHTML = txts;
		AddClassName (me, 'active', true);
	}
}

// Klapptext Functions - Class Handling

function HasClassName(objElement, strClass)
{
	if ( objElement.className )
	{
		var arrList = objElement.className.split(' ');
		var strClassUpper = strClass.toUpperCase();
		for ( var i = 0; i < arrList.length; i++ )
		{
			if ( arrList[i].toUpperCase() == strClassUpper )
			{
				return true;
			}
		}
	}
	return false;
}

function AddClassName(objElement, strClass, blnMayAlreadyExist)
{
	if ( objElement.className )
	{
		var arrList = objElement.className.split(' ');
		if ( blnMayAlreadyExist )
		{
			var strClassUpper = strClass.toUpperCase();
			for ( var i = 0; i < arrList.length; i++ )
			{
				if ( arrList[i].toUpperCase() == strClassUpper )
				{
					arrList.splice(i, 1);
					i--;
				}
			}
		}
		arrList[arrList.length] = strClass;
		// add the new class to beginning of list
		//arrList.splice(0, 0, strClass);
		objElement.className = arrList.join(' ');
	}
	else
	{
	objElement.className = strClass;
	}
}

function RemoveClassName(objElement, strClass)
{
	if ( objElement.className )
	{
		var arrList = objElement.className.split(' ');
		var strClassUpper = strClass.toUpperCase();
		for ( var i = 0; i < arrList.length; i++ )
		{
			if ( arrList[i].toUpperCase() == strClassUpper )
			{
				arrList.splice(i, 1);
				i--;
			}
		}
		objElement.className = arrList.join(' ');
	}
}


