/* Begin: TragicMedia.com - Animated Tab
/* created 9/08 by Rich Rudzinski
/*------------------------------------------*/
//constants={buttonClass:'class', speed:#, expandAllBool:bool, opacityBool:bool, horizontalBool:bool}  
//var tabs = new TabObject(constants);
//Only buttonClass is required. 'expandAllBool' if true will allow all of the tabs to open at once, 'opacityBool' if true will add opacity effect, 'horizontalBool' if true will expand width instead of height
/*------------- BEGIN: animateTab ----------------*/
function TabObject(values) { //create container object which will hold booleans and child objects
	var links = TM.getElementsByClassName(values.buttonClass, '*', document); //get all the links with the accordian class
	this.tabs = [];
	this.expandAllBool = (values.expandAllBool != undefined) ? values.expandAllBool : true;
	this.horizontalBool = (values.horizontalBool != undefined) ? values.horizontalBool : false;
	this.opacityBool = (values.opacityBool != undefined) ? values.opacityBool : true;
	for(i=0; i<links.length; i++) {
		this.tabs.push(new AnimatedTab(links[i], values.speed, values.opacitySpeed, this));
	}
}
function AnimatedTab(button, speed, opacitySpeed, objVar) {   //create individual tab objects
	this.speed = (speed != undefined) ? speed : 5; 	 // define obj vars 
	this.objVar = objVar;
	this.content = TM.$(button.rel);
	this.button = button;
	this.content.opacitySpeed = (opacitySpeed != undefined) ? opacitySpeed : 60;
	if(this.objVar.horizontalBool) { 		// set initial parameters based on user presets
		this.content.max = this.content.offsetWidth;
		if(this.button.className.match('active')) this.content.style.width = this.content.max + 'px';
		else this.content.style.width = '0px';
		this.content.current = parseInt(this.content.style.width);
	} else {
		this.content.max = this.content.offsetHeight;
		if(this.button.className.match('active')) this.content.style.height = this.content.max + 'px';
		else this.content.style.height = '0px'
		this.content.current = parseInt(this.content.style.height);
	}
	if(this.button.className.match('active') && this.objVar.opacityBool) {  // set initial opacity
		this.content.style.filter = 'alpha(opacity='+100+')';
		this.content.style.opacity = 1;
	} else if(this.objVar.opacityBool) {
		this.content.style.filter = 'alpha(opacity='+0+')';
		this.content.style.opacity = 0;
	}	
	this.button.onclick = TM.bindFunction(this, this.click);	// onclick
}
AnimatedTab.prototype.click = function() {
	if(this.button.className.match('active')) { // if open, close
		this.content.endOpacity = 0;
		this.speed = this.speed * -1;
		this.button.className = this.button.className.replace('active', '');
		if(this.objVar.horizontalBool) this.animateHoriz();
		else this.animate();
	} else { 
		if(!this.objVar.expandAllBool) { // manages other tabs when expandAll is false
			for(i=0; i<this.objVar.tabs.length; i++) {
				var initTimeout;
				if(this.objVar.tabs[i].button.className.match('active')) {
					this.objVar.tabs[i].content.endOpacity = 0;
					if(this.objVar.opacityBool) TM.animateOpacity(this.objVar.tabs[i].content); 
					this.objVar.tabs[i].button.className = this.objVar.tabs[i].button.className.replace('active', '');
					this.objVar.tabs[i].speed = this.objVar.tabs[i].speed * -1;
					if(this.objVar.horizontalBool) this.objVar.tabs[i].animateHoriz();
					else this.objVar.tabs[i].animate();
				}
			}
		}
		this.content.endOpacity = 1;
		this.button.className = this.button.className + ' active';  // else close
		this.speed = Math.abs(this.speed);
		if(this.objVar.horizontalBool) this.animateHoriz();
		else this.animate();
	}
	if(this.objVar.opacityBool) TM.animateOpacity(this.content);
}
/* animation method */
AnimatedTab.prototype.animate = function() {  // animates both open and closed solely based on +/- of speed
	clearTimeout(this.timeout);
	this.content.style.height = this.content.current + this.speed + 'px';
	this.content.current = parseInt(this.content.style.height);
	if(this.speed > 0) {
		if(this.content.max > (this.content.current + this.speed)) this.timeout = setInterval(TM.bindFunction(this, this.animate), 25); 
		else this.content.style.height = this.content.max + 'px';
	} else if (this.speed < 0) {
		if(this.content.current + this.speed > 0) this.timeout = setInterval(TM.bindFunction(this, this.animate), 25); 
		else this.content.style.height = '0px';
	}
}
/* horizontal animation */
AnimatedTab.prototype.animateHoriz = function() {
	clearTimeout(this.timeout);
	this.content.style.width = this.content.current + this.speed + 'px';
	this.content.current = parseInt(this.content.style.width);
	if(this.speed > 0) {
		if(this.content.max > (this.content.current + this.speed)) this.timeout = setInterval(TM.bindFunction(this, this.animateHoriz), 25); 
		else this.content.style.width = this.content.max + 'px';
	} else if (this.speed < 0) {
		if(this.content.current + this.speed > 0) this.timeout = setInterval(TM.bindFunction(this, this.animateHoriz), 25); 
		else this.content.style.width = '0px';
	}
}


