/*
 *
 * CLASE PARA VENTANA FLOTANTE
 *
*/


function InfoWindow(Nombre) {
	this.Name = Nombre;
	this.ImgPath = 'http://pics.miarroba.com/admin';
	this.txtAgent = navigator.userAgent.toLowerCase();
	this.IsIe = ((this.txtAgent.indexOf("msie")!==-1) && (this.txtAgent.indexOf("opera")===-1));
	if( this.IsIe ) {
			this.BrowserVer = parseInt(navigator.appVersion.split("MSIE")[1]);
	}
	this.Window = {
		'Obj':		false,
		'Content':	false,
		'Black':	false,
		'Opened':	false
	}
	this.WriteStyle();
}

InfoWindow.prototype = {
	/*
	 * Funcion que muestra la ventana
	 *
	 * @Param	object/string	Content		El objeto o el codigo HTML que hay que mostrar dentro.
	 * @Param	string			BackColor	Color base de la transparencia.
	 * @Param	Bool			Anim		Activar la animacion
	*/
	Open: function(Obj, BackColor, Anim, doOnLoad) {
		// Color de fondo por defecto
		if( typeof(BackColor)=='undefined' ) {
			BackColor = '#000000';
		}
		// Tenemos activada la animacion
		if( typeof(Anim)=='undefined' ) {
			Anim = false;
		}

		if( typeof(doOnLoad)=='undefined' ) {
			this.doOnLoad = false;
		} else {
			this.doOnLoad = doOnLoad;
		}

		// Tenemos la ventana creada?
		if( this.Window.Obj==false ) {
			this.CreateWindow();
		}
		// Solo cambiamos el contenido y colocamos la ventana si no se esta mostrando ya... por si hay algun error
		if( !this.Window.Opened ) {
			// Marcamos como abierto
			this.Window.Opened = true;
			// Quitamos el contenido anterior (si es que habia alguno...)
			this.Window.Content.innerHTML = '';
			// Ponemos el color de fondo de la cortina
			this.Window.Black.style.backgroundColor = BackColor;
			// Aņadimos el nuevo contenido
			if( typeof(Obj)=='object' ) {
				this.Window.Content.appendChild(Obj);
			} else {
				this.Window.Content.innerHTML = Obj;
			}
			// Algunas cosas para explorer 6 e inferiores
			if( this.IsIe && this.BrowserVer<7) {
				var Objs = document.getElementsByTagName('select');
				for( x=0;x<Objs.length;x++ ) {
					//if( Objs.propertyIsEnumerable(x) ) {
						Objs[x].style.visibility = 'hidden';
					//}
				}
			}

			// Agregamos el objeto fondo
			document.getElementsByTagName('body')[0].insertBefore(this.Window.Black, document.getElementsByTagName('body')[0].firstChild);

			if( Anim==false ) {
				this.DoAnimation(70);
				//document.getElementsByTagName('body')[0].insertBefore(this.Window.Obj, document.getElementsByTagName('body')[0].firstChild);
			} else {
				this.DoAnimation(1);
			}
		}
	},
	/*
	 * Animacion de la cortina ( de transparente a mas solido 0-80)
	 *
	 * @Param	number		x		Nivel actual
	*/
	DoAnimation: function(x) {
		this.DoTransparent(this.Window.Black, x);
		if( x==70 ) {
			document.getElementsByTagName('body')[0].insertBefore(this.Window.Obj, document.getElementsByTagName('body')[0].firstChild);
			if( this.doOnLoad ) {
				if( typeof(this.doOnLoad)=='function' ) {
					this.doOnLoad();
				} else {
					eval(this.doOnLoad);
				}
			}
		} else {
			x += 15;
			if( x>70 ) x=70;
			setTimeout(this.Name+'.DoAnimation('+x+')',0);
		}
	},
	/*
	 * Funcion que cierra la ventana
	*/
	Close: function() {
		if( this.Window.Obj && this.Window.Opened ) {
			this.Window.Obj.parentNode.removeChild(this.Window.Obj);
			this.Window.Black.parentNode.removeChild(this.Window.Black);
			// Algunas cosas para explorer 6 e inferiores
			if( this.IsIe && this.BrowserVer<7) {
				var Objs = document.getElementsByTagName('select');
				for( x=0;x<Objs.length;x++ ) {
					//if( Objs.propertyIsEnumerable(x) ) {
						Objs[x].style.visibility = 'visible';
					//}
				}
			}
			this.Window.Opened = false;
		}
	},
	/*
	 * Crea la el objeto ventana y todo el molde de dentro
	*/
	CreateWindow: function() {
		this.Window.Obj = document.createElement('table');
		this.Window.Black = document.createElement('div');
		var Tbody = document.createElement('tbody');
		var Tr = document.createElement('tr');
		this.Window.Content = document.createElement('td');
		Tr.appendChild(this.Window.Content);
		Tbody.appendChild(Tr);
		this.Window.Obj.appendChild(Tbody);
		this.Window.Obj.setAttribute('id', 'InfoWindowCortina');
		this.Window.Black.setAttribute('id', 'InfoWindowDivCortina');
		this.Window.Black.className = 'InfoWindowTransparent';				
	},
	/*
	 * Aplica una transparencia a un objeto
	 *
	 * @Param	object		Obj		El objeto al que le aplicamos la transparencia
	 * @Param	number		x		transparencia a aplicar
	*/
	DoTransparent: function(Obj, x) {
		Obj.style.opacity = (x/100);
		Obj.style.MozOpacity = (x/100);
		Obj.style.KhtmlOpacity = (x/100); 
		Obj.style.filter = 'alpha(opacity='+(x)+')';
	},
	/*
	 * Escribe todo el style que necesitamos
	*/
	WriteStyle: function() {
		var CSS = '<style type="text/css">';
		CSS += '	#InfoWindowCortina {\n';
		CSS += '		z-index:20001;\n';
		CSS += '		position:fixed;\n';
		CSS += '		top:0px;\n';
		CSS += '		left:0px;\n';
		CSS += '		width:100%;\n';
		CSS += '		height:100%;\n';
		CSS += '		border:0px;\n';
		CSS += '		margin:0px;\n';
		CSS += '		padding:0px;\n';
		CSS += '	}\n';
		CSS += '	#InfoWindowDivCortina {\n';
		CSS += '		z-index:20000;\n';
		CSS += '		position:fixed;\n';
		CSS += '		top:0px;\n';
		CSS += '		left:0px;\n';
		CSS += '		width:100%;\n';
		CSS += '		height:100%;\n';
		CSS += '		border:0px;\n';
		CSS += '		margin:0px;\n';
		CSS += '		padding:0px;\n';
		CSS += '		background-color:#000000;filter:alpha(opacity=0);opacity: 0;-moz-opacity: 0; -khtml-opacity: 0;\n';
		CSS += '	}\n';
		CSS += '\n';
		CSS += '	#InfoWindowCortina td {vertical-align:middle;text-align:center;}\n';
		CSS += '</style>\n';
		CSS += '<!--[if IE]>\n';
		CSS += '<style type=\"text/css\">\n';
		CSS += '	#InfoWindowCortina {\n';
		CSS += '		position:absolute;\n';
		CSS += '		top:expression(Math.max(document.body.scrollTop,document.documentElement.scrollTop));\n';
		CSS += '		left:expression(Math.max(document.body.scrollLeft,document.documentElement.scrollLeft));\n';
		CSS += '		width:expression( parseInt(document.documentElement.clientWidth)>0 ? document.documentElement.clientWidth : document.body.clientWidth );\n';
		CSS += '		height:expression( parseInt(document.documentElement.clientHeight)>0 ? document.documentElement.clientHeight : document.body.clientHeight );\n';
		CSS += '	}\n';
		CSS += '	#InfoWindowDivCortina {\n';
		CSS += '		position:absolute;\n';
		CSS += '		top:expression(Math.max(document.body.scrollTop,document.documentElement.scrollTop));\n';
		CSS += '		left:expression(Math.max(document.body.scrollLeft,document.documentElement.scrollLeft));\n';
		CSS += '		width:expression( parseInt(document.documentElement.clientWidth)>0 ? document.documentElement.clientWidth : document.body.clientWidth );\n';
		CSS += '		height:expression( parseInt(document.documentElement.clientHeight)>0 ? document.documentElement.clientHeight : document.body.clientHeight );\n';
		CSS += '	}\n';
		CSS += '</style>\n';
		CSS += '<![endif]-->\n';
		document.writeln(CSS);
	}
}