/** 
	@author: wagner renzi 
	funções relacionadas a adaptação do blig para domínios ig, ou seja, http://www.ig.com.br/<dominio>
**/


  //seta domínio do documento
	document.domain = "ig.com.br";

	//include de funções principais do blig
	document.write('<scr'+'ipt type="text/javascript" src="http://blig.ig.com.br/js/funcoes_templates.js"></scr'+'ipt>');

	// Esta variavel é responsavel por abrir ou não em _top os link's dos arquivos (Default false quando usado na capa)
    var arqIMpBliG = false;

  //recupera paramentos da string passada
	function getURLParam(param,strOr)
	{
	    var param = "[\?&]"+param+"=([^&#]*)";  
	    var tmpEx = (new RegExp(param)).exec(strOr);
	    return (tmpEx == null ? "":tmpEx[1]);
	}

	//monta frame para o inner blig
  function montaIFrameBliG(param){
     param['end_src']  = "";
     houveAlter = false;   
     loc = window.location.href;
     if (act = getURLParam("act",loc)){
        switch (act){
          case "lkpost":
			if (getURLParam("arquivohtml",loc)!="")
			{
	            param['src_blig_zes']  = param['src_blig_zes'] + getURLParam("arquivohtml",loc)+".html";
	            param['end_src'] = "#" + getURLParam("postanch",loc);
			} 
			else
			{
	            param['src_blig_zes']  = param['src_blig_zes'] + "index.html";
	            param['end_src'] = "#" + getURLParam("postanch",loc);
			}
          break;
          case "arquivo":
            param['src_blig_zes']  = param['src_blig_zes'] + getURLParam("arquivodata",loc)+".html";
          break;
        }       
        houveAlter = true;
     }

    param['src_blig_zes'] = param['src_blig_zes'] + ((param['src_blig_zes'].indexOf("?")!= -1)?"&":"?")+ "ext=true";
    
    //tem que estar no domínio ig, senão zera o source
    if (window.location.href.toString().indexOf("ig.com.br/")==-1){param['src_blig_zes']="";}

    document.write('<iframe frameborder="0" '+
    						' scrolling="no" '+
    						' class="ifrPaiBliGEstilo" '+
    						' name="ifrPaiBliG" '+
    						' id="ifrPaiBliG" '+
    						' src="'+param['src_blig_zes']+'" '+
    						' width="'+param['largura']+'" '+
    						' height="50000">Seu browser não pode exibir iframes</iframe>'); //altura inicial, depois o iframe se auto-redimensiona (correção / bug firefox)
  }
    

  //trata o arquivo do blig para ser apresentado na capa do outter blig
  function montaArquivoCapa(urlcapa){
	  if(objs = document.getElementById("arquivo_container").getElementsByTagName("A")){
	    for (i=0; i<objs.length; i++){
	      fnl = "index";
	      if(objs[i].href.indexOf(fnl+".html") == -1){
	        pos = objs[i].href.indexOf(".html");
	        fnl = objs[i].href.substring(pos-7).substring(0,7);
	      }
	      objs[i].href = urlcapa+"?act=arquivo&arquivodata="+fnl;
	      
	      if(arqIMpBliG) {
            objs[i].target = "_top";
		  }
	    }
	  }
	}

	//envio amigo exclusivo para outter blig
	function abreEnvioAmigoOutter(id_post, perma){
		urlWO = location.href;
	 	if ((ind = urlWO.indexOf("?ext=true")) != -1){
	 		urlWO = urlWO.substring(0,ind-1);
	 	}
	 	perma = unescape(perma); perma = escape(perma);
	 	janela = window.open('http://blig.ig.com.br/envia_amigo.php?url='+urlWO+'&id_post='+id_post+'&permalink='+ perma,'popEnvioAmigo','width=300,height=360'); 
	}

	//redimensiona blig
	function chRedimOutter(){
		if(obj = parent.document.getElementById('ifrPaiBliG')) {
			alturaBlig = document.getElementById('containerHTMLBliG').offsetHeight;
			
			document.getElementById('containerHTMLBliG').style.height = alturaBlig;
			obj.height = alturaBlig;
			
			 setTimeout(function() {
				 obj.src = top.paramsBliG['src_blig_zes'] + "#" + top.getURLParam("postanch",top.location.toString());
			 }, 1000);
		}
	}

	//caso ele reconhecer que está no miolo blig, redireciona para capa
   	function confereCapaBliG(pathCapa){
  		capa = false;
  		toploc = top.location.toString();
  		if (toploc.indexOf(".blig.ig.com.br") != -1){
			capa=true;
			urlPart = toploc.substr(toploc.indexOf( "/",7),toploc.length);
			if(urlPart!='')
			{
				urlPart = urlPart.substring(0,(urlPart.length-5));
				pathCapa += "?act=lkpost&arquivohtml="+urlPart+"&postanch=&ext=true";
			}
  		}else if (toploc.indexOf("http://z00") != -1){
			capa=true;
			if ((posPost = toploc.indexOf("#post_")) != -1){
				postDados = (toploc.substring(posPost-12)).split("#");
				pathCapa += "?act=lkpost&arquivohtml="+postDados[0]+"&postanch="+postDados[1]+"&ext=true";
			}
  		}
  		if(capa){
    		top.location.replace(pathCapa);
      	}
  	}
  
 
    //monta aviso de atualização no header da capa
	function montaAvisoRSS(paramsAviso){
	  avisoRSS  = '<link rel="alternate" type="text/xml" title="RSS .92" href="'+paramsAviso['src_blig_zes']+'/rssposts.xml" />';
	  avisoRSS += '<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="'+paramsAviso['src_blig_zes']+'/rssposts.xml" />';
	  document.write(avisoRSS);
	}