//create Lib v2
function domMan() //class
{
}


function attObj()
	{
		this.attName = "";
		this.attValue = "";
	}
/*---------------------------------------------
--PRE-APPEND - FUNCTIONS DEALING WITH PRE-APPEND OPERATIONS
----------------------------------------------*/
	function addEl(whatElement, parentId, thisId, unFoAttAr)
	{
		/*creates an element and adds it to the page*/
		if(unFoAttAr && thisId !== "") unFoAttAr.push('id:'+thisId); //add id to att list because it was passed in differently
		else if(thisId && thisId !== "") {
			unFoAttAr = new Array('id:'+thisId);
		}
		
		if(unFoAttAr) var foAtts = makeAttAr(unFoAttAr); //used to get name from, and insertBefore/after attributes
		
		var useRegular = true;
		//ALL BECAUSE IE WONT APPEND A NAME ATTRIBUTE
		if(navigator.appName == "Microsoft Internet Explorer" && unFoAttAr && whatElement=="input")
		{
			useRegular = false;
			var nameVar = "";
			var i = 0;
			while(i < foAtts.length)
			{
				if(foAtts[i].attName == "name") {
					nameVar = foAtts[i].attValue;
					//alert(nameVar);
					break;
				}
				i++;
			}
			if(nameVar !== "") window[thisId] = document.createElement("<"+whatElement+" name='"+nameVar+"'>");
			//var nameVar = "it";
			///*if(nameVar !== "")*/ window[thisId] = document.createElement("<"+whatElement+" name=''>"); 
			else useRegular = true;
		}
		
		//alert(useRegular);
		if(useRegular == true) window[thisId] = document.createElement(whatElement); //1 line for all other browsers
		var curNode = window[thisId];
		
		if(unFoAttAr)
			addAttSet(curNode, unFoAttAr);
			
		if(curNode.fadeIn > 0) {
		curNode.style.opacity = 0;
		curNode.style.filter = "alpha(opacity=0)";
		curNode.curOpacity = 0;
		}
		
		//add it to the document (either before a specified element or at the end)
		var insertId = parentId;
		var beforeAfterId = "";
		var i = 0;
		if(unFoAttAr){ //check if the attribute array was passed in
			while(i < foAtts.length) //search for the insertBefore/After attributes
			{
				if(foAtts[i].attName == "insertBefore" || foAtts[i].attName == "insertAfter") {
					beforeAfterId = foAtts[i].attValue;
					//alert(beforeAfterId);
					break;
				}
				i++;
			}
		}
		if(beforeAfterId != "")
		{
			var oldChild = document.getElementById(beforeAfterId);
			//alert(oldChild);
			oldChild.parentNode.insertBefore(curNode, oldChild); //insert before the oldChild
		}
		else document.getElementById(parentId).appendChild(curNode);
		//end adding it to the document

		if( eval(curNode.fadeIn) > 0) 
		{
			window[thisId+'fade'] = setInterval(function() { increaseOpacity(thisId)}, curNode.fadeIn);
		}
	}
	
	//var fadeIntervalArray = new Array();
	//var thefade;
	function fadeIn(id, speed)
	{
		window[id+'fade'] = setInterval(function() { increaseOpacity(id)}, speed); //i hate internet explorer
		//fadeIntervalArray.push( setInterval(function() { increaseOpacity(id)}, speed) ); //i hate internet explorer
		//window[id+'fade'] = setInterval(increaseOpacity, speed, id);
		//thefade = setInterval(increaseOpacity, speed, id);
	}
	
	function increaseOpacity(id)
	{
		var thelogo = document.getElementById(id);
		if( document.getElementById(id) )
		{
			thelogo.curOpacity+=.03;
			if(thelogo.curOpacity >= 1) 
			{
				window.clearInterval(window[id+'fade']);
				//delete window[id+'fade'];
				//alert('intervalCleared');
				//clearIntervalArray(fadeIntervalArray);
				//window.clearInterval(thefade);
				//window.clearInterval(window.fadeId);
			}
			
			var mozLevel = thelogo.curOpacity;
			var ieLevel = (thelogo.curOpacity)*100; //300 instead of 100 because IE is sloooowwwww
			//alert(ieLevel);
			
			if(ieLevel <= 100) {thelogo.style.filter = "alpha(opacity="+ieLevel+")";}
			thelogo.style.opacity = mozLevel;
		}
		/*else 
		{
			//window.clearInterval(window.fadeId);
			window.clearInterval(window[id+'fade']);
			//clearIntervalArray(fadeIntervalArray);
		}*/
	}
	
	/*function clearIntervalArray(array)
	{
		var i = 0;
		while(i < array.length)
		{
			//alert('interval array cleared');
			clearInterval(array[i]);
			i++;
		}
	}*/
	
	function addTagGroup(whatElement, parentId, thisId, labelAr, unFoAttAr)
	{
		if(labelAr && document.getElementById(parentId))
		{
			var i = 0;
			while(i < labelAr.length)
			{
				if(unFoAttAr) var curUnFoAttAr = unFoAttAr.slice(0);
				else var curUnFoAttAr = new Array();
				curUnFoAttAr.push('text:'+labelAr[i]);
				
				addEl(whatElement, parentId, [thisId+i], curUnFoAttAr);
				i++;
			}
		}
	}
	
	//ADD ALL ATTRIBUTES TO THE NODE
	function addAttSet(curElNode, unFoAttAr)
	{
		/*adds a set of attributes to a NODE*/
		if(unFoAttAr){
		var foAr = makeAttAr(unFoAttAr);
		var i = 0;
		var curAttName;
		var curAttValue;
		var labelText;
		while(i < foAr.length)
		{
			curAttName = foAr[i].attName;
			curAttValue = foAr[i].attValue;
			if(curAttName == "text")
			{
				labelText = document.createTextNode(curAttValue);
				curElNode.appendChild(labelText);	
			}
			else if(curAttName == "fadeIn")
			{
				curElNode.fadeIn = curAttValue;	
				//addOneAtt(curElNode, "style", "width: 100%");
			}
			else addOneAtt(curElNode, curAttName, curAttValue);
			i++;
		}}
	}
	
	function addOneAtt(curElNode, att, attVal)
	{
		/*adds an attribute to a NODE or ELEMENT*/
		if(att == "onclick" || att == "onClick") curElNode.setAttribute("onclick",attVal);
		
		var added = false;
		if(att == "class") curElNode.setAttribute("className", attVal);
		else if(att == "onclick" || att == "onClick"){ curElNode.onclick = Function(attVal);
		added = true;}
		else if(att == "onblur"){ curElNode.onblur = Function(attVal);
		added = true;}
		else if(att == "onchange") {curElNode.onchange = Function(attVal);
		added = true;}
		else if(att == "onfocus") {curElNode.onfocus = Function(attVal);
		added = true;}
		else if(att == "onunfocus"){ curElNode.onunfocus = Function(attVal);
		added = true;}
		else if(att == "onmouseover"){ curElNode.onmouseover = Function(attVal);
		added = true;}
		else if(att == "onmouseout"){ curElNode.onmouseout = Function(attVal);
		added = true;}
		if(attVal !== "" && added == false) curElNode.setAttribute(att, attVal);
		
		//alert(att + " " + attVal);
		
	}	
	
	function makeAttAr(unFoAttAr)
	{
		/*Splices up the paramter array passed in and puts it in a more complex but simpler form.. hmm*/
		var attAr = new Array();
		var i = 0;
		while(i < unFoAttAr.length)
		{
			var curPa = unFoAttAr[i];
			var curAtt = new attObj();
			
			var curIndex = curPa.indexOf(':');
			
			curAtt.attName = curPa.substring(0, curIndex);
			curAtt.attValue = curPa.substring(curIndex+1, curPa.length);
			
			attAr.push(curAtt);
			i++;
		}
		
		return attAr;
	}
	
	//parentId - where to put the radio set
	//thisId - the base id to use, 1, 2, 3, etc.. will be appended to it
	//valueAr - array of values that will be attached to each radio respectively -order matters - determines the number of elements
	//labelAr - array of labels that will be created to go sidebyside with its corresponding radio -order matters
	
	function addRadioGroup(parentId, thisId, valueAr, labelAr, unFoAttAr)
	{
		if(unFoAttAr)
			unFoAttAr.push('type:radio'); //need the implied radio type to be set
		
		addGroup(parentId, thisId, valueAr, labelAr, unFoAttAr);
	}
	
	function addCheckboxGroup(parentId, thisId, valueAr, labelAr, unFoAttAr)
	{
		if(unFoAttAr)
			unFoAttAr.push('type:checkbox'); //need the implied radio type to be set
		
		addGroup(parentId, thisId, valueAr, labelAr, unFoAttAr);
	}
	
	function addGroup(parentId, thisId, valueAr, labelAr, unFoAttAr)
	{
		var i = 0;
		while(i < valueAr.length)
		{
			if(unFoAttAr) var curUnFoAttAr = unFoAttAr.slice(0); //create a new att ar because each will be different
			else var curUnFoAttAr = new Array();	
			
			curUnFoAttAr.push('value:'+valueAr[i]); //add the specific value to each att ar
			addEl('label', parentId, ['label'+thisId+i], ['for:'+thisId+i, 'text:'+labelAr[i]]); //add label with specific for attribute
			addEl('input', parentId, [thisId+i], unFoAttAr);
			i++;
		}	
	}
	
	function addOptionGroup(selectId, thisId, valueAr, labelAr, unFoAttAr)
	{
		var i = 0;
		while(i < valueAr.length)
		{
			var curUnFoAttAr = unFoAttAr.slice(0);
			curUnFoAttAr.push('value:'+valueAr[i]);
			curUnFoAttAr.push('text:'+labelAr[i]);
			addEl('option', selectId, [thisId+i], curUnFoAttAr);
			i++;
		}
	}
	
	
