/*
 * Rotating Ad scripts 0.1
 * Copyright(c) 2010, Servigistics.
 * 
 */


RotatingAd=function(_1,_2,_3,_4,_5,_6,_7,_8,_9,_a){this._parentAdId=_1;this._langCode=_2;this._location=_3;this._duration=_4;this._showNav=_5;this._boundAds=_6;this._shownContainerId=_7;this._hiddenContainerId=_8;this._navContainerId=_9;this._showErrors=_a;RotatingAd.superclass.constructor.call(this);};Ext.extend(RotatingAd,Ext.util.Observable,{_gatewayUrl:"json.php?target=ads_gateway",_gatewayGetMethod:"&method=getAdHtml",_currentAdIndex:0,_timeoutId:null,_adsAdded:{},play:function(){if(this._adsAdded[this._boundAds[this._currentAdIndex].adId]){this._prepareAd(this._adsAdded[this._boundAds[this._currentAdIndex].adId]);this._setNextAdTimeout();}else{Ext.Ajax.request({url:this._gatewayUrl+this._gatewayGetMethod,params:{"ad_id":this._boundAds[this._currentAdIndex].adId,"lang_code":this._langCode,"ad_location":this._location},callback:this._getAdCallback.createDelegate(this,[this._boundAds[this._currentAdIndex].adId],true)});}},stop:function(){if(this._timeoutId){clearTimeout(this._timeoutId);}},getAd:function(_b){if(_b!=null&&_b!=this._currentAdIndex&&this._boundAds[_b]){this.stop();this._currentAdIndex=_b;this.play();}},_getAdCallback:function(_c,_d,_e,_f){if(_d){var _10=(_e&&_e.responseText)?this._decodeJSON(_e.responseText):{};if(_10.success&&_10.html){this._prepareAd(_10.html);this._adsAdded[_f]=_10.html;}else{this._getAdFailure(_e);}}else{this._getAdFailure(_e);}
this._setNextAdTimeout();},_getAdFailure:function(_11){if(this._showErrors=="Y"){var _12=(_11&&_11.responseText)?this._decodeJSON(_11.responseText):{};var _13="<div>An error occurred while retrieving the ad data.</div>";if(_12.message){_13+="<div>"+_12.message+"</div>";}
this._renderAd(_13);}},_setNextAdTimeout:function(){if(this._boundAds.length>1){this._timeoutId=this._getNextAd.defer((this._duration*1000),this);}},_getNextAd:function(){this._currentAdIndex++;if(this._currentAdIndex>=this._boundAds.length){this._currentAdIndex=0;}
this.play();},_prepareAd:function(_14){this._renderAd(_14);if(this._showNav=="Y"){this._updateNav();}},_renderAd:function(_15){var _16=Ext.get(this._shownContainerId);var _17=Ext.get(this._hiddenContainerId);_17.update(_15);animation=(this._boundAds[this._currentAdIndex].animation=="fade")?true:false;_16.hide(animation);_17.show(animation);var _18=this._shownContainerId;this._shownContainerId=this._hiddenContainerId;this._hiddenContainerId=_18;},_updateNav:function(){for(var _19=0;_19<this._boundAds.length;_19++){Ext.get(this._navContainerId+"-"+_19).removeClass("ws-active");}
Ext.get(this._navContainerId+"-"+this._currentAdIndex).addClass("ws-active");},_decodeJSON:function(_1a){try{var _1b=Ext.util.JSON.decode(_1a);}
catch(e){var _1b={};}
return _1b;}});
