var Banner=Class.create(ContentControler.prototype,
{
init:function(template,element,data)
{
this.sup(template,element,data,"init");
this.type="Banner";
},
getSupportParameters:function()
{
with(this)
{
var p=sup("getSupportParameters");
return $.extend(p,
{
Link:DataAccessInterface.sources.Banner.click+"?Id="+data.Id,
ThumbUrl:THUMB_URL,
Altura:data.Zona.Altura,
Largura:data.Zona.Largura,
Target:data.PermaLink.indexOf(RESOLVE_URL)>-1?"":"target='_blank'"
});
}
},
getTemplate:function()
{
with(this)
{
return $.template(template[data.Tipo]);
}
},
render:function(t)
{
with(this)
{
var d=getTemplateData();
sup(t,"render");
if(d.Tipo=='Flash'&&d.Zona.Codigo!="home_destaque_01_469x287")
{
var params={wmode:"transparent",allowScriptAccess:"always"};
var atts={id:d.Id};
swfobject.embedSWF(window.MEDIACENTER_FLASH_URL+'/images/'+d.Arquivo,
'bannerFlash_'+d.Id,d.Largura.toString(),d.Altura.toString(),"8.0.0",false,{clickurl:d.Link},params,atts);
}
if(d.Zona.Codigo=="home_destaque_01_469x287")
{
$("#bannerFlash_"+d.Id).data("json",d);
}
}
}
});
var Banners=Class.create(ContentList.prototype,
{
initProperties:function(template,element,externalInterface,data){
this.sup(template,element,externalInterface,data,"initProperties");
this.type="Banners";
this.hasMany=Banner;
},
load:function(params){
var defaultParams={q:1,z:this.zona};
this.sup($.extend(defaultParams,params),"load");
},
montar:function(){
with(this){
if(template.cols!=null){
this.renderer=new ColsRenderer(this);
renderer.render();
}
else{
sup("montar");
}
if(this.data.Banners.length>0){
if(this.data.Banners[0].Zona.Codigo=="home_destaque_01_469x287"){
this.skin=$("div.skin"),
this.highlights=$("div.flashHome ul li",skin),
this.btNext=$(".bt_next",skin),
this.btPrev=$(".bt_prev",skin),
this.changeAdOn=false,
this.pagination;
!highlights.is(".ativo")
&&highlights.eq(0).addClass("ativo");
this.buildPagination();
this.changeView();
this.changeInTime();
btNext.add(btPrev).click(function(){
if(changeAdOn)
return false;
var method=$(this).is(".bt_prev ")?"prev":"next",
active=highlights.filter(".ativo"),
index=highlights.index(active[method]("li"));
changeAdOn=true;
active[method]("li").length
&&changeView(index);
return false;
});
}
}
}
},
changeButtons:function(){
var active=this.highlights.filter(".ativo"),
buttons={prev:this.btPrev,next:this.btNext};
for(button in buttons){
buttons[button][!active[button]("li").length?"addClass":"removeClass"]("disabled");
$.browser.msie
&&buttons[button][!active[button]("li").length?"hide":"show"]();
}
return true;
},
changeView:function(nindex){
var index=nindex||0,
active=this.highlights.filter(".ativo"),
activeIndex=this.highlights.index(active),
actual=active.removeClass("ativo").end()
.eq(index).addClass("ativo"),
type=actual.attr("rel"),
$this=this,
d,elem,url;
this.highlights.parent().animate({left:(index*469)*-1},1000,function(){
$this.changeAdOn=false;
});
this.changePagination(index);
this.changeButtons();
if(type=="image"){
actual.find("img").attr("src",actual.find("img").attr("temp"))
}
else if(type=="flash"){
url=actual.text();
elem=actual.find("div")
d=elem.data("json");
swfobject.embedSWF(window.MEDIACENTER_FLASH_URL+'/images/'+d.Arquivo,elem.attr("id"),d.Largura.toString(),d.Altura.toString(),"8.0.0","",
{
clickurl:d.Link
},
{
menu:"false",
scale:"noscale",
wmode:'transparent',
allowScriptAccess:'always',
allowfullscreen:'true'
},
{
salign:'t',
wmode:'transparent'
}
);
}
actual.removeAttr("rel");
if(index){
clearInterval(this.time);
this.changeInTime();
}
return true;
},
changePagination:function(index){
!$.browser.msie
&&this.pagination.parent().eq(index)
.addClass("ativo")
.siblings(".ativo")
.removeClass("ativo");
return true;
},
buildPagination:function(){
var lis='<ul class="pagination">',
$this=this;
for(var i=0;i<this.highlights.length;i++){
lis+='<li><a href="#">'+i+'</a></li>';
}
this.pagination=$(lis+"</ul>").insertAfter(this.btNext)
.find("li:first").addClass("ativo").end()
.find("li a")
.click(function(){
if($this.changeAdOn||$(this).parent().is(".ativo"))
return false;
$this.changeAdOn=true;
var index=$this.pagination.parent().index($(this).parent());
$this.changeView(index);
return false;
})
.addClass("png");
$.browser.msie&&this.pagination.parents("ul").find(".ativo").removeClass("ativo")
&&$.browser.version=="6.0"
&&DD_belatedPNG.fix(".png");
},
changeInTime:function(){
var $this=this,
next,index;
this.time=setInterval(function(){
next=$this.highlights.filter(".ativo").next();
index=next.length
?$this.highlights.index(next)
:0;
$this.changeView(index);
},13000);
},
displayEmpty:function(){}
});
Banners.reg=new Array();
Banners.fromZone=function(z,template,element,externalInterface,data)
{
if(Banners.reg[z]==null)
{
Banners.reg[z]=new Banners(template,element,externalInterface,data);
Banners.reg[z].zona=z;
}
return Banners.reg[z];
};
