$(document).ready(function(){if($('#outlet-hero').length>0){window.outletHero=new SuperHero($('#outlet-hero'),true);}});var SuperHero=function(container,autoplay){var self=this;var timer=null;this.panels=new Array();this.currentIndex=0;var flashPlayerVersion=swfobject.getFlashPlayerVersion();this.hasFlash=(flashPlayerVersion&&flashPlayerVersion.major>=8?true:false);this.callBackFn=null;this.init=function(){$('.panel',container).each(function(i){var duration=Number($(this).attr('data-img-duration'));var swfDuration=Number($(this).attr('data-swf-duration'));var imgSrc=$(this).attr('data-img');var swfSrc=$(this).attr('data-swf');var type='image';var altText=$('a',this).text();var date=new Date();var id='hero'+i+date.getTime();$('a',this).attr('id',id).css('background-image','url('+imgSrc+')');if(swfSrc){if(self.hasFlash){$(this).addClass('flashContent');type='flash';var flashvars={};var autoplay=(i==0?'true':'false');var params={wmode:'opaque',play:autoplay,allowScriptAccess:'always'};var attributes={id:id,name:id};swfobject.embedSWF(swfSrc,id,'196','197','9','',flashvars,params,attributes);duration=swfDuration;}}
self.panels.push({elem:this,duration:duration,type:type,id:id});}).eq(0).addClass('show');self.buildControls();if(autoplay){self.play();}
container.removeClass('loading');}
this.setCallBack=function(fn){this.callBackFn=fn;}
this.buildControls=function(){var controls;if(autoplay){controls=$('<div class="controls"><div class="pagination"></div><a class="button btnPause" href="#">Play/Pause</a></div>');}
else{controls=$('<div class="controls"><div class="pagination"></div><a class="button btnPlay" href="#">Play/Pause</a></div>');}
for(var i=0;i<self.panels.length;i++){$('<a href="#">'+(i+1)+'</a>').appendTo($('.pagination',controls));}
$('.pagination a',controls).eq(0).addClass('selected');$('.button',controls).click(function(){if($(this).hasClass('btnPlay')){self.play();}
else if($(this).hasClass('btnPause')){self.pause();}
return false;});$('.pagination a',controls).click(function(){var index=Number($(this).text())-1;self.pause();self.gotoIndex(index,true);return false;});container.append(controls);}
this.next=function(){var nextIndex=self.currentIndex+1;if(self.currentIndex==(self.panels.length-1))nextIndex=0;if(nextIndex==0&&self.callBackFn!=null){self.gotoIndex(nextIndex,false);}
else{self.gotoIndex(nextIndex,true);var duration=self.panels[nextIndex].duration*1000;self.timer=setTimeout(self.next,duration);}}
this.gotoIndex=function(nextIndex,rewind){if(self.currentIndex==nextIndex)return false;var currentPanel=self.panels[self.currentIndex].elem;var nextPanel=self.panels[nextIndex].elem;$(currentPanel).fadeOut().removeClass('show');if(!rewind){self.callBackFn();$(nextPanel).show();}
else{$(nextPanel).fadeIn(750,function(){$(this).addClass('show');if(self.panels[nextIndex].type=='flash'){var id=self.panels[nextIndex].id;document.getElementById(id).Play();}});}
self.currentIndex=nextIndex;$('.pagination a',container).removeClass('selected').eq(nextIndex).addClass('selected');}
this.play=function(){var currentPanel=self.panels[self.currentIndex];var duration=currentPanel.duration*1000;self.timer=setTimeout(self.next,duration);$('.controls .button',container).removeClass('btnPlay').addClass('btnPause');}
this.pause=function(){clearTimeout(self.timer);$('.controls .button',container).removeClass('btnPause').addClass('btnPlay');}
this.init();}
