//init button manager
function buttonMgrInit(container)
{
	if(container=='' || container==undefined || container==null) container = 'body';

	$$(container+' .buttonMgr').each( function(el) { addEvent(el, 'click', buttonToggleManager) } );
}

//force a button trigger on element
function buttonTrigger(currElement)
{
	currElement.onclick = buttonManager;
		currElement.onclick();	
}

//determine button behaviors
function buttonToggleManager(el)
{
	//check if we need to hide or show elements
	if(this.getAttribute('hide') !=null || this.getAttribute('show') !=null)
		toggleContent(this);
}

//fades content/form ids in and out
function fadeContent(obj)
{

	var toObjId = obj.id;
	var toObjIDArray = obj.id.split('_');
	$(toObjId).style.height='';

	//fade to default content
	if(toObjIDArray[toObjIDArray.length-1]=="content")
	{
		var fromObjId = obj.id;
		var fromObjIdArray = fromObjId.split('_');
		fromObjIdArray[fromObjIdArray.length-1] = "form";
		fromObjId = fromObjIdArray.join('_');
	}
	else
	//fade to form content
	{
		var fromObjId = obj.id;
		var fromObjIdArray = fromObjId.split('_');
		fromObjIdArray[fromObjIdArray.length-1] = "content";
		fromObjId = fromObjIdArray.join('_');
	}

	//get our default content height so we can resize back to original
	$(fromObjId).style.overflow = 'hidden';
	var contentHeight = $(fromObjId).getHeight();
	$(fromObjId).style.overflow = '';
		
	//create obj instances for fade/resize
	opacityTweenHide = new OpacityTween($(fromObjId),Tween.regularEaseOut, 100, 0, .5);
	opacityTweenShow = new OpacityTween(obj,Tween.regularEaseOut, 0, 100, .5);
	
	//stretch our content height to match our form height
	contentResize = new Tween($(fromObjId).style,'height',Tween.regularEaseIn,$(fromObjId).getHeight(),obj.getHeight(),1,'px');
	
	//when finished fading out, start resize
	opacityTweenHide.onMotionFinished= function(){ contentResize.start() };
	
	//when finished resizing hide/show elements and fade in
	contentResize.onMotionFinished= function(){ 

		Element.hide($(fromObjId));
		Element.show(obj);
		opacityTweenShow.start();
		
		//reset our content height
		$(fromObjId).style.height = contentHeight+'px';
		};

	//start pimped out profile
	opacityTweenHide.start();


}

// hide/show elements based on element attributes
function toggleContent(obj)
{
	//alert(obj.getAttribute('hide')+' '+obj.getAttribute('show'));
	//get our elements to hide
	if(hidenames = obj.getAttribute('hide'))
	{
		try
		{
			//go through our elements and hide them
			Hnames = hidenames.split(' ');
			//alert(Hnames);
			for(var loop=0;loop<Hnames.length;loop++)
			{
				if(Hnames[loop] == 'this')
					Element.hide(obj);
				else
					Element.hide(Hnames[loop]);
			}
		}
		catch(err) {}
	}
	
	//get our elements to show
	if(shownames = obj.getAttribute('show'))
	{
		try
		{
			//go through our elements and show them
			Snames = shownames.split(' ');
			for(var loop=0;loop<Snames.length;loop++)
			{
				if(Snames[loop] == 'this')
					Element.show(obj);
				else
				{
					objID = Snames[loop].split('_');
					if(objID[objID.length-1]=="content" || objID[objID.length-1]=="form" )
						fadeContent($(Snames[loop]));
					else
						Element.show(Snames[loop]);
				}
			}
		}
		catch(err) {}
	}
}

