// JavaScript Document

/*
 * 
 * Clases para el sitio www.kimelu.cl
 * 
 * (c) 2009 Carlos Martel Werner
 * 
 * Prohibida su reproducciï¿½n total o parcial 
 */

/*########## Inicio Clase dialogo *################ */
function Dialogo() {
	/* Atributos */
	this.isOpened = false;
	this.height = 200;
	this.topString = '';/*
						 * '<div id="dialogContainer"><div
						 * id="dialogTop">&nbsp;</div><div id="dialogCenter"
						 * style="height:'+this.height+'px;">';
						 */
	this.bottomString = '</div><div id="dialogBottom">&nbsp;</div></div>';
	this.text = null;
	this.container = null;
	this.marginTop = '';
	this.position = 'fixed';
	
	/* funciones */
	this.show = function(element) {
		this.container = element;
		
		
		this.container.style.position = this.position;
		/* Corregir centro de Internet Explorer por Carlos Martel Werner */
		if (navigator.appName == "Microsoft Internet Explorer")
			this.container.style.width = (document.documentElement.clientWidth - 110) + 'px';

		this.container.innerHTML = this.topString + this.text
				+ this.bottomString;

	}

	this.setHeight = function(height) {
		this.height = height;
		this.topString = '<div id="bgContainer"; background:url(../img/bgDialog.png); style="position:absolute; z-index:20000; width:100%; height:100%; top: 0; left: 0; z-index: 0;margin-top:'+this.marginTop+'px">'
				+ '<div id="dialogBackground" style="height:'
				+ (this.height + 40)
				+ 'px; "> </div>'
				+ '</div>'
				+

				'<div id="dialogContainer" style="z-index:10; position:relative;margin-top:'+this.marginTop+'px">'
				+ ' <div id="dialogTop">&nbsp;</div>'
				+ '<div id="dialogCenter" style="height:'
				+ this.height+'px; margin-top'
				+ 'px;">';
	}

	this.close = function() {
		try {
			this.container.innerHTML = '';
		} catch (e) {
			alert('ERROR: ' + e.toString());
		}
	}
}

/* ########## Fin Clase Dialogo ##################### */
/* ########## Inicio Clase GloboTexto *################ */

function GloboTexto(container, text) {
    this.abierto = false;
	this.container = container;
    this.text = text;
	this.globoString = '<div class="globoTexto" id="globoTexto">'
			+ '<div align="right" style="margin-top:5px"><a href="javascript:globo.close()"><img border="0" src="'+IMG_URL+'/img/cruz_globo.gif" style="margin-right:10px;padding-top:15px:"></a></div>'
			+ '<div class="globoTextoContent">' + this.text + '</div>' + '</div>';

	this.mostrar = function() {
		this.htmlOriginal = container.innerHTML;
		container.innerHTML = this.globoString + container.innerHTML;
        this.abierto = true;
	}
	this.close = function(param) {
        /*
         *Procedimientos de disolver         *
         **/
        if(param == 1){
        dis = new Disolver();
        dis.setDiv(document.getElementById('globoTexto'));
        dis.nIntervalo = 4;
        dis.desaparecer();
        dis.encambioestado = function(){
            if(dis.estado == 1){
                this.container.innerHTML = this.htmlOriginal;
            }
        }
        }
        else{
            this.container.innerHTML = this.htmlOriginal;
        }

		
	}

}

/* ########## Fin Clase Dialogo ##################### */

/* ########### Clase disolver ###################*/
function Disolver(){
    this.estado = 0;
    this.div = null;
    var valocidad;
    var intervalo;
    this.nIntervalo = 1;
    this.debug = false;

    /* Eventos */
    /**
     * Cambia el estado
     */
    this.encambioestado = function(){};

    this.setDiv = function (div){
        this.div = div;
    }
    this.mostrarDiv = function(){
        alert('el div es'+this.div.id);
    }

    this.tratar = function(op){
        this.estado = 1;
        this.encambioestado();
        var i =(op ==1)? 0:100;
        var maximo = (op ==1)? 100:0;
        //alert('i es'+i+', maximo es '+maximo);
        var div = this.div;
        var parent = this;
        var intervalo = setInterval(function(){

            /* DistinciÃ³n entre navegadores */
            if(navigator.appName == "Microsoft Internet Explorer"){
                div.style.filter = 'alpha(opacity='+i+')';
            }
            else{
                 div.style.MozOpacity = i/100;
            }

            if(parent.debug)document.title =  i;
            if(op==1)i=i+parent.nIntervalo;
            else i=i-parent.nIntervalo;
            condicion = (op ==1)?(i>maximo):(i<maximo);
            if(condicion){
                parent.estado = 2;
                parent.encambioestado();
                clearInterval(intervalo);
            }
        },10);

    }


    this.aparecer = function(){
        if(this.div == null){
            alert("No está¡ definida la DIV");
        }
        else{
            this.tratar(1);
        }
    }
    this.desaparecer = function(){
        if(this.div == null){
            alert("No estÃ¡ definida la DIV");
        }
        else{
            this.tratar(2);
        }
    }

}
