// JavaScript Document

function AccordianItem( pannel , tab ){
	this.pannel = pannel;
	this.pannel.style.height = tab.offsetHeight + 1 + "px";
	this.pannel.style.overflow = "hidden";
	this.tab = tab;
	this.tab.parent = this;
	this.speed = 5;
	this.closing = 0;
	this.tab.onclick = function(){ 
		this.parent.parent.doCloses( this.parent );
	}
}
function Accordion( items ){
	this.speed = 5;
	this.spacing = 2;
	this.items = items;
	this.OPEN = this.items[ 0 ].pannel.scrollHeight;
	this.CLOSED = this.items[ 0 ].tab.offsetHeight + this.spacing;
	
	for( var i = 0; i < this.items.length; i++ ){
		this.items[ i ].parent = this;
		this.items[ i ].H = this.CLOSED;
	}
	this.doCloses = function( obj ){
		for( var i = 0; i < this.items.length; i++ ){
			if( this.items[ i ].H > this.CLOSED ){  
				this.items[ i ].closing = -1;
			}
			//this.items[ i ].H = this.items[ i ].pannel.offsetHeight;
			this.items[ i ].pannel.className = "accordion_div";
		}
		obj.closing = 1;
		//obj.H = obj.pannel.offsetHeight;
		obj.pannel.className = "accordion_open";
		this.doCloses1();
	}
	this.doCloses1 = function(){
		var done = true;
		for( var i = 0; i < this.items.length; i++ ){
			//closing div
			if( this.items[ i ].closing == -1 ){ 
				//if not finnished closing
				if( this.items[ i ].H > this.CLOSED ){
					this.items[ i ].H = Math.max( this.items[ i ].H - this.speed , this.CLOSED );
					this.items[ i ].pannel.style.height = this.items[ i ].H + "px";
					done = false;
				}
				else{ 
					this.items[ i ].pannel.style.height = this.CLOSED + "px";
					this.items[ i ].closing = 0; 
				}
			//opening div
			} else if( this.items[ i ].closing == 1 ){
				//if not finnished openning
				if( this.items[ i ].H < this.OPEN ){
					this.items[ i ].H = Math.min( this.items[ i ].H + this.speed , this.OPEN );
					this.items[ i ].pannel.style.height = this.items[ i ].H + "px";
					done = false;
				}
				else{ 
					this.items[ i ].pannel.style.height = this.OPEN + "px";
					this.items[ i ].closing = 0; 
				}
			}
		}
		if( !done ){
			var self = this;
			this.int = setTimeout( function(){ self.doCloses1(); } , 15 );
		} else { clearTimeout( this.int ); }
	}
}
function getChildByClass( o , c ){
	for( var i = 0; i < o.childNodes.length; i++ ){
		if( o.childNodes[ i ].className == c ){
			return o.childNodes[ i ];
		}
	}
}