
function Effect(obj){
	this.onEnterFrame = null
	this.obj = null
	this.currentHeight = null
	this.minHeight = 20
	this.maxHeight = 100
	this.interval = 10;
	this.aceleration = 10;
	this.header = null
	this.moving = false;
	this.open =  function (){
		this.currentHeight = parseFloat(this.obj.style.height )
		if(Math.round(this.currentHeight)<this.maxHeight){
		    //if(!this.moving){this.onStartOpen()}
			this.moving = true
			this.currentHeight  += ( this.maxHeight - this.currentHeight)/this.aceleration
			this.obj.style.height = this.currentHeight+"px"
			var _this = this;
            this.onEnterFrame = window.setTimeout(function() { _this.open(); },this.interval);
        }else{
            this.moving = false;
            //this.onFinishOpen()
        }	
		  	
	}
	this.close  =  function (){
		this.currentHeight = parseFloat(this.obj.style.height)
		if(Math.round(this.currentHeight)>this.minHeight){
		    //if(!this.onStartClose){this.onStartClose()}
			this.moving = true
			this.currentHeight  -= ( this.minHeight + this.currentHeight)/this.aceleration
			this.obj.style.height = this.currentHeight+"px"
			var _this = this;
            this.onEnterFrame = window.setTimeout(function() { _this.close(); },this.interval);	
        }else{
            this.moving = false;
            //this.onFinishClose()
        }	
	
	
	}
	this.stop = function () {
		
		if(this.onEnterFrame) {clearTimeout(this.onEnterFrame)}
	
	}
	this.init=function(obj) {
	this.obj = obj
	this.currentHeight = parseFloat(this.obj.offsetHeight)
	this.obj.style.height = this.currentHeight+"px"
	}
	this.init(obj)
}

function acordeon(obj){
	this.obj = obj
	this.items = []
	this.options = ({initItem:1})
	this.itemsContent = []
	this.itemsHeader = []
	this.minHeight  = 0
	this.maxHeight  = 0
	this.initialize = false
	
	this.init = function () {
		this.obj = document.getElementById(obj);
		var itemHeaderMaxHeight = 0;
		for (var i=0;i<this.obj.childNodes.length;i++) {
			var item = this.obj.childNodes[i];			
			if (item.nodeName.toUpperCase()=="DIV"){ 
				var _this = this
				var _item = item
				listen("click",item,function() {_this.event(this)})
				this.items.push(item)
				for (var j=0;j<item.childNodes.length;j++) {
					var subItem = item.childNodes[j]
					if (subItem.className){
						if (subItem.className.toUpperCase()=="HEADER"){ 
							this.itemsHeader.push(subItem);
							if(itemHeaderMaxHeight<subItem.offsetHeight)itemHeaderMaxHeight = subItem.offsetHeight;
						}
						if (subItem.className.toUpperCase()=="CONTENT") {
							subItem.style.height = "0px"
							this.itemsContent.push(subItem);
						}
					}	
				}
			}
		
		}
		
		//revision
		
		
		if(ToolKit.navegadorIsGecko){
			var margin = (test(parseFloat(ToolKit.getProperty(this.items[0],"margin-top")))+test(parseFloat(ToolKit.getProperty(this.items[0],"margin-bottom"))))/2
			var padding = (test(parseFloat(ToolKit.getProperty(this.items[0],"padding-top")))+test(parseFloat(ToolKit.getProperty(this.items[0],"padding-bottom"))))/2
		}else{
			var margin = (test(parseFloat(ToolKit.getProperty(this.items[0],"marginTop")))+test(parseFloat(ToolKit.getProperty(this.items[0],"marginBottom"))))/2
			var padding = (test(parseFloat(ToolKit.getProperty(this.items[0],"paddingTop")))+test(parseFloat(ToolKit.getProperty(this.items[0],"paddingBottom"))))/2
		}
		var tolerance = 2
		var _this = this
		if(this.maxHeight==0)this.maxHeight = this.obj.offsetHeight-((itemHeaderMaxHeight+padding+margin+tolerance)*(this.items.length));
		for(var k=0;k<this.items.length;k++){
			var _item = this.items[k]
			var _subItemContent = this.itemsContent[k]
			_item.fx__ = new Effect(_subItemContent);
			_item.fx__.header = this.itemsHeader[k]
			_item.fx__.minHeight = this.minHeight;
			_item.fx__.maxHeight = this.maxHeight;
		}
		this.items[this.options.initItem-1].fx__.open()
		this.initialize = true
	}
	this.event = function (curItem) {
		for (var i=0;i<this.items.length;i++) {
			var item = this.items[i]
			if(curItem==item){
				if(item.fx__.moving)item.fx__.stop();
				this.itemsHeader[i].style.background="#transparent url('images/arrowAcordeon_enabled.gif') no-repeat scroll 2px 0"
				item.fx__.open()
			}else{
				if(item.fx__.moving)item.fx__.stop();
				this.itemsHeader[i].style.background="#transparent url('images/arrowAcordeon_disabled.gif') no-repeat scroll 2px 0"
				item.fx__.close()
		}	}
	
	}

}



