/*
**************
* PPupInLoad
*   2009
* PP Studio
**************

Usage :
    window.onload = function(){
      PPup.Load(ElementID, largura, altura);
    }
*/

// NÃO COMPACTADO
var
d=document,
PP$=function(i){return d.getElementById(i)},
PPS=function(a,b,c){PP$(a).style.b=c},
PPup={
  div:'PPupInLoad',
  intervalo:null,
  x:0,

  El:function(){
        var html = "<div id=\"PPupInLoad\" class=\"PPupInLoad\"><div id=\"PPFecha\" title=\"Fechar\" class=\"fecha fr\">X</div><div id=\"tl\" class=\"tl\"></div><div id=\"tr\" class=\"tr\"></div><div id=\"PPupBody\" class=\"corpo cb\"></div><div id=\"bl\" class=\"bl\"></div><div id=\"br\" class=\"br\"></div></div>";
        return html;
  },

  Transparenta:function(){
        PP$('PPupBody').style.marginTop = '-16px';
        PP$('PPupBody').style.backgroundColor = 'transparent';
        PP$('tl').style.display = 'none';
        PP$('tr').style.display = 'none';
        PP$('bl').style.display = 'none';
        PP$('br').style.display = 'none';
  },

  Resizar:function(w,h){
        var
        p   = 'px',
        m   = '-',
        lef = w/2,
        top = (h/2)+25;

        PP$('tl').style.width       = w-11;
        PP$('bl').style.width       = w-11;
        PP$(this.div).style.width      = w+p;
        PP$(this.div).style.height     = h+p;
        PP$(this.div).style.marginLeft = m+lef+p;
        PP$(this.div).style.marginTop  = m+top+p;
  },

  Carregar:function(DiD){
        var hte = PP$(DiD).innerHTML;
        if(!this.x){
          var el = this.El();
          d.body.innerHTML += el;
          PP$('PPupBody').innerHTML = hte;
        }else{
          PP$('PPupBody').innerHTML = hte;
        }

    	$('#PPFecha').click(function(){
    		PPup.Fechar();
    	});
  },

  Mostrar:function(){
        $("#"+this.div).fadeIn("slow");
        //$("#"+this.div).show();
  },

  Fechar:function(){
        $("#"+this.div).fadeOut("slow");
        this.setCookie("promo", "sim", 1);
        PP$('Protext').style.display = "block";
        //$("#"+this.div).hide();
        this.x = 1;
  },

  Clica:function(){
        this.setCookie("promo", "sim", 1);
  },

  setCookie:function(c_name,value,expiredays){
        var exdate = new Date();
        exdate.setDate(exdate.getDate()+expiredays);
        //document.cookie = c_name + "=" + escape(value)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
        document.cookie = c_name + "=" + escape(value)+";expires=";
  },

  getCookie:function(c_name){
        if (document.cookie.length>0){
          c_start=document.cookie.indexOf(c_name + "=");
          if (c_start!= -1){
            c_start=c_start + c_name.length+1;
            c_end=document.cookie.indexOf(";",c_start);
            if (c_end == -1){c_end=document.cookie.length;}
            return unescape(document.cookie.substring(c_start,c_end));
            }
          }
        return "";
  },

  Loader:function(i,w,h,t){
        this.Carregar(i);
        if(t=='transparent'){this.Transparenta()}
        this.Resizar(w,h);
        this.Mostrar();
        clearInterval(this.intervalo);
  },

  Load:function(i,w,h,t){
        if(this.getCookie("promo") == "sim"){
            PP$('Protext').style.display = "block";
            return false;
        }else{
            this.intervalo = window.setInterval(function(){PPup.Loader(i,w,h,t)}, 1000);
        }
  }
};