
/**
 * Clase OverlayTexto
 */
var OverlayTexto = function(){

	//SOBRECARGA
	if ( arguments.length == 1 )
		var $texto = arguments[0];
	else
		var $texto = "";
	
	
	//ATRIBUTOS DE LA CLASE
	this.atributos = {
		texto:          $texto,
		divImagenClose: "",
		divImagenClick: "",
		divOverlay:     "",
		idDivOverlay:   "",
		trigger:        "",
		colorFondo:     "",
		width:          "688px",
		height:         "412px",
		api:            "",
		imgFondo:       "ingresar_advertencia.png",
		imagenLink:     false,
		imgLinkCoord1:  0,
		imgLinkCoord2:  0,
		imgLinkCoord3:  0,
		imgLinkCoord4:  0 
	}
	
	
	
	/**
	 * CONSTRUCTOR PUBLICO
	 */
	this.__construct = function(){	
		this.atributos.idDivOverlay = "overlay_texto_class";
		this.atributos.colorFondo = "transparent";
	}
	
	
	/**
	 * Metodo Publico
	 */
	 
	this.abrir = function(){	
		prepararElementos.call(this);
		//borrarHtmlAnterior.call(this);

		
		this.atributos.divOverlay.append( this.atributos.divImagenClose );
		this.atributos.divOverlay.append( this.atributos.divImagenClick );
		this.atributos.divOverlay.append( this.atributos.texto );
		
		corregirNodoNulo.call(this);
		
		$("body").append( this.atributos.trigger );
		$("body").append( this.atributos.divOverlay );
	
		this.atributos.api = $(this.atributos.trigger).overlay({
			speed: 'fast',
			effect: 'apple',
			closeOnEsc: 'true',
			closeOnClick: 'true',
			expose: {
				color: this.atributos.colorFondo
			}
		});
		
		$( "body a[rel='#"+ this.atributos.idDivOverlay +"']" ).click();
	}
	
	
	this.setTexto = function($texto){
		this.atributos.texto = $texto;
	}
	
	this.setImagenFondo = function($imgFondo){
		this.atributos.imgFondo = $imgFondo;
	}
	
	this.setColorFondo = function($colorFondo){
		this.atributos.colorFondo = $colorFondo;
	}
	
	this.setWidth = function($width){
		this.atributos.width = $width;
	}
	
	this.setHeight = function($height){
		this.atributos.height = $height;
	}
	
	this.setimagenLink = function($imagenLink){
		this.atributos.imagenLink = $imagenLink;
	}
	
	this.getimagenLink = function(){
		return this.atributos.imagenLink;	
	}
	
	this.setimgLinkCoord1 = function($imgLinkCoord1){
		this.atributos.imgLinkCoord1 = $imgLinkCoord1;
	}
	this.setimgLinkCoord2 = function($imgLinkCoord2){
		this.atributos.imgLinkCoord2 = $imgLinkCoord2;
	}
	this.setimgLinkCoord3 = function($imgLinkCoord3){
		this.atributos.imgLinkCoord3 = $imgLinkCoord3;
	}
	this.setimgLinkCoord4 = function($imgLinkCoord4){
		this.atributos.imgLinkCoord4 = $imgLinkCoord4;
	}
	
	/**
	 * Metodo privado
	 */
	function borrarHtmlAnterior(){
		this.atributos.divOverlay.empty();
	
		$( "body div#exposeMask" ).remove();
		$( "body img[src='images/fondos/"+this.atributos.imgFondo+"']" ).remove();
		$( "body a[rel='#"+ this.atributos.idDivOverlay +"']" ).remove();
		$( "body #"+this.atributos.idDivOverlay ).remove();
	}
	
	
	
	
	function prepararElementos(){
		$height = this.atributos.height;
		$width  = this.atributos.width;
		
		if(this.atributos.imagenLink == false){
	
		this.atributos.divOverlay =  $("<div/>", {
			id: this.atributos.idDivOverlay,
			css: {
				background:   "url(images/fondos/"+this.atributos.imgFondo+") no-repeat scroll center center transparent",
				display:      "none",
				fontFamily:   "Arial,Helvetica,sans-serif",
				height:       $height,
				padding:      "20px",
				textAlign:    "left",
				width:        $width
			}
		});	
		
		}else{
			$imgLinkCoord1 = this.atributos.imgLinkCoord1;
			$imgLinkCoord2 = this.atributos.imgLinkCoord2;
			$imgLinkCoord3 = this.atributos.imgLinkCoord3;
			$imgLinkCoord4 = this.atributos.imgLinkCoord4;
			
			
			this.atributos.divOverlay =  $("<div/>", {
			id: this.atributos.idDivOverlay,
			css: {
				background:   "url(images/fondos/"+this.atributos.imgFondo+") no-repeat scroll center center transparent",
				display:      "none",
				fontFamily:   "Arial,Helvetica,sans-serif",
				height:       $height,
				padding:      "20px",
				textAlign:    "left",
				width:        $width
			}
			});	
			
			this.atributos.divImagenClick = $("<div/>", {
				id: 'overlay_texto_class_link',							  
				css: {
					backgroundImage: "url(images/transparente.png)",
					position:        "absolute",
					right:			 $imgLinkCoord1,
					top:			 $imgLinkCoord2,
					cursor:          "pointer",
					height:          $imgLinkCoord3,
					width:           $imgLinkCoord4
				}
			});
		}
		
		
		this.atributos.divImagenClose = $("<div/>", {
			css: {
				backgroundImage: "url(images/close.png)",
				position:        "absolute",
				right:			 "5px",
				top:			 "5px",
				cursor:          "pointer",
				height:          "35px",
				width:           "35px"
			}
		});
		this.atributos.divImagenClose.attr("class", "close");
		
		
		
		this.atributos.trigger = $("<a/>",{
			rel: "#" + this.atributos.idDivOverlay,
			href: "#",
			css: {
				display: "none"
			}
		});	
	}
	
	
	/**
	 * No se porque, se inserta un nodo "vacio" (un espacio en blanco q ve firebug, que no existe ni se detecta pero deja lugar y molesta).
	 * Esta funcion recorre todos los nodos que jquery detecta, y los vuelve a insertar, eliminando el vacio.
	 */
	function corregirNodoNulo(){
		
		var $array = new Array();
		var $div = this.atributos.divOverlay;
		
		
		$.each( $div.children(),  function($i, $value){
			$array.push( $value );
		});
	
		$div.empty();

		$.each($array, function($i, $value){
			$div.append( $value );
		});
		
	}
	

	
	this.__construct();
}



