var Vocento = {};
Vocento.Controlador = Class.create();
Vocento.Controlador.prototype  = {
	initialize: function(){ with(this) {
		controladorElementosInsertarOnFly();
	}},
	controladorElementosInsertarOnFly: function(){ with(this) {
		if (existeElemento(Vocento.Selectores.enlaceVerFormularioEnVentanaModal))
			construye().enlaceVerFormularioEnVentanaModal(Vocento.Selectores.enlaceVerFormularioEnVentanaModal);
	}},
	existeElemento: function(selector){ with(this) {
		return ($$(selector).length > 0)
	}},
	construye: function(selector){ with(this) {
		return new Vocento.Constructor(this);
	}},
	insertaComportamiento: function(selector){ with(this) {
		return new Vocento.GeneradorComportamientos(this);
	}}
}


Vocento.Constructor = Class.create();
Vocento.Constructor.prototype  = {
	initialize: function(controlador){ with(this){
		this.controlador = controlador;
	}},
	enlaceVerFormularioEnVentanaModal: function (selector) { with(this) {
		$$(selector).each( function (enlace) {
			var cadenaHTML = enlace.innerHTML +  Vocento.CodigosHTML.enlaceVerFormularioEnVentanaModal;
			insertaHTMLOnFly(enlace, cadenaHTML);
		},this)
	}},
	insertaHTMLOnFly: function (nodoPadre, cadenaHTML) { with(this) {
		nodoPadre.innerHTML = cadenaHTML;
	}}
}



Vocento.GeneradorComportamientos = Class.create();
Vocento.GeneradorComportamientos.prototype  = {
	initialize: function(controlador){ with(this){
		this.controlador = controlador;
	}},
	enlaceVerFormularioEnVentanaModal: function(enlace){ with(this){
		Event.observe(enlace, 'click', this.generaVentanaModalVerFormulario.bindAsEventListener(this), false);
	}},
	generaVentanaModalVerFormulario: function(enlace,argumentos){ with(this){
		this.controlador.construye().ventanaModalFormularioHome();
	
	}}
}



//CONSTANTES DE LA APLICACION

Vocento.Textos = {
	enlaceVerFormularioEnVentanaModal: 'Abre en ventana nueva modal.'
}

Vocento.Selectores = {
	enlaceVerFormularioEnVentanaModal: '.enlaceVerFormularioEnVentanaModal'

}
/*
Vocento.Clases = {
	openBlank: 'openBlank'

}
*/
Vocento.CodigosHTML = {
	enlaceVerFormularioEnVentanaModal: '<span class="indentado"> '+Vocento.Textos.enlaceVerFormularioEnVentanaModal+'</span>'
}




//CODIGO PARA CARGAR DISTINTOS EVENTOS DE LA APLICACION
Event.observe(window, 'load', lanzarEventos, false);


function lanzarEventos() {
	new Vocento.Controlador();
}
