/*
	RowCollapse
*/
RowCollapse=Class.create();
RowCollapse.prototype=
{
	hasInit:false,
	holder:"",
	holderOBJ:null,
	holders:null,
	handler:"",
	handlerOBJ:null,
	rowStatus:0, // 0 = collapse, 1= open
	rowToggler:"",
	rowTogglerOBJ:null,
	
	initialize:function(args)
	{
		args=getDefaults(args,{holder:this.holder,handler:this.handler,rowToggler:this.rowToggler});
		
		this.hasInit=true;
		
		if(args.holder!="")
		{
			this.holder=args.holder;
			
			this.holders=$$("." +this.holder);
			
			if(this.holders.length>0)
			{
				
			} else {
				this.hasInit=false;
			}
		} else {
			this.hasInit=false;
		}
		
		if(args.rowToggler!="")
		{
			if(this.rowTogglerOBJ=$(args.rowToggler))
			{
				this.rowToggler=args.rowToggler;
				this.rowTogglerOBJ.hide();
			} else {
				this.hasInit=false;	
			}
		} else {
			this.hasInit=false;
		}
		
		
		if(args.handler!="")
		{
			if(this.handlerOBJ=$(args.handler))
			{
				this.handler=args.handler;				
			} else {
				this.hasInit=false;	
			}
		} else {
			this.hasInit=false;
		}
		
		//alert(this.hasInit);
		
		if(this.hasInit)
		{
			this.rowTogglerOBJ.show();
			
			this.closeRows(false);		
						
			this.handlerOBJ.style.cursor="pointer";
			
			Event.observe(this.handler,'click',this.toggle.bind(this));
		}
	},
	
	toggle:function()
	{
		if(this.rowStatus==1)
		{
			this.closeRows(true);		
		} else {
			this.openRows();
		}
	},
	
	closeRows:function(animate)
	{
		len=this.holders.length;
		for(i=0;i<len;i++)
		{
			if(id=$(this.holders[i].id))
			{
				if(animate==true)
				{
					id.fade({duration:0.5});
				} else {
					id.style.display="none";
				}
			}
		}
		
		this.rowStatus=0;
		
		if(this.rowTogglerOBJ!=null)
		{
			this.rowTogglerOBJ.style.backgroundPosition="top left";
		}
	},
	
	openRows:function()
	{
		len=this.holders.length;
		for(i=0;i<len;i++)
		{
			if(id=$(this.holders[i].id))
			{
				id.appear({duration:0.5});
			}
		}
		this.rowStatus=1;
		
		if(this.rowTogglerOBJ!=null)
		{
			this.rowTogglerOBJ.style.backgroundPosition="bottom left";
		}		
	}	
};