/*##inlineEdit*/
function LynxInlineEdit(object,text){
	//alert("test");
	this.label = object;
	var jlab = $j(this.label);
	if($j.trim(jlab.text())=='')jlab.text('edytuj...');
	if(text==undefined){
		this.text = $j("<div style='width:100%;height:100%;display:none'><textarea style='min-height:160px'></textarea>\
		<input type='button' value='Zapisz' class='save'/><input type='button' value='Anuluj' class='cancel'/>");
		jlab.before(this.text);
	}else this.text = text;
	this.mode = 0;
	var _me = this;
	jlab.click(function(){_me.toggle()});
	$j(this.text).find('.cancel').click(function(){_me.toggle()}).end().
		find('.save').click(function(){_me._save()});
	this.cmingle = true;//whether to change the data (replace ',' with '<br>')
	this.toggle_on_save = false;
}

LynxInlineEdit.prototype.toggle = function(){
	var _me = this;
	if(this.mode==0)$j(this.label).fadeOut("slow",function(){_me._showEdit()});
	else $j(this.text).fadeOut("slow",function(){_me._showLabel()});
	this.mode = !this.mode;
}

LynxInlineEdit.prototype._showEdit = function(){
	if(this.cmingle){
		var val = this.label.innerHTML.replace(/<br.*?>/g,',').replace('\n',' ');
		val = val.replace(/^[, (\t)]*/,'').replace(/[, (\t)]*$/,'');
	}else{
		var val = this.label.innerHTML;
		//val = val.replace(/^[, (\t)]*/,'').replace(/[, (\t)]*$/,'');
	}
	$j(this.text).find('textarea').val(val).end().fadeIn("normal");
}

LynxInlineEdit.prototype._showLabel = function(){
	$j(this.label).fadeIn("normal");
}

LynxInlineEdit.prototype.free = function(){
	$j(this.label).unbind('click');
	this.label = null;
	this.text = null;
	this.onsave = null;
}

LynxInlineEdit.prototype._save = function(){
	if(this.cmingle){
		var cont = $j(this.text).find('textarea').val().replace('\n',' ');
		if($j.trim(cont)=='')$j(this.label).html('edytuj...');
		else $j(this.label).html(cont.replace(/,/g,'<br />'));
	}else{
		var cont = $j(this.text).find('textarea').val();
		if($j.trim(cont)=='')$j(this.label).html('edytuj...');
		else $j(this.label).html(cont);
	}
	if(cont.length==0)this.label.style.height = '100%';
	else this.label.style.height = 'auto';
	if(this.onsave)this.onsave(cont,this);
	if(this.toggle_on_save)this.toggle();
}

