var ContentTextImageModule = new Object();

ContentTextImageModule.widgControls = new Object();


ContentTextImageModule.preMove = function( cof_index, the_index )
{
	if( this.widgControls[ cof_index + '_' + the_index ] )
		this.widgControls[ cof_index + '_' + the_index ].switchOff();
}


ContentTextImageModule.postMove = function( cof_index, the_index )
{
	if( this.widgControls[ cof_index + '_' + the_index ] )
		this.widgControls[ cof_index + '_' + the_index ].switchOn();
}


ContentTextImageModule.editorLoaded = function( cof_index, the_index )
{
	// wysiwyg
	var textarea = document.getElementById( 'cof_textarea_' + cof_index + '_' + the_index );
	var module_el = textarea.parentNode; //document.getElementById( 'cof_module_' + cof_index + '_' + the_index );
	var el_dim = Element.getDimensions(module_el);
	Element.setStyle( 'cof_textarea_' + cof_index + '_' + the_index, { width: (el_dim.width - 16) + 'px' } );

	this.widgControls[ cof_index + '_' + the_index ] = widgInitElem( 'cof_textarea_' + cof_index + '_' + the_index, ContentObjectFactory.admin );
}


ContentTextImageModule.preSave = function( cof_index, the_index )
{
	if( this.widgControls[cof_index + '_' + the_index] )
	{
		var the_form = document.getElementById( 'cof_form_' + cof_index + '_' + the_index );
		
		var new_el = Builder.node( 'input', { name:'text', type:'hidden' } );
		new_el.value = this.widgControls[cof_index + '_' + the_index].getInput();
		the_form.appendChild( new_el );
		
		delete( this.widgControls[cof_index + '_' + the_index] );
	}
}


ContentTextImageModule.preCancel = function( cof_index, the_index )
{
	if( this.widgControls[cof_index + '_' + the_index] )
		delete( this.widgControls[cof_index + '_' + the_index] );
}

ContentTextImageModule.preDelete = ContentTextImageModule.preCancel;

ContentTextImageModule.getInputList = function ( cof_index, the_index )
{
	return new Array( 
		'cof_files_' + cof_index + '_' + the_index + '_0',
		'cof_imagedescr_' + cof_index + '_' + the_index,
		'cof_imagecaption_' + cof_index + '_' + the_index,
		'cof_imagealign_' + cof_index + '_' + the_index + '_left',
		'cof_imagealign_' + cof_index + '_' + the_index + '_right'
	);
}

ContentTextImageModule.getRules = function()
{
	var self = this;

	var my_rules = {
		'.cof-textimage-remove' : function(el)
		{
			el.onclick = function()
			{
				BasicControlDisable.removeControlsClick( el, self );
			},
			
			el.onkeypress = function(e)
			{
				return ContentObjectFactory.doKeyPress( el, e );
			};	
		}
	};

	return my_rules;
}

