
jQuery.iXmlFeed={build:function(options)
{var defaults={itemWidth:200,itemHeight:70,navHeight:20,maxItems:3,stripTitle:0,titleLen:40,stripDesc:0,descLen:350,linkLen:30,displayTitle:true,displayDescription:true,displayPubDate:true,displayLink:true,titleAsLink:true,literalDate:false,prevImg:"",nextImg:"",clickOnUl:false,linkImage:"",phpFile:"xml.php"};var options=jQuery.extend(defaults,options);return jQuery(this).each(function()
{var $el=jQuery(this);jQuery(this).append("<span class='prev'><img src='"+options.prevImg+"' \
   alt='prev'/></span><span class='next'><img src='"+options.nextImg+"' alt='next'/></span><ul></ul>");var $ul=jQuery(this).children("ul");var $spanl=jQuery(this).children("span:first");var $spanr=jQuery(this).children("span:last");var elHieght=options.itemHeight+options.navHeight;var elCss={width:options.itemWidth+"px",height:elHieght+"px",overflow:"hidden"}
var ulWidth=options.itemWidth*options.maxItems;var ulCss={position:"relative",width:ulWidth+"px",height:options.itemHeight+"px",clear:"both",'list-style':"none",padding:0}
var liCss={width:options.itemWidth+"px",height:options.itemHeight+"px",float:"left"}
var spanlCss={height:options.navHeight,float:"left"}
var spanrCss={height:options.navHeight,float:"right"}
$el.css(elCss);$spanl.css(spanlCss);$spanr.css(spanrCss);$ul.css(ulCss);$spanr.bind("click",function(){$ul.trigger("click",['next'])});$spanl.bind("click",function(){$ul.trigger("click",['prev'])});$ul.bind("click",function(event,whichway)
{if((options.clickOnUl==false)&&(whichway==undefined)){return false;}
var left=jQuery(this).css("left").slice(0,-2);left=left*-1;if(whichway=="prev"){if(left-options.itemWidth<0){var end=(options.itemWidth*(options.maxItems-1))*-1;$(this).animate({left:end+"px"},500);}else{var newLeft=(left-options.itemWidth)*-1;newLeft=newLeft+"px";$(this).animate({left:newLeft},500);}}else{if(left+options.itemWidth>ulWidth-options.itemWidth){$(this).animate({left:"0px"},500);}else{var newLeft=(left+options.itemWidth)*-1;newLeft=newLeft+"px";$(this).animate({left:newLeft},500);}}});var i=0;jQuery.ajax({type:"GET",url:options.phpFile,data:"uri="+options.feedURI,dataType:"xml",success:function(xml){jQuery(xml).find("item").each(function()
{if(i>=options.maxItems){return false};var input="";var link=jQuery(this).find('link').text();if(options.displayTitle){var title=jQuery(this).find('title').text().slice(options.stripTitle);if(title.length>options.titleLen){title=title.substr(0,options.titleLen)+"...";}
if(options.titleAsLink){input=input+"<span class='title'><a href='"+link+"'>"+title+"</a></span>";}else{input=input+"<span class='title'>"+title+"</span>";}}
if(options.displayDescription){var description=jQuery(this).find('description').text().slice(options.stripDesc);description=description.replace(/(<([^>]+)>)/ig,"");if(description.length>options.descLen){description=description.substr(0,options.descLen)+"...";}
input=input+"<span class='description'>"+description+"</span>";}
if((options.titleAsLink==false)&&(options.displayLink==true)){var linkRef=link;if(link.length>options.linkLen){link=link.substr(0,options.linkLen)+"...";}
var linkImg="";if(options.linkImage!=""){linkImg="<img src='"+options.linkImage+"'/>"}
input=input+"<span class='link'>"+linkImg+"<a href='"+linkRef+"'>"+link+"</a></span>";}
if(options.displayPubDate){var pubDate=jQuery(this).find('pubDate').text();if(!options.literalDate){pubDate=new Date(pubDate).getTime();var nowTime=new Date().getTime();var diff=(nowTime-pubDate)/1000;if(diff<300){pubDate="less than 5 minutes ago"}else if(diff<3600){diff=Math.round(diff/60);pubDate="about "+diff+" minutes ago";}else if(diff<6000){diff=Math.round((diff-3600)/60);pubDate="1 hour "+diff+" minutes ago";}else if(diff<86400){diff=Math.round(diff/3600);pubDate="about "+diff+" hours ago";}else if(diff<172800){diff=Math.round((diff-86400)/3600);pubDate="1 day "+diff+" hours ago";}else{diff=Math.round(diff/86400);pubDate="about "+diff+" days ago";}}
input=input+"<span class='pubdate'>"+pubDate+"</span>";}
$ul.append("<li>"+input+"</li>");i++;});$ul.children("li").each(function(){$(this).css(liCss);});}});});}}
jQuery.fn.XmlFeed=jQuery.iXmlFeed.build;
