function FloatingWindow(urlImagens)
{
	this.Init(urlImagens);
}

FloatingWindow.prototype = {
	popupName:'FloatingWindow',
	TitleBarName:'titleBar',
	urlImagens:'',
	ImagensAlteradas:'',
	
	InitMove:function()
	{
		Drag.init(document.getElementById(this.TitleBarName), document.getElementById(this.popupName));
		this.ImagensAlteradas = new Array();
	},
	
	ToggleFloatingLayer:function(iState)
	{
		this.centerLayers();
		
		if(document.layers) {
			document.layers[this.popupName].visibility = iState ? "show" : "hide";
		} else if(document.getElementById) {
			var obj = document.getElementById(this.popupName);
			obj.style.visibility = iState ? "visible" : "hidden";
		} else if(document.all) {
			document.all[this.popupName].style.visibility = iState ? "visible" : "hidden";
		}
	},
	
	centerLayers:function()
	{
		var ie5 = document.all&&document.getElementById;
		var ns6 = document.getElementById&&!document.all;
		
		var winWidth = ns6? window.innerWidth-20 : this.iecompattest().clientWidth;
		var winHeight = ns6? window.innerHeight-20 :this.iecompattest().clientHeight;
		
		var popupWidth		= document.getElementById(this.popupName).style.width;
		var popupWidth		= popupWidth.substr(0,popupWidth.length-2);
		var popupHeight 	= document.getElementById(this.popupName).style.height;
		var popupHeight		= popupHeight.substr(0,popupHeight.length-2);
		
		var winX = Math.ceil((winWidth - popupWidth) / 2);
		var winY = Math.ceil((winHeight - popupHeight) / 2);
		
		document.getElementById(this.popupName).style.left = winX + 'px';
		document.getElementById(this.popupName).style.top = (this.scrollY() + winY) + 'px';
	},
	
	iecompattest:function()
	{
		return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
	},

	scrollY:function()
	{
		var scrolledY = 0;
		var ie5 = document.all&&document.getElementById;
		var ns6=document.getElementById&&!document.all;
		
		if (ns6) {
			scrolledY = window.pageYOffset;
		} else {
			scrolledY = document.body.scrollTop;
		}
		
		return scrolledY;
	},
	
	abrePopup:function(url,titulo)
	{
		this.fechaPopup();
		
		document.getElementById(this.TitleBarName).innerHTML = titulo;
		window.FloatingLayerContent.location = url;
		return;
	},
	
	getConteudo:function()
	{
		if (window.FloatingLayerContent.location != 'about:blank') {
			var largura = parseInt(window.FloatingLayerContent.document.body.scrollWidth);
			var altura = parseInt(window.FloatingLayerContent.document.body.scrollHeight);
			var w = largura;
			var h = altura;		
			var scroll = false;
			
			var standardbody = (window.FloatingLayerContent.document.compatMode=="CSS1Compat") ? window.FloatingLayerContent.document.documentElement : window.FloatingLayerContent.document.body;
			var ff = document.getElementById&&!document.all;
			
			w += 20;
			h += 49;
			
			if (w < 250) {
				w = 250;				
			}

			if (h >= this.iecompattest().clientHeight) {
				h = parseInt(this.iecompattest().clientHeight) - 20;
				scroll = true;
			}
			
			if (scroll) {
				w += 20;
			}

			if (ff)
				h += 1;
					
			document.getElementById(this.popupName).style.width = w + 'px';
			document.getElementById(this.popupName).style.height = h + 'px';			
			
			/*if (ff)
				standardbody.style.overflow = 'auto';
			else
				standardbody.style.overflow = 'hidden';*/
				if (ff) {
					standardbody.style.overflow = 'auto';
				} else {
					standardbody.style.overflowY = 'auto';
					standardbody.style.overflowX = 'hidden';
				}
			
			this.ToggleFloatingLayer(1);
		}		
	},
	
	fechaPopup:function()
	{
		document.getElementById(this.TitleBarName).innerHTML = '';
		document.getElementById(this.popupName).style.width = '1px';
		document.getElementById(this.popupName).style.height = '1px';
		
		window.FloatingLayerContent.location = 'about:blank';
		this.ToggleFloatingLayer(0);
		return;
	},
	
	applyCssHack:function()
	{
		var supported = /MSIE (5\.5)|[6]/.test(navigator.userAgent) && navigator.platform == "Win32";
		
		if (supported) {//document.all.length
		var i;
			for (i=0; i<document.getElementsByTagName('*'); i++) {
				if (document.all[i].currentStyle) {
					var bg = document.all[i].currentStyle.backgroundImage;
					if (bg) {
						if (bg.match(/\.png/i) != null) {
							var mypng = bg.substring(5,bg.length-2);
							document.all[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+mypng+"', sizingMethod='scale')";
							document.all[i].style.backgroundImage = "URL('" + this.urlImagens + "transparent.gif')";
							this.ImagensAlteradas.push(mypng);
						}
					}
				}				
			}
			
			this.applyCSSHack2();
		}
	},
	
	seachInImagens:function(query)
	{
		for (var k = 0; k < this.ImagensAlteradas.length; k++) {
			if (query == this.ImagensAlteradas[k])
				return true;
		}
		
		return false;
	},
	
	applyCSSHack2:function()
	{//document.all.length
		for(var i=0; i < document.getElementsByTagName('*'); i++) {
			var img = document.all[i];
			if (img.src) {
				var imgName = img.src.toUpperCase();
				if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
					if (!this.seachInImagens(img.src)) {
						var Teste = new Image();
						Teste.src = img.src;
						
						if (Teste.src.indexOf("top_close.png") != -1) {
	//Teste.width = LARGURA_DA_IMG + 'px';
	//Teste.height = ALTURA_DA_IMG + 'px';
}

						var imgID = (img.id) ? "id='" + img.id + "' " : "";
						var imgClick = (img.onclick) ? 'onClick="' + this.trataFunction(img.onclick.toString()) + '" ' : "";
						var imgClass = (img.className) ? "class='" + img.className + "' " : "";
						var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
						var imgStyle = "display:inline-block;" + img.style.cssText;
						if (img.align == "left") imgStyle = "float:left;" + imgStyle;
						if (img.align == "right") imgStyle = "float:right;" + imgStyle;
						if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
						var strNewHTML = 
						"<div " + imgID + imgClass + imgTitle + imgClick
						+ " style=\"" + "width:" + Teste.width + " px; "
						+ "height:" + Teste.height + "px;" + imgStyle + ";"
						+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
						+ "(src=\'" + img.src + "\', sizingMethod='scale'); background-image:url('" + this.urlImagens + "transparent.gif');\"></div>";
						img.outerHTML = strNewHTML;
						i = i--;
					}
				}
			}
		}
	},
	
	trataFunction:function(funcao)
	{
		var texto = funcao.replace(/function anonymous()/g, '');
		texto = texto.replace(/{/g, '');
		texto = texto.replace(/}/g, '');
		texto = texto.replace(/\r/g, '');
		texto = texto.replace(/\n/g, '');
		
		return texto.substr(2);
	},
	
	drawWindow:function()
	{
		var htmlPopup = '<div id="' + this.popupName + '" style="position:absolute; left:0px; top:0px; visibility:hidden; width:1px; height: 1px; z-index:100000;">';
		htmlPopup += '<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"><tr><td>';
		htmlPopup += '<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr>'
		htmlPopup += '<td width="17" background="' + this.urlImagens + 'top_left.png"><img src="' + this.urlImagens + 'top_left.png" width="17" height="39" style="visibility:hidden;"></td>';
		htmlPopup += '<td width="20" background="' + this.urlImagens + 'top_logo.png"><img src="' + this.urlImagens + 'top_logo.png" width="20" height="39" style="visibility:hidden;"></td>';
		htmlPopup += '<td width="100%" background="' + this.urlImagens + 'top_bg.png" style="cursor:move; padding-top:7px; font-weight:bold; font-size:9.5px; color:#FFFFFF;" id="' + this.TitleBarName +'"></td>';
		htmlPopup += '<td width="19"><img src="' + this.urlImagens + 'top_close.png" alt="Fechar" width="25" height="39" border="0" style="cursor:pointer;" onClick="FloatingWindow.fechaPopup()"></td>';
		htmlPopup += '<td width="17" background="' + this.urlImagens + 'top_right.png"><img src="' + this.urlImagens + 'top_right.png" width="17" height="39" style="visibility:hidden;"></td>';
		htmlPopup += '</tr></table></td>';
		htmlPopup += '</tr><tr>';
		htmlPopup += '<td height="100%" width="100%">';
		htmlPopup += '<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"><tr>';
		htmlPopup += '<td width="10" height="100%" background="' + this.urlImagens + 'middle_left.png"><img src="' + this.urlImagens + 'middle_left.png" width="10" height="44" style="visibility:hidden;"></td>'
		htmlPopup += '<td height="100%" width="100%" style="background-color:#F9F9F9;"><iframe name="FloatingLayerContent" allowtransparency="false" id="FloatingLayerContent" src="about:blank" width="100%" height="100%" style="width:100%; height:100%;" frameborder="no" onload="FloatingWindow.getConteudo()"></iframe></td>'
		htmlPopup += '<td width="10" height="100%" background="' + this.urlImagens + 'middle_right.png"><img src="' + this.urlImagens + 'middle_right.png" width="10" height="44" style="visibility:hidden;"></td>'
		htmlPopup += '</tr></table></td>';
		htmlPopup += '</tr><tr>';
		htmlPopup += '<td width="100%">';
		htmlPopup += '<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr>';
		htmlPopup += '<td width="17" background="' + this.urlImagens + 'bottom_left.png"><img src="' + this.urlImagens + 'bottom_left.png" width="17" height="10" style="visibility:hidden;"></td>'
		htmlPopup += '<td width="100%" background="' + this.urlImagens + 'bottom_bg.png"><img src="' + this.urlImagens + 'bottom_bg.png" width="17" height="10" style="visibility:hidden;"></td>'
		htmlPopup += '<td width="17" background="' + this.urlImagens + 'bottom_right.png"><img src="' + this.urlImagens + 'bottom_right.png" width="17" height="10" style="visibility:hidden;"></td>'
		htmlPopup += '</tr></table></td>';
		htmlPopup += '</table>';
		htmlPopup += '</div>';
		
		document.write(htmlPopup);
	},
	
	Init:function(url)
	{
		this.urlImagens = url;
		this.drawWindow();
		this.InitMove();
		this.applyCssHack();
	}
}