/*
Exemplo: <a href="javascript:void(0)" onclick="javascript:openWindow(800, 350, 'teste.html', 'Meu teste', 'silver');">teste</a>
Id da div contente: newWindowContent

////////////
Para inserir um procedimento no clique do botao fechar faça:
<script type="text/javascript">
	onBtnCloseClick(function({
		alert('Mensagem de teste ao clicar no botao fechar');
	}));
</script>

Obs.: Insira o scrip na página que será carregada!
------------------------------------------
*/
        var backWindow;
        var geralWindow;
        var shadow;
        var titleWindow;
        var _closeWindow;
        var contentWindow;
		        
        function closeWindow(){	
            $(geralWindow).slideUp();
            $(shadow).slideUp();
            $(backWindow).fadeOut();
			
			window.setTimeout(function(){
				$(geralWindow).remove();
				$(shadow).remove();
				$(backWindow).remove();
			}, 500);
        }
		
		function onBtnCloseClick(fn){
			_closeWindow.onclick = fn;
		}

        function openWindow(width, height, url, title, backgroundcolor){
            if(typeof url == 'undefined')
                alert('� necess�rio definir uma url');
            
            if(typeof title == 'undefined')
                title = "Untitled - " + url;

            if(typeof backgroundcolor == 'undefined')
                backgroundcolor = "#ececec";
				
            backWindow = document.createElement('div');
            $(backWindow).css({
                'position':'fixed',
                'top':'0',
                'left':'0',
                'right': '0',
                'bottom': '0',
                'width':'100%',
                'height':'100%',
                'background-color':'#000000',
                'opacity':'0.7',
                'filter':'alpha(opacity=70)',
                'display' : 'none'
            });
            document.body.appendChild(backWindow);


            shadow = document.createElement('div');
            $(shadow).css({
                'position':'fixed',
                'width':(width+2)+'px',
                'height':(height+2)+'px',
                'border':'0px solid',
                'left':'50.4%',
                'margin-left': -(width/2)+'px',
                'top':'50.4%',
				'margin-top': -(height/2)+'px',
                'float':'left',
                'display': 'none',
                'opacity':'0.25',
                'filter':'alpha(opacity=25)',
                'background-color':'black'
            });
            document.body.appendChild(shadow);

            geralWindow = document.createElement('div');		
            $(geralWindow).css({
                'position':'fixed',
                'width':width+'px',
                'height':height+'px',
                'border':'1px solid',
                'left':'50%',
                'margin-left': -(width/2)+'px',
                'top':'50%',
				'margin-top': -(height/2)+'px',
                'float':'left',
                'display': 'none',
                'z-index':'99'
            });
            document.body.appendChild(geralWindow);
            
            titleWindow = document.createElement('div');
            $(titleWindow).css({
                'text-align':'center',
                'width': (width-20)+'px',
                'background':'url(http://img188.imageshack.us/img188/986/pintetoe.png) repeat-x',
                'float':'left',
                'font-weight':'bold',
                'font-family': 'arial',
                'font-size' : '13px',
                'line-height':'20px',
                'height': '20px',
                'color':'white'
            });
            $(titleWindow).html(title);
            geralWindow.appendChild(titleWindow);

            _closeWindow = document.createElement('div');
            $(_closeWindow).css({
                'font-family':'arial',
                'background':'url(http://img188.imageshack.us/img188/986/pintetoe.png) repeat-x',
                'font-weight':'bold',
                'font-size':'13px',
                'text-align':'center',
                'width': '20px',
                'height': '20px',
                'line-height':'20px',
                'color':'white',
                'float':'left'
            });
            $(_closeWindow).html('<a href=\"javascript:void(0);\" onclick=\"javascript:closeWindow();\" style=\"text-decoration: none; color: blue; color: black;\" title=\"Fechar\">X</a>');
            geralWindow.appendChild(_closeWindow);

            contentWindow = document.createElement('div');
            $(contentWindow).attr('id', 'newWindowContent');
            $(contentWindow).css({
                'width': (width-3)+'px',
                'height': (height-20)+'px',
                'background-color':backgroundcolor,
                'overflow':'auto',
                'padding-left':'3px',
                'float':'left'
            });
			$(contentWindow).html("<center><b>Carregando. Aguarde...</b></center>");
            
			$.get(url, function(data){
                $(contentWindow).html(data);
            });

            geralWindow.appendChild(contentWindow);
            $(backWindow).fadeIn();
            $(geralWindow).slideDown();
            $(shadow).slideDown();

        }
