$(document).ready(function(){
	var componentesLSE = buscarContenedoresLSE();
});

function buscarContenedoresLSE(){
	var selectorContenedorLSE = ".contenedorLSE";
	componentesLSE = [];
	$(selectorContenedorLSE, document.body).each(function(){
		var componente =  new LSE($(this));
		componente.videoLSE.hide();
		componente.asignarComportamientos();
		componentesLSE.push(componente);
	});
	return componentesLSE;
}
function LSE (contenedorLSE){ 
	var selectorEnlace = ".enlaceLSE";
	var selectorVideo = ".videoLSE object";
	var imagen = {open: "abrir_lse.png", close: "cerrar_lse.png"}
	var classVideoON = "videoON";
	var velocidad = 500;
	var that = this;
	
	this.contenedorLSE = contenedorLSE;
	this.enlaceLSE = this.contenedorLSE.children(selectorEnlace);
	this.videoLSE = this.contenedorLSE.find(selectorVideo);
	
	this.cambiarImagenEnlace = function(imagenAntigua, imagenNueva){
		var img = this.enlaceLSE.find('img')[0];
		img.src = img.src.replace(imagenAntigua, imagenNueva);
	};
	
	this.mostrarVideo = function(){
		this.enlaceLSE.blur();
		this.videoLSE.focus();
		this.contenedorLSE.addClass(classVideoON);
		this.videoLSE.slideDown(velocidad);
		this.cambiarImagenEnlace(imagen.open, imagen.close);
	};
	
	this.ocultarVideo = function(){
		this.enlaceLSE.blur();
		this.videoLSE.focus();
		this.videoLSE.slideUp(velocidad, function(){
			that.contenedorLSE.removeClass(classVideoON);
		});
		this.cambiarImagenEnlace(imagen.close, imagen.open);
	};
	
	this.asignarComportamientos = function(){
		this.enlaceLSE.toggle(
			function() {
				that.mostrarVideo();
			},
			function() {
				that.ocultarVideo();
			}
		);
	};
}

