var newsCarousel=Class.create();newsCarousel.prototype={initialize:function(a,d,b,c){this.id=a;this.obj=$(a);this.feedUrl=d;this.options=Object.extend({imageDir:"",updateTime:10,fontFamily:"Helvetica Neue, Trebuchet MS, Arial, Helvetica, sans-serif",containerWidth:490,containerHeight:250,containerBackground:"#ffffff",containerRepeat:"no-repeat",descbarHeight:65,descbarBackground:"#000000",descbarPosition:"bottom",titleColor:"#fe6000",descColor:"#ffffff",paginationPosition:"top",paginationHeight:6,paginationWidth:6,paginationMax:5,paginationInactiveColor:"#666666",paginationActiveColor:"#fe6000",paginationClassName:"carouselpage",className:"carousel",imagePath:"",waitImage:"ub/images/bigwait.gif",leftImage:"carousel_left.gif",rightImage:"carousel_right.gif"},b||{});this.options.anchorExtra=Object.extend({target:"_blank"},this.options.anchorExtra||{});this.options.imageExtra=Object.extend({},this.options.imageExtra||{});this.title=null;this.desc=null;this.link=null;this.leftArrow=null;this.rightArrow=null;this.descBar=null;this.paginationBar=null;this.pageIndicator=[];this.tween=null;this.tweenObj=null;this.timer=null;this.count=0;this.position=-1;this.pageObjs=[];this.isIE=navigator.appVersion.match(/MSIE (\d+\.\d+)/,"")!=null;this.stopRotation=false;this.histogram={"'":"%27","(":"%28",")":"%29","*":"%2A","~":"%7E","!":"%21","%20":"+","\u00DC":"%DC","\u00FC":"%FC","\u00C4":"%D4","\u00E4":"%E4","\u00D6":"%D6","\u00F6":"%F6","\u00DF":"%DF","\u20AC":"%80","\u0081":"%81","\u201A":"%82","\u0192":"%83","\u201E":"%84","\u2026":"%85","\u2020":"%86","\u2021":"%87","\u02C6":"%88","\u2030":"%89","\u0160":"%8A","\u2039":"%8B","\u0152":"%8C","\u008D":"%8D","\u017D":"%8E","\u008F":"%8F","\u0090":"%90","\u2018":"%91","\u2019":"%92","\u201C":"%93","\u201D":"%94","\u2022":"%95","\u2013":"%96","\u2014":"%97","\u02DC":"%98","\u2122":"%99","\u0161":"%9A","\u203A":"%9B","\u0153":"%9C","\u009D":"%9D","\u017E":"%9E","\u0178":"%9F"};this._createView();this._initBehavior();this._initAjax(c)},_createView:function(){var b=this.obj;b.style.marginLeft="0px";b.style.width=this.options.containerWidth+"px";b.style.height=this.options.containerHeight+"px";b.style.backgroundColor=this.options.containerBackground;b.style.backgroundRepeat=this.options.containerRepeat;b.className=this.options.className;b.style.backgroundImage='url("'+this.options.waitImage+'")';b.style.position="relative";b=new Element("div");b.style.position="absolute";b.style.width=this.obj.style.width;b.style.height=this.obj.style.height;b.style.background="none";b.style.backgroundRepeat=this.obj.style.backgroundRepeat;b.style.top=0;b.style.left=0;this.tweenObj=b;this.obj.appendChild(this.tweenObj);this.tween=new Fx.Opacity(this.tweenObj);b=new Element("a");for(var a in this.options.anchorExtra){b[a]=this.options.anchorExtra[a]}b.style.position="absolute";b.style.height=(this.options.containerHeight-this.options.descbarHeight)+"px";b.style.width="100%";b.style.display="block";b.style.textDecoration="none";b.className="link";if(this.options.descbarPosition=="bottom"){b.style.top="0"}else{if(this.options.descbarPosition=="top"){b.style.bottom="0"}}b.href="#";b.innerHTML="&nbsp;";this.link=b;this.obj.appendChild(this.link);b=new Element("div");b.style.position="absolute";b.style.height=this.options.descbarHeight+"px";b.style.width="100%";b.style.position="absolute";b.className="descbar";if(this.options.descbarPosition=="bottom"){b.style.bottom="0"}else{if(this.options.descbarPosition=="top"){b.style.top="0"}}this.descBar=b;this.obj.appendChild(this.descBar);b=new Element("div");b.style.position="absolute";b.style.height="100%";b.style.width="100%";b.style.background=this.options.descbarBackground;if(this.isIE){b.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity = 60)"}else{b.style.MozOpacity="0.6";b.style.KhtmlOpacity="0.6"}b.style.opacity="0.6";b.className="descbarbg";this.descBar.appendChild(b);b=new Element("a");for(var a in this.options.anchorExtra){b[a]=this.options.anchorExtra[a]}b.style.position="absolute";b.style.top="4px";b.style.left="53px";b.style.fontFamily=this.options.fontFamily;b.style.fontSize="14pt";b.style.fontWeight="bold";b.style.display="block";b.style.height="27px";b.style.width="388px";b.style.overflow="hidden";b.style.color=this.options.titleColor;b.style.textDecoration="none";b.className="titlebar";b.href="#";b.innerHTML="Loading...";this.title=b;this.descBar.appendChild(this.title);b=new Element("div");b.style.position="absolute";b.style.top="30px";b.style.left="53px";b.style.fontFamily=this.options.fontFamily;b.style.fontSize="9pt";b.style.lineHeight="11pt";b.style.display="block";b.style.height="28px";b.style.width="388px";b.style.overflow="hidden";b.style.color=this.options.descColor;b.className="desc";b.innerHTML="";this.desc=b;this.descBar.appendChild(this.desc);b=new Element("span");b.style.position="absolute";b.style.top="5px";b.style.left="9px";b.style.height="54px";b.style.width="27px";b.style.background='url("'+this.options.imagePath+this.options.leftImage+'") left top no-repeat';b.style.cursor="pointer";b.className="leftarrow";this.leftArrow=b;this.descBar.appendChild(this.leftArrow);b=new Element("span");b.style.position="absolute";b.style.top="5px";b.style.right="9px";b.style.height="54px";b.style.width="27px";b.style.background='url("'+this.options.imagePath+this.options.rightImage+'") left top no-repeat';b.style.cursor="pointer";b.className="rightarrow";this.rightArrow=b;this.descBar.appendChild(this.rightArrow);b=new Element("div");b.style.position="absolute";b.style.display="block";b.style.height=this.options.paginationHeight+"px";b.style.overflow="hidden";b.style.width="100%";b.style.position="absolute";b.className="paginationbar";if(this.options.paginationPosition=="bottom"){b.style.bottom="8px"}else{if(this.options.paginationPosition=="top"){b.style.top="8px"}}this.paginationBar=b;this.obj.appendChild(this.paginationBar)},_clearNodes:function(a){if(a.hasChildNodes()){while(a.childNodes.length>=1){a.removeChild(a.firstChild)}}},_createPaginationMarks:function(b){this._clearNodes(this.paginationBar);if(b<this.options.paginationMax){this.setCount(b)}else{this.setCount(this.options.paginationMax)}var a=this.getCount();var d=9;var f;for(var c=0;c<a;c++){f=new Element("span");f.style.position="absolute";f.style.right=d+"px";f.style.display="block";f.style.height="100%";f.style.width=this.options.paginationWidth+"px";f.style.backgroundColor=this.options.paginationInactiveColor;f.innerHTML="&nbsp;";f.className="pageindicator";this.pageIndicator[a-c-1]=f;this.paginationBar.insert(f);d+=10}},setCount:function(a){if(a==0){this.obj.style.background="#FFF";this.title.innerHTML="No data available."}if(a<2){this.leftArrow.style.display="none";this.rightArrow.style.display="none"}if(this.position>a){this.pageIndicator[this.position].style.backgroundColor=this.options.paginationInactiveColor;this.position=0}this.count=a},getCount:function(){return this.count},_initUpdateTimer:function(){this._nextStory();if(this.getCount()>1){if(!this.timer){this.timer=new PeriodicalExecuter(this._nextStoryEvent.bindAsEventListener(this),this.options.updateTime)}}else{if(this.timer){this.timer.stop();this.timer=null}}},_initAjax:function(d){if(d){var a=new Object;if(this.isIE){a.responseXML=new ActiveXObject("Microsoft.XMLDOM");a.responseXML.async="false";a.responseXML.loadXML(d)}else{try{var c=new DOMParser();a.responseXML=c.parseFromString(d,"text/xml")}catch(b){a.responseXML=null}}this._ajaxResponse(a)}else{this._callAjax()}new PeriodicalExecuter(this._callAjax.bindAsEventListener(this),900)},_nextStoryEvent:function(){if(this.stopRotation){return}this._nextStory()},_nextStory:function(){if(this.position>-1){this.pageIndicator[this.position].style.backgroundColor=this.options.paginationInactiveColor}this.position=++this.position>=this.getCount()?0:this.position;if(!this.pageIndicator[this.position]){return}this.pageIndicator[this.position].style.backgroundColor=this.options.paginationActiveColor;this._setNews(this.pageObjs[this.position])},_prevStory:function(){this.pageIndicator[this.position].style.backgroundColor=this.options.paginationInactiveColor;this.position=this.position==0?this.getCount()-1:--this.position;if(!this.pageIndicator[this.position]){return}this.pageIndicator[this.position].style.backgroundColor=this.options.paginationActiveColor;this._setNews(this.pageObjs[this.position])},_setNews:function(a){this.title.innerHTML=a.title;this.desc.innerHTML=a.desc;if(this.timer){this.tweenObj.style.backgroundImage=this.obj.style.backgroundImage;this.tween.show();this.tween.toggle()}this.obj.style.backgroundImage='url("'+a.img+'")';this.title.href=a.url;this.link.href=a.url},_initBehavior:function(){this.obj.observe("mouseover",this._mouseOverResponse.bindAsEventListener(this));this.obj.observe("mouseout",this._mouseOutResponse.bindAsEventListener(this));this.leftArrow.observe("click",this._leftClickResponse.bindAsEventListener(this));this.rightArrow.observe("click",this._rightClickResponse.bindAsEventListener(this))},_mouseOverResponse:function(){this.stopNewsRotation()},_mouseOutResponse:function(){this.startNewsRotation()},_leftClickResponse:function(){this._prevStory()},_rightClickResponse:function(){this._nextStory()},stopNewsRotation:function(){this.stopRotation=true},startNewsRotation:function(){this.stopRotation=false},_callAjax:function(){new Ajax.Request(this.feedUrl,{method:"get",onSuccess:this._ajaxResponse.bindAsEventListener(this),onFailure:this._ajaxError,asynchronous:true})},_ajaxResponse:function(d){var b=d.responseXML;if(b&&b.getElementsByTagName("stories").length){var a=b.getElementsByTagName("stories")[0];if(!a.getAttribute("count")||!a.getElementsByTagName("story")){return}this.setCount(a.getAttribute("count"));this._createPaginationMarks(this.getCount());a=a.getElementsByTagName("story");for(var c=0;c<this.getCount();c++){this.pageObjs[c]=this._createPageObject(this._urldecode(a[c].getAttribute("url")),a[c].getAttribute("img"),a[c].getAttribute("title"),a[c].getAttribute("desc"))}this._initUpdateTimer()}},_createPageObject:function(a,d,f,e){var c={url:a,img:d,obj:new Image(this.options.containerWidth,this.options.containerHeight),title:f||"No title",desc:e||"No description"};for(var b in this.options.imageExtra){c[b]=this.options.imageExtra[b]}c.obj.src=d;return c},_ajaxError:function(a){},_replaceStr:function(b,a,d){var c=[];c=d.split(b);return c.join(a)},_urldecode:function(c){var b=c.toString(),a="";for(a in this.histogram){b=this._replaceStr(this.histogram[a],a,b)}return decodeURIComponent(b)}};
