function gd_collapse(params)
{
	this.name=params.name;
	this.fields=params.fields;
	if(params.sc_factor)
		this.sc_factor=params.sc_factor;
	else
		this.sc_factor=sc_factor;
	this.max_height=params.max_height;
	if(params.margin_height)
		this.margin_height=params.margin_height;
	else
		this.margin_height=20;
	this.lang=params.lang;
	this.fields_height=new Array();
}

gd_collapse.prototype.init=function()
{
	for(var i=0;i<this.fields.length;i++)
	{
		this.fields_height[this.fields[i]]=0;
		jQuery("#"+this.fields[i]).after('<div id="'+this.fields[i]+'_op" class="tright collapse_div"></div>');
	}
	this.collapse_all();
}

gd_collapse.prototype.collapse_all=function()
{
	for(var id in this.fields_height)
		this.close_one(id,this.fields_height[id]);
}
gd_collapse.prototype.close_one=function(id,height)
{
	if(jQuery("#"+id).height()>(this.max_height+this.margin_height)*this.sc_factor)
	{
		this.fields_height[id]=jQuery("#"+id).height();
		jQuery("#"+id).css("overflow-y","hidden").height(this.max_height*this.sc_factor);
		jQuery("#"+id+"_op").html('<a href="javascript:'+this.name+'.show_one(\''+id+'\');">'+this.lang.expand+'</a>');
	}
}
gd_collapse.prototype.hide_one=function(id)
{
	jQuery("#"+id).animate({height:(this.max_height*this.sc_factor)+"px"},500,"linear",function(){jQuery("#"+id).css("overflow-y","hidden")});				
	jQuery("#"+id+"_op").html('<a href="javascript:'+this.name+'.show_one(\''+id+'\');">'+this.lang.expand+'</a>');
}
gd_collapse.prototype.show_one=function(id)
{
	jQuery("#"+id).animate({height:this.fields_height[id]+"px"},500);
	jQuery("#"+id+"_op").html('<a href="javascript:'+this.name+'.hide_one(\''+id+'\');">'+this.lang.collapse+'</a>');
}