/**
 * @author rnogueira@uolinc.com
 * @projectDescription Exibir um layer com informações sobre a estação para o usuário que veio de um determinado endereço
 */
layerInfoInternautaJS = {

  HTML_HEAD : document.getElementsByTagName('head')[0],
  HTML_DIV : document.createElement("div"),
  textoSel : "",
  texto : {
    uolnews :  "\
        <div class=\"texto\"><p>\
          <strong>Caro internauta,</strong><br /><br />\
          Você está prestes a entrar no novo <strong>UOL Notícias</strong>.\
          A nova central de jornalismo do portal nasce da <strong>fusão</strong> dos \
          antigos <strong>UOL News</strong> e <strong>UOL Últimas Notícias</strong>. Reúne as \
          principais notícias do Brasil e do mundo em textos, fotos, blogs, \
          vídeos e infográficos. Traz também atalhos para serviços como \
          cotações, previsão do tempo, trânsito e horóscopo. <br /><br />\
          Os <strong>vídeos</strong> que você estava acostumado a encontrar no \
          UOL News continuam disponíveis. Basta clicar o <strong>segundo item \
          do menu</strong> de navegação: <strong>Vídeos</strong>.\
        </p></div>\
        <a href=\"http://noticias.uol.com.br/ultnot/infografico/2008/05/20/ult3224u71.jhtm\" class=\"saibaMais\">Saiba mais sobre a nova estação de notícias do UOL</a>\
    ",
    ultnot :  "\
        <div class=\"texto\"><p>\
          <strong>Caro internauta</strong>,<br /><br />\
			O UOL Notícias passa a publicar todo o conteúdo do UOL Mídia Global em sua editoria de Internacional. Com navegação unificada, agora é possível encontrar, em um mesmo ambiente, textos traduzidos das principais e mais prestigiadas publicações do mundo, notícias internacionais em tempo real, vídeos e comentários. O conteúdo antigo de UOL Mídia Global continua à disposição. <br /><br />\
			Obrigado,<br /><br />\
			UOL Notícias\
			</p></div>\
    "
  },
  
  init : function(){
  	var nova = '';
  	re = new RegExp("(fromUolnews|fromUltnot)=([^&]+)");
  	try{nova=re.exec(document.location)[2]}catch(e){}
  	if(nova=='' || nova < (new Date()).getTime()-60*1000) return;
  	//alert(re.exec(document.location)[2]);
    if (re.exec(document.location)[1] == 'fromUltnot') {
    	this.textoSel = this.texto.ultnot;
	    this.importarDependencias();
    }
    else if (re.exec(document.location)[1] == 'fromUolnews') {
    	this.textoSel = this.texto.uolnews;
	    this.importarDependencias();
    }
    this.createElements();
    this.show();
  },

  importarDependencias : function(){
    if (typeof FullOpacity == "undefined") {
      var HTML_SCRIPT = document.createElement("script");
      HTML_SCRIPT.src="http://lib.uol.com.br/fullopacity/fullopacity.js";
      this.HTML_HEAD.appendChild(HTML_SCRIPT);
    }
  },
  
  createElements : function(){
    this.HTML_DIV.id="layerInfoInternauta";
    this.HTML_DIV.innerHTML="\
      <div class=\"layerInfoInternautaConteudo\">\
        <img src=\"http://n.i.uol.com.br/layer-noticia-titulo.gif\" border=\"0\" />\
        <a href=\"javascript:FullOpacity.hide();\" class=\"btFechar\"><img src=\"http://n.i.uol.com.br/layer-noticia-bt-fechar.gif\" border=\"0\" /></a>"+this.textoSel+"\
      </div>";
    this.append();
  },
  
  /**
   * Insere após ter carregado o primeiro node dentro do elemento body, feito para evitar bug no IE
   */
  append : function(){
    if(document.getElementsByTagName("body").length>0 && document.getElementsByTagName("body")[0].childNodes[0].parentNode)
      document.getElementsByTagName("body")[0].childNodes[0].parentNode.insertBefore(this.HTML_DIV,document.getElementsByTagName("body")[0].childNodes[0]);
    else
      setTimeout(function(){
        layerInfoInternautaJS.append();
      },1000);
  },
  
  /**
   * Exibe o layer utilizando o FullOpacity apenas se o script "FullOpacity" e o elemento de id "layerInfoInternauta" existirem
   */
  show : function(){
    if (typeof FullOpacity != "undefined" && document.getElementById("layerInfoInternauta"))
       FullOpacity.show("layerInfoInternauta");
    else
       setTimeout(function(){
         layerInfoInternautaJS.show();
       },1000);
  }

}
layerInfoInternautaJS.init();
