/**
 *
 * Extends the Carousel Class to add infinite scrolling like a ticker
 * <p>Usage: new YAHOO.EU.widget.Carousel().infiniteScroll();</p>
 */
YAHOO.EU.widget.Carousel.prototype.infiniteScroll = function(){
 this.moveBy = function(e, nPanes){
 if(this.bActive){
 return;
 }
 if(e){
 YAHOO.util.Event.preventDefault(e);
 this.onNavigate.fire();
 }
 this.nCurrentPane += nPanes * this.nPanesToMove;
 if(this.nCurrentPane + this.nVisiblePanes - this.nPanesToMove >= this.nPanes){
 if(this.bLoop){
 this.nCurrentPane = 0;
 }
 this.onCarouselEnd.fire();
 }else if(this.nCurrentPane <= -this.nPanesToMove){
 if(this.bLoop){
 return this.nCurrentPane = 0;
 }
 this.onCarouselEnd.fire();
 }
 this.gotoPane(this.nCurrentPane);
 }
 this.oClone = this.oPanel.getElementsByTagName("li")[0].cloneNode(true);
 this.oPanel.appendChild(this.oClone);
 this.assignElements();
 this.onAnimStart.subscribe(function(){
 this.bActive = 1;
 }, this, true);
 this.onAnimEnd.subscribe(function(){
 if(this.nCurrentPane == this.nPanes-1){
 this.oPanel.style.left = 0;
 this.nCurrentPane = 0;
 }
 this.bActive = 0;
 }, this, true);
 return this;
};
YAHOO.EU.widget.Carousel.prototype.checkedForUpdates = function(oResponse){
 var re = /[\S]/g;
 if(!re.test(oResponse.responseText)){
 return;
 }
 var oReturn = eval( '(' + oResponse.responseText + ')' );
 var sCurrentHTML = this.oPanel.innerHTML;
 this.oPanel.innerHTML = oReturn.listitems;
 YAHOO.util.Dom.getElementsByClassName("yeug-ticker-rss", "a")[0].setAttribute("href", oReturn.rssurl);
 if(oReturn.activecategory){
 YAHOO.EU.widget.DTKNav.tickerDrop.setLabel(oReturn.activecategory);
 }
 this.assignElements();
 this.gotoPane(0);
 this.enableButtons();
 if(this.oPanel.innerHTML != sCurrentHTML){
 this.onContentChange.fire();
 }
};
YAHOO.EU.widget.Carousel.prototype.checkForUpdates = function(sQuerystring){
 if(sQuerystring){
 this.sQuerystring = sQuerystring;
 }
 YAHOO.util.Connect.asyncRequest("GET", (!this.sQuerystring) ? this.oLoadConfig.url : this.oLoadConfig.url.split("&sport")[0] + this.sQuerystring, {
 success : this.checkedForUpdates,
 scope : this
 }
 );
};
YAHOO.EU.widget.DTKNav.DropDown.prototype.changeLabelOnSelect = function(){ 
 YAHOO.util.Event.on(this.dropper, 'click', function(e){
 var oTarget = YAHOO.util.Event.getTarget(e);
 if(oTarget.nodeName.toLowerCase() != "a"){
 return;
 }
 this.setLabel(oTarget.firstChild.nodeValue);
 this.hideDropper(e);
 YAHOO.EU.oTicker.checkForUpdates("&sport=" + oTarget.getAttribute("href").split("#")[1].replace("sportid", ""));
 }, this, true);
}
YAHOO.EU.widget.DTKNav.DropDown.prototype.setLabel = function(sLabel){
 this.dropper.previousSibling.firstChild.firstChild.nodeValue = sLabel;
}
YAHOO.util.Event.onAvailable("yeug-ticker", function(){
 var oCarouselConfig = {
 buttonCont : 'yeug-ticker-wrapper',
 loop : 1
 };
 YAHOO.EU.widget.Carousel.prototype.addPopout = function(oConfig){
 if(window.opener){
 YAHOO.util.Event.on(this.oPanel, "click", this.popin, this, true);
 return;
 }
 var a = document.createElement("button");
 YAHOO.util.Dom.addClass(a, "btnpop");
 this.oButtonCont.appendChild(a);
 YAHOO.util.Event.on(a, "click", this.popout, this, true);
 return this;
 }
 YAHOO.EU.widget.Carousel.prototype.popout = function(e){
 YAHOO.util.Event.preventDefault(e);
 var aSports = YAHOO.util.Dom.getElementsByClassName("selected", "a", "yeug-ticker-wrapper-drop");
 sSportID = (aSports.length) ? aSports[0].getAttribute("href").split("#")[1].replace("sportid", "") : "0";
 window.open("/ticker/popup.html?sport=" + sSportID, 'yeugticker', 'width=670,height=240');
 }
 YAHOO.EU.widget.Carousel.prototype.popin = function(e){
 var oTarget = YAHOO.util.Event.getTarget(e);
 if(oTarget.nodeName.toLowerCase() == "a"){
 YAHOO.util.Event.preventDefault(e);
 if(window.opener){
 window.opener.location = oTarget.href;
 }else{
 window.open(oTarget.href);
 }
 }
 }
 
 YAHOO.EU.oTicker = new YAHOO.EU.widget.Carousel().init('yeug-ticker', oCarouselConfig)
 YAHOO.EU.oTicker.autoPlay(oAutoConfig).addPopout();
 YAHOO.EU.oTicker.infiniteScroll();
 var aSelected = YAHOO.util.Dom.getElementsByClassName("selected", "a", "yeug-ticker-wrapper-drop");
 var sSportID = (aSelected.length) ? aSelected[0].getAttribute("href").split("#")[1].replace("sportid", "") : "0";
 YAHOO.EU.oTicker.enableCheckForUpdates({url : "/ticker/update.html?output=json" + ((window.opener) ? "&type=long" : "&type=short") + "&sport=" + sSportID, checkDelay : 30000, maxItems:2});
 
});
YAHOO.util.Event.onAvailable("yeug-ticker-wrapper", function(){
 var aLabels = YAHOO.util.Dom.getElementsByClassName("selected", "a", "yeug-ticker-wrapper-drop");
 var oConfigTicker = {
 sNavContainerId: "yeug-ticker-wrapper",
 sClassNavParent: "yeug-ticker-wrapper-drop",
 sClassNavDrop: "drop-down",
 sClassNavRogue: "rogue",
 oTextNavItem: {
 label: (aLabels.length) ? ((aLabels[0].firstChild) ? aLabels[0].firstChild.nodeValue : ' ') : document.getElementById("yeug-ticker-wrapper-drop").getElementsByTagName("a")[0].firstChild.nodeValue,
 location: "#"
 },
 iColMax:(window.opener)?5:30
 };
 YAHOO.EU.widget.DTKNav.tickerDrop = new YAHOO.EU.widget.DTKNav.DropDown(oConfigTicker);
 YAHOO.EU.widget.DTKNav.tickerDrop.create();
 YAHOO.EU.widget.DTKNav.tickerDrop.changeLabelOnSelect();
 YAHOO.EU.widget.DTKNav.tickerDrop.showDropper = function(e){
 YAHOO.util.Dom.setStyle(this.dropper, 'display', 'block');
 var iRightWhitespace = 20;
 var iCParLeft = YAHOO.util.Dom.getX(this.oConfig.sNavContainerId);
 var iOrigLeft = (this.iLeft - this.iParLeft) + iCParLeft;
 YAHOO.util.Dom.setX(this.dropper, iOrigLeft-2);
 if(navigator.userAgent.toLowerCase().indexOf('gecko') === -1){
 var attributes = {
 height: { to: this.dropHeight }
 };
 var anim = new YAHOO.util.Anim(this.dropper, attributes, 0.3, YAHOO.util.Easing.backOut);
 anim.animate();
 }else{
 YAHOO.util.Dom.setStyle(this.dropper, 'height', this.dropHeight+'px');
 }
 this.isActive = true;
 };
});
