var a;function GFdynamicFeedControl(b,c,d){this.nodes={};this.collapseElements=[];this.feeds=[];this.results=[];if(typeof b=="string"){this.feeds.push({url:b})}else{if(typeof b=="object"){for(var e=0;e<b.length;e++){var f=b[e],g={};if(typeof f=="string"){g.url=b[e]}else{if(typeof f=="object"){if((g=b[e])&&g.title){g.title=g.title.replace(/</g,"&lt;").replace(/>/g,"&gt;")}}}this.feeds.push(g)}}}if(typeof c=="string"){c=document.getElementById(c)}this.parseOptions_(d);this.setup_(c)}GFdynamicFeedControl.DEFAULT_NUM_RESULTS=5;GFdynamicFeedControl.DEFAULT_FEED_CYCLE_TIME=18E5;GFdynamicFeedControl.DEFAULT_DISPLAY_TIME=3E3;GFdynamicFeedControl.DEFAULT_FADEOUT_TIME=1E3;GFdynamicFeedControl.DEFAULT_TRANSISTION_STEP=40;GFdynamicFeedControl.DEFAULT_HOVER_TIME=100;a=GFdynamicFeedControl.prototype;a.parseOptions_=function(b){this.options={numResults:GFdynamicFeedControl.DEFAULT_NUM_RESULTS,feedCycleTime:GFdynamicFeedControl.DEFAULT_FEED_CYCLE_TIME,linkTarget:google.feeds.LINK_TARGET_SELF,displayTime:GFdynamicFeedControl.DEFAULT_DISPLAY_TIME,transitionTime:GFdynamicFeedControl.DEFAULT_TRANSISTION_TIME,transitionStep:GFdynamicFeedControl.DEFAULT_TRANSISTION_STEP,fadeOutTime:GFdynamicFeedControl.DEFAULT_FADEOUT_TIME,scrollOnFadeOut:true,pauseOnHover:true,hoverTime:GFdynamicFeedControl.DEFAULT_HOVER_TIME,autoCleanup:true,transitionCallback:null,feedTransitionCallback:null,feedLoadCallback:null,collapseable:false,sortByDate:false,horizontal:false,stacked:false,title:null};if(b){for(var c in this.options){if(typeof b[c]!="undefined"){this.options[c]=b[c]}}}if(!this.options.stacked){this.options.collapseable=false}this.options.displayTime=Math.max(200,this.options.displayTime);this.options.fadeOutTime=Math.max(0,this.options.fadeOutTime);this.fadeOutDelta=Math.min(1,1/(this.options.fadeOutTime/this.options.transitionStep));this.started=false};a.setup_=function(b){if(b!=null){this.nodes.container=b;if(window.ActiveXObject){this.ie=this[window.XMLHttpRequest?"ie7":"ie6"]=true}else{if(document.childNodes&&!document.all&&!navigator.taintEnabled){this.safari=true}else{if(document.getBoxObjectFor!=null){this.gecko=true}}}this.feedControl=new google.feeds.FeedControl;this.feedControl.setLinkTarget(this.options.linkTarget);this.expected=this.feeds.length;for(b=this.errors=0;b<this.feeds.length;b++){var c=new google.feeds.Feed(this.feeds[b].url);c.setResultFormat(google.feeds.Feed.JSON_FORMAT);c.setNumEntries(this.options.numResults);c.load(this.bind_(this.feedLoaded_,b))}}};a.bind_=function(b){var c=this,d=[].slice.call(arguments,1);return function(){var e=d.concat([].slice.call(arguments));return b.apply(c,e)}};a.feedLoaded_=function(b,c){this.options.feedLoadCallback&&this.options.feedLoadCallback(c);if(c.error){if(++this.errors>=this.expected){this.nodes.container.innerHTML="Feed"+(this.expected>1?"s ":" ")+"could not be loaded."}}else{if(this.feeds[b].title){c.feed.title=this.feeds[b].title}this.results.push(c);if(this.started){!this.options.horizontal&&this.options.stacked&&this.addResult_(this.results.length-1)}else{this.createSubContainers_();this.displayResult_(0)}}};a.sortByDate_=function(b,c,d){for(var e=Date.parse(this.results[b].feed.entries[0].publishedDate),f=null,g=0;g<this.results.length;g++){var i=Date.parse(this.results[g].feed.entries[0].publishedDate);if(e>i){f=g;break}}if(f==null){this.nodes.root.appendChild(c);this.nodes.root.appendChild(d);this.createListEntries_(b,d)}else{var h=2+f*2;g=h+2;i=b+1;e=this.nodes.root.childNodes;h=e[h];this.nodes.root.insertBefore(c,h);this.nodes.root.insertBefore(d,h);this.results.splice(f,0,this.results[b]);this.results.splice(i,1);this.createListEntries_(f,d);f==0&&this.displayResult_(0);f+=1;for(g=g;g<e.length;g+=2){b=e[g].nextSibling.childNodes;for(d=0;d<b.length;d++){b[d].onmouseover=this.bind_(this.listMouseOver_,f,d);b[d].onmouseout=this.bind_(this.listMouseOut_,f,d)}f++}}};a.addResult_=function(b){var c=this.results[b],d=this.createDiv_("gfg-subtitle");this.setTitle_(c.feed,d);c=this.createDiv_("gfg-list");if(this.options.collapseable){var e=document.createElement("div");c.style.display="none";e.className="gfg-collapse-closed";d.appendChild(e);e.onclick=this.toggleCollapse(this,c,e);this.collapseElements.push({list:c,collapse:e})}e=document.createElement("div");e.className="clearFloat";d.appendChild(e);if(this.options.sortByDate){this.sortByDate_(b,d,c)}else{this.nodes.root.appendChild(d);this.nodes.root.appendChild(c);this.createListEntries_(b,c)}};a.displayResult_=function(b){this.resultIndex=b;var c=this.results[b];this.options.feedTransitionCallback&&this.options.feedTransitionCallback(c);this.options.title?this.setPlainTitle_(this.options.title):this.setTitle_(c.feed);this.clearNode_(this.nodes.entry);if(this.started&&!this.options.horizontal&&this.options.stacked){this.entries=c.feed.entries}else{this.createListEntries_(b,this.nodes.list)}this.displayEntries_()};a.setPlainTitle_=function(b,c){(c||this.nodes.title).innerHTML=b};a.setTitle_=function(b,c){c=c||this.nodes.title;this.clearNode_(c);var d=document.createElement("a");d.target=google.feeds.LINK_TARGET_SELF;d.href=b.link;d.className="gfg-collapse-href";d.innerHTML=b.title;c.appendChild(d)};a.toggleCollapse=function(b,c,d){return function(){for(var e=b.collapseElements,f=0;f<e.length;f++){var g=e[f];g.list.style.display="none";g.collapse.className="gfg-collapse-closed"}c.style.display="block";d.className="gfg-collapse-open"}};a.createListEntries_=function(b,c){var d=this.results[b].feed.entries;this.clearNode_(c);for(var e=0;e<d.length;e++){this.feedControl.createHtml(d[e]);var f="gfg-listentry ";f+=e%2?"gfg-listentry-even":"gfg-listentry-odd";f=this.createDiv_(f);var g=this.createLink_(d[e].link,d[e].title,this.options.linkTarget);f.appendChild(g);if(this.options.pauseOnHover){f.onmouseover=this.bind_(this.listMouseOver_,b,e);f.onmouseout=this.bind_(this.listMouseOut_,b,e)}d[e].listEntry=f;c.appendChild(f)}if(c==this.nodes.list){this.entries=d}};a.displayEntries_=function(){this.entryIndex=0;this.displayCurrentEntry_();this.setDisplayTimer_();this.started=true};a.displayNextEntry_=function(){if(this.options.autoCleanup&&this.isOrphaned_()){this.cleanup_()}else{if(++this.entryIndex>=this.entries.length){if(this.results.length>1){if(++this.resultIndex>=this.results.length){this.resultIndex=0}this.displayResult_(this.resultIndex);return}else{this.entryIndex=0}}this.options.transitionCallback&&this.options.transitionCallback(this.entries[this.entryIndex]);this.displayCurrentEntry_();this.setDisplayTimer_()}};a.displayCurrentEntry_=function(){this.clearNode_(this.nodes.entry);this.current=this.entries[this.entryIndex].html;this.current.style.top="0px";this.nodes.entry.appendChild(this.current);this.createOverlay_();if(this.options.collapseable){for(var b=null,c=0;c<this.results.length;c++){if(this.results[c].feed.entries==this.entries){b=this.results[c].feed.title}}var d=this.collapseElements;for(c=0;c<d.length;c++){var e=d[c],f=e.collapse;if(b==e.collapse.previousSibling.innerHTML){this.ie?f.click():f.onclick()}}}if(this.currentList){b="gfg-listentry ";b+=this.currentListIndex%2?"gfg-listentry-even":"gfg-listentry-odd";this.currentList.className=b}this.currentList=this.entries[this.entryIndex].listEntry;this.currentListIndex=this.entryIndex;b="gfg-listentry gfg-listentry-highlight ";b+=this.currentListIndex%2?"gfg-listentry-even":"gfg-listentry-odd";this.currentList.className=b};a.listMouseHover_=function(b,c){var d=this.results[b];d.feed.entries[c].listEntry.selectTimer=null;this.clearTransitionTimer_();this.clearDisplayTimer_();this.resultIndex=b;this.entries=d.feed.entries;this.entryIndex=c;this.displayCurrentEntry_()};a.listMouseOver_=function(b,c){var d=this.results[b].feed.entries[c].listEntry;b=this.bind_(this.listMouseHover_,b,c);d.selectTimer=setTimeout(b,this.options.hoverTime)};a.listMouseOut_=function(b,c){b=this.results[b].feed.entries[c].listEntry;if(b.selectTimer){clearTimeout(b.selectTimer);b.selectTimer=null}else{this.setDisplayTimer_()}};a.entryMouseOver_=function(){this.clearDisplayTimer_();if(this.transitionTimer){this.clearTransitionTimer_();this.displayCurrentEntry_()}};a.entryMouseOut_=function(){this.setDisplayTimer_()};a.createOverlay_=function(){if(this.current!=null){if(this.overlay==null){var b=this.createDiv_("gfg-entry");b.style.position="absolute";b.style.top="0px";b.style.left="0px";this.overlay=b}this.setOpacity_(this.overlay,0);this.nodes.entry.appendChild(this.overlay)}};a.setDisplayTimer_=function(){this.displayTimer&&this.clearDisplayTimer_();var b=this.bind_(this.setFadeOutTimer_);this.displayTimer=setTimeout(b,this.options.displayTime)};GFdynamicFeedControl.timeNow=function(){return(new Date).getTime()};a=GFdynamicFeedControl.prototype;a.fadeOutEntry_=function(){if(this.overlay){var b=this.fadeOutDelta,c=this.options.transitionStep,d=GFdynamicFeedControl.timeNow(),e=d-this.lastTick;this.lastTick=d;b*=e/c;b=this.overlay.opacity+b;this.setOpacity_(this.overlay,b);if(this.options.scrollOnFadeOut&&b>0.5){this.current.style.top=Math.round(this.current.offsetHeight*(b-0.5)*2)+"px"}if(b<1){return}}this.clearTransitionTimer_();this.displayNextEntry_()};a.setFadeOutTimer_=function(){this.clearTransitionTimer_();this.lastTick=GFdynamicFeedControl.timeNow();var b=this.bind_(this.fadeOutEntry_);this.transitionTimer=setInterval(b,this.options.transitionStep)};a.clearTransitionTimer_=function(){if(this.transitionTimer){clearInterval(this.transitionTimer);this.transitionTimer=null}};a.clearDisplayTimer_=function(){if(this.displayTimer){clearTimeout(this.displayTimer);this.displayTimer=null}};a.createSubContainers_=function(){var b=this.nodes,c=this.nodes.container;this.clearNode_(c);if(this.options.horizontal){c=this.createDiv_("gfg-horizontal-container");b.root=this.createDiv_("gfg-horizontal-root");this.nodes.container.appendChild(c)}else{b.root=this.createDiv_("gfg-root")}b.title=this.createDiv_("gfg-title");b.entry=this.createDiv_("gfg-entry");b.list=this.createDiv_("gfg-list");b.root.appendChild(b.title);b.root.appendChild(b.entry);if(!this.options.horizontal&&this.options.stacked){var d=this.createDiv_("gfg-subtitle");b.root.appendChild(d);this.setTitle_(this.results[0].feed,d);if(this.options.collapseable){var e=document.createElement("div");e.className="gfg-collapse-open";d.appendChild(e);e.onclick=this.toggleCollapse(this,b.list,e);this.collapseElements.push({list:b.list,collapse:e});b.list.style.display="block"}e=document.createElement("div");e.className="clearFloat";d.appendChild(e)}b.root.appendChild(b.list);c.appendChild(b.root);if(this.options.pauseOnHover){b.entry.onmouseover=this.bind_(this.entryMouseOver_);b.entry.onmouseout=this.bind_(this.entryMouseOut_)}if(this.options.horizontal){b.branding=this.createDiv_("gfg-branding");google.feeds.getBranding(b.branding,google.feeds.VERTICAL_BRANDING);c.appendChild(b.branding)}};a.clearNode_=function(b){if(b!=null){for(var c;c=b.firstChild;){b.removeChild(c)}}};a.createDiv_=function(b,c){var d=document.createElement("div");if(c){d.innerHTML=c}if(b){d.className=b}return d};a.createLink_=function(b,c,d){var e=document.createElement("a");e.href=b;e.innerHTML=c;if(d){e.target=d}return e};a.clearResults_=function(){for(var b=0;b<this.results.length;b++){var c=this.results[b].feed.entries;for(b=0;b<c.length;b++){var d=c[b];d.html=null;d.listEntry.onmouseover=null;d.listEntry.onmouseout=null;if(d.listEntry.selectTimer){clearTimeout(d.listEntry.selectTimer);d.listEntry.selectTimer=null}d.listEntry=null}}};a.isOrphaned_=function(){var b=this.nodes.root,c=false;if(!b||!b.parentNode){c=true}else{if(this.options.horizontal&&!b.parentNode.parentNode){c=true}}return c};a.cleanup_=function(){this.started=false;this.clearDisplayTimer_();this.clearTransitionTimer_();this.clearResults_();this.clearNode_(this.nodes.root);this.nodes.container=null};a.setOpacity_=function(b,c){if(b!=null){c=Math.max(0,Math.min(1,c));if(c==0){if(b.style.visibility!="hidden"){b.style.visibility="hidden"}}else{if(b.style.visibility!="visible"){b.style.visibility="visible"}}if(this.ie){b.style.filter="alpha(opacity="+Math.round(c*100)+")"}b.style.opacity=b.opacity=c}};GFgadget=GFdynamicFeedControl;
