// JavaScript Document

 var currentindex = 0;
	   var totalEntries = 0
	   var widgetDelay = 10;
	   var autoWidget = true;
	   $(document).ready(function () {
			$.ajax({
				type: "GET",
				url: "includes/ajax/poker_news.php",
				dataType: "xml",
				success: xmlParser
			});
			
			$("#upbutton").click(function() {
				autoWidget = false;
			 currentindex--;
			 if (currentindex < 0) currentindex = totalEntries-1;
			 animateToPosition();
		   });
			
			$("#downbutton").click(function() {
				autoWidget = false;
			 currentindex++;
			 if (currentindex > totalEntries-1) currentindex = 0;
			 animateToPosition();
		   });
			
			setInterval(function () {
				if (autoWidget) {
				currentindex++;
				 if (currentindex > totalEntries-1) currentindex = 0;
				 animateToPosition();
				}
				
			}, widgetDelay * 1000);
		});
	   
	   function animateToPosition() {
		   var newpos = currentindex*133*-1;
		   
		   $("#holder").animate({ top: newpos }, 'fast');
	   }
	   
	   function xmlParser(xml) {
		
			$(xml).find("item").each(function () {
				totalEntries++;
				var des = $(this).find("description").text();
				des.replace("<br>","");				
				var pub = $(this).find("pubDate").text();		
				$("#holder").append('<div class="entry"><div class="title"><span class="blue"><a href="'+$(this).find("link").text()+'" target="_blank">' + $(this).find("title").text() + '</a></span></div><div class="description">' + des + ' <span class="blue"><a href="'+$(this).find("link").text()+'" target="_blank">Read more</a></span> </div></div>');
			});
		
		}