/*-------------------------------------------
END OF FUNCTIONS DEALING WITH PRE-APPEND OPERATIONS*/
/*---------------------------------------------*/
	
	
	
/*---------------------------------------------
--POST-APPEND - FUNCTIONS DEALING WITH POST-APPEND OPERATIONS
----------------------------------------------*/
	function removeElementById(elId)
	{
		var didRemove = true;
		if( document.getElementById(elId) )
		{
			idToDelete = document.getElementById(elId);
			idToDelete.parentNode.removeChild(idToDelete);
		} else didRemove = false;
		
		return didRemove;
	}
	
	function removeInsidesById(elId)
	{
		var didRemove = true;
		if( document.getElementById(elId) )
		{
			
			var idToClear = document.getElementById(elId);
			
			var container = idToClear.cloneNode(false);	
			idToClear.parentNode.insertBefore(container, idToClear);
			idToClear.parentNode.removeChild(idToClear);
		} else didRemove = false;
		
		return didRemove;
	}
	
	function addAttributes(elId, unFoAttAr)
	{
		var curEl = document.getElementById(elId);
		
		addAttSet(curEl, unFoAttAr);
		if(eval(curEl.fadeIn) > 0)
		{
			curEl.style.opacity = 0;
			curEl.style.filter = "alpha(opacity=0)";
			curEl.curOpacity = 0;
			window[elId+'fade'] = setInterval(function() { increaseOpacity(elId)}, curEl.fadeIn);
		}
		//if(curEl.fadeIn > 0) setInterval(fadeIn, curEl.fadeIn, [elId]);
	}
	
	/*Not in use right now*/
	/*
	function minimizeId(elId, curIndex)
	{
		var curId = document.getElementById(elId);
		var totalIndex = curId.childNodes.length;
		if(!curIndex) var curIndex = totalIndex-1;
		else curIndex--;
		
		if (curIndex == -1) {
			//curId.style.display = "none";
			//alert("switching to minIdH");
			minimizeIdHeight(elId, 50);
		}
		else if (curId.childNodes[curIndex].style && curId.childNodes[curIndex].getAttribute("class") != "dummyFloat") 
		{
			curId.childNodes[curIndex].style.display = "none";
		}
		if(curIndex != -1) setTimeout('minimizeId("'+elId+'","'+curIndex+'")', 50);
	}*/
	
	function minimizeIdHeight(elId, speed)
	{
		//alert(elId);
		if(speed >= 15) speed = speed - 5;			//dont let the speed get faster than 15ms;
		//alert(speed);
		var curId = document.getElementById(elId);	
		var curHeight = curId.clientHeight - 10;	//decrease height by 10px
		if(curHeight <= 10) curHeight = 0;			//if the element is less than 10px high
		curId.style.height = curHeight + 'px';		
		//curId.setAttribute("style", "height:"+curHeight);		
		
		if(curHeight > 10) setTimeout('minimizeIdHeight("'+elId+'","'+speed+'")', speed);
		//else curId.style.display = "none";
	}
	
	function maximizeIdHeight(elId, speed, maxHeight)
	{
		//alert(elId);
		if(speed >= 15) speed = speed - 5;			//dont let the speed get faster than 15ms;
		//alert(speed+"_"+maxHeight);
		var curId = document.getElementById(elId);	
		var curHeight = curId.clientHeight + 10;	//decrease height by 10px
		if(curHeight >= (maxHeight-10) ) curHeight = maxHeight;			//if the element is less than 10px high
		curId.style.height = curHeight + 'px';		
		//curId.setAttribute("style", "height:"+curHeight);		
		//alert("curHeight: " + curHeight + " maxHeight: " + maxHeight);
		if(curHeight < maxHeight-10 ) setTimeout('maximizeIdHeight("'+elId+'","'+speed+'","'+maxHeight+'")', speed);
	}
	
/*-------------------------------------------
END OF FUNCTIONS DEALING WITH POST-APPEND OPERATIONS*/
/*-------------------------------------------*/

domMan.prototype.addEl = addEl;
domMan.prototype.addElement = addEl;
domMan.prototype.addAttributes = addAttributes;
domMan.prototype.addAtts = addAttributes;
domMan.prototype.addCheckboxGroup = addCheckboxGroup;
domMan.prototype.addGroup = addGroup;
domMan.prototype.addRadioGroup = addRadioGroup;
domMan.prototype.addTagGroup = addTagGroup;
domMan.prototype.addOptionGroup = addOptionGroup;
domMan.prototype.addCheckboxGroup = addCheckboxGroup;
domMan.prototype.remElById = removeElementById;
domMan.prototype.removeElementById = removeElementById;
domMan.prototype.remInById = removeInsidesById;
domMan.prototype.removeInsidesById = removeInsidesById;
domMan.prototype.minIdH = minimizeIdHeight;
domMan.prototype.maxIdH = maximizeIdHeight;
