/* utf8 marker ö */

// ----------------------------------------------------------------
// create the Icon class
// ----------------------------------------------------------------
mlvi.Label = function(){
};
mlvi.Label.prototype = {
	// ----------------------------------------------------------------
	// place the icon in the correct location
	// ----------------------------------------------------------------
	mlviPlace: function(){
		var element = this.VIcontainer.mlviGetElementFromIndex(this.VIelement.mlviIndex);
		//save the text
		this.mlviSetLabelText(element.label.text);
		//set the styles
		var labelStyles = this.mlviGetStyles();
		this.setStyle(labelStyles);
	},
	
	// ----------------------------------------------------------------
	// get the styles of the label
	// ----------------------------------------------------------------
	mlviGetStyles: function(){
		var element = this.VIcontainer.mlviGetElementFromIndex(this.VIelement.mlviIndex);

		//set styles to the container
		var labelStyles = {
			'float':		'left'
		};

		//add the dinamic styles
		if(element.label != null && element.label.style!=null){
			for(var styleName in element.label.style){
				labelStyles[styleName] = element.label.style[styleName];
			}
		}
		
		//set the size
		if(labelStyles.fontSize){
			labelStyles['lineHeight'] 	= labelStyles.fontSize;
			labelStyles['height'] 		= '30px';
		}

		if(!this.VIcontainer.mlviGetMode()){
			var width = this.VIcontainer.mlviImageDefinition.background.width - element.position.x;
			width = this.VIcontainer.mlviTransformX(width);
			labelStyles['width'] = width + 'px';
		}
		
		return labelStyles;
	},
	
	// ----------------------------------------------------------------
	// save the text of the label
	// ----------------------------------------------------------------
	mlviSetLabelText: function(text){
		//save the text in the data structure
		if(this.VIcontainer.mlviImageDefinition.elements[this.VIelement.mlviIndex].label!=null){
			this.VIcontainer.mlviImageDefinition.elements[this.VIelement.mlviIndex].label.text = text;
		}
		
		//show in the interface
		this.innerHTML = text;
	},
	
	// ----------------------------------------------------------------
	// get the label text
	// ----------------------------------------------------------------
	mlviGetLabelText: function(){
		//save the text in the data structure
		if(this.VIcontainer.mlviImageDefinition.elements[this.VIelement.mlviIndex].label!=null){
			return this.VIcontainer.mlviImageDefinition.elements[this.VIelement.mlviIndex].label.text;
		}
		
		return '';
	},

	// ----------------------------------------------------------------
	// show interface to edit the text
	// ----------------------------------------------------------------
	mlviEditText: function(){
		var InputID 	= 	this.VIelement.mlviInputID;
		var dimensions 	= 	this.getDimensions();
		var inputDef 	=	'<input ' + 
							'id="' + InputID + '" ' + 
							'type="text" ' +
							'value="' + this.mlviGetLabelText() + '" ' +
							'style="' +
								'float: left; ' + 
								'border: 0px; ' +
								'width: ' + dimensions.width + 'px; ' + 
								'height: ' + dimensions.height + 'px;  '+
								'vertical-align: middle; ' + 
								'line-height: ' + dimensions.height + 'px;  '+
								'background-color: transparent;  '+
							'" ' + 
						'/>'
		var labelStyles 			= this.mlviGetStyles();
		this.replace(inputDef);
		var VIinput 				= $(InputID);
		VIinput.VIelement 			= this.VIelement;
		VIinput.VIcontainer 		= this.VIcontainer;

		//extend the input object
		var input = new mlvi.Input();
	    Object.extend(VIinput, input);
		VIinput.mlviSetEvents();
		VIinput.setStyle(labelStyles);
		VIinput.focus();
		
	},	

	
	// ----------------------------------------------------------------
	// set the events to handle the label
	// ----------------------------------------------------------------
	mlviSetEvents: function(){
		var readOnly = 0;
		if(this.VIcontainer.mlviImageDefinition.elements[this.VIelement.mlviIndex].readonly!=null){
			readOnly = 1;
		}
	
		if(this.VIcontainer.mlviGetMode() && !readOnly){
		    Event.observe(this, 'click', this.mlviEventClick.bindAsEventListener(this));
		}
	},	
	
	// ================================================================
	// EVENT HANDLERS
	// ================================================================

	// ----------------------------------------------------------------
	// mark an element like selected
	// ----------------------------------------------------------------
	mlviEventClick: function(event){
		this.mlviEditText();
	}, 


	
	
	
	
	
	NADA: ''
	
}



