dojo.require("dojo.cookie");
dojo.declare("Floating",null,{
  content:false,
  width:300,
  height:200,
  modal:false,
  fixed:false,
  left:false,
  top:false,
  created:false,
  zIndex:10,
  hpos:'center',//center|left|right
  vpos:'center',//center|top|bottom
  distance:'10%',//caso não seja center, qual a distancia das bordas?
  cookieTime:0,//expire date do cookie, em segundos
  style:{'border':'1px solid #555','margin':'10px','backgroundColor':'white','overflow':'hidden'},
  constructor:function(args){
    dojo.mixin(this,args);
    dojo.addOnLoad(dojo.hitch(this,this.show));
  },
  show:function(){
  	if(this.cookieTime&&this.cookieTime>0){
  		var f=this;
  		var ck=dojo.cookie("banner_flutuante");
  		if(ck){return;}
  		else{dojo.cookie("banner_flutuante","true",{expires:f.cookieTime/(24*60*60)});}
  	}
    if(!this.created && this.content){
      this.box=dojo.doc.createElement('div');
      this.box.style.width=this.width+'px';
      this.box.style.height=this.height+'px';
      for(st in this.style){
        dojo.style(this.box,st,this.style[st]);
      }
      this.box.style.position=this.fixed?'fixed':'absolute';
      this.box.style.zIndex=this.zIndex+1;
      if(this.modal){
        this.bgall=dojo.doc.createElement('div');
        this.bgall.style.backgroundColor='black';
        dojo.style(this.bgall,'opacity','0.7');
        this.bgall.style.zIndex=this.zIndex;
        this.bgall.style.position='fixed';
        this.bgall.style.top='0px';
        this.bgall.style.left='0px';
        this.bgall.style.width='100%';
        this.bgall.style.height='100%';
        dojo.place(this.bgall,dojo.body(),'last');
      }
      if(this.top || this.left){
        this.box.style.top=this.top?this.top:'0px';
        this.box.style.left=this.left?this.left:'0px';
      } else {
          dojo.require("dijit._base.place");
          var vp = dijit.getViewport();
          if(this.hpos=='center'){
            this.box.style.left=Math.floor((vp.w-this.width)/2) + 'px';
          }else if(this.hpos=='left'){
            this.box.style.left=this.distance;
          }else if(this.hpos=='right'){
            this.box.style.right=this.distance;
          }
          if(this.vpos=='center'){
            this.box.style.top=Math.floor((vp.h-this.height)/2) + 'px';
          }else if(this.vpos=='top'){
            this.box.style.top=this.distance;
          }else if(this.vpos=='bottom'){
            this.box.style.bottom=this.distance;
          }
      }

      if(this.content.lastIndexOf('swf') == this.content.length - 3){
        this.box.innerHTML='<object width="100%" height="100%" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0"><param name="wmode" value="opaque"><param name="movie" value="'+this.content+'" /><embed src="'+this.content+'" wmode="opaque" width="100%" height="100%" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" /></object>';
      }else{
        this.box.innerHTML='<img src="'+this.content+'" width="100%" height="100%" />';
      }

      this.close=dojo.doc.createElement('div');
      this.close.style.position='absolute';
      this.close.style.right='0px';
      this.close.style.top='0px';
      this.close.style.backgroundColor='#555';
      this.close.style.padding='2px';
      this.close.style.color='white';
      this.close.style.fontFamily='verdana';
      this.close.style.fontSize='11px';
      this.close.innerHTML='FECHAR X';
      this.close.style.cursor='pointer';
      dojo.connect(this.close,'onclick',dojo.hitch(this,this.hide));

      dojo.place(this.box,dojo.body(),'last');
      dojo.place(this.close,this.box,'last');
      this.created=true;
    }
  },
  hide:function(){
    this.box.style.display='none';
    if(this.bgall){
      this.bgall.style.display='none';
    }
  }
}
);
