jQuery.fn.extend({ scrollbox: function(xml){ var src = xml || false; return this.each(function(){ if( src ){ // setup the scrollbox with the elements in the rss feed jQuery(this).find('a').remove(); jQuery(this).append('
Video from TODAY Netcast: Watch now Subscribe to Podcasts | Download
previousnext
'); var panel = jQuery(this).find('div.sbxpanel'); var w = 129; var total = 0; jQuery(src).find('item').each(function(t){ var l = document.createElement('a'); //new Date(jQuery(this).find('pubDate').text()); var tn = this.childNodes[3]; var trl = tn.attributes[1].nodeValue; var contents = ''+jQuery(this).find('title').text()+''; contents = contents.replace("vmodv4","thumb-m"); var link = jQuery(this).find('link').text(); l.href = link.replace("v.htm", 'msnbc.htm'); $(l).css({left:total+'px'}).html(contents).click(function(){ window.open(this.href,"msnVDWd","width=1020,height=750,status=1,scrollbars=1,resizable=1"); return false; }).appendTo(panel); total += w; }); var max = jQuery(this).width(); var min = max - total; jQuery(panel).width(total); var scroll = function(dir){ // if panel is smaller than container if(total < max) return; var l = jQuery(panel).css('left'); l = ( (l.replace(/[^-0-9]/g, '')) * 1 ) + ( dir * w ); if(l < min || l > 0) return; jQuery(panel).css({left:l+'px'}); }; jQuery(this).find('a.sbxprev').click(function(){ scroll(1); }); jQuery(this).find('a.sbxnext').click(function(){ scroll(-1); }); }else{ // load the rss var rss = jQuery(this).find('a').attr('href') || false; if(!rss) return; var l = this; // for closure $.get(rss, function(feed){ jQuery(l).scrollbox(feed); }); }; }); } }); $().ready(function(){ $('div.scrollbox').scrollbox(); });