//SLIDER FOR GEOSOCIALS RECENT ACTIVITY
var recentObj = new RecentActivitySlider();
$(document).ready(function() {
	var htmls = '';
	$.ajax({
	    type: "GET",
	        url: "data/sites.xml",
	        dataType: "xml",
	        success: function(xml) {
	        	var html = '';
	        	var xmlData = new Array();
	        	
	        	$(xml).find('site').each(function(){
	        		var title = $(this).find('title').text();
	        		var date = $(this).find('date').text();
	        		xmlData.push(new Array(title,date));
	        	});
	        	xmlData.reverse();
	        	for (key in xmlData){
	        		my_class = key <= 1 ? "initially-show" : "initially-hide";
	        	
	        		dateArray = xmlData[key][1].split(",");

	        		dateHtml ='<div class="datebg">'+dateArray[0]+"\n"+	        				
	        				  '<br>'+ "\n" +
	        				  '<span class="datebg_date">'+dateArray[1]+'</span></div>';
	        		
	        		html = '<li class="'+my_class+'">' + 
	        		dateHtml+ '<span class="xlabznews">'+ xmlData[key][0] +'</span>'+
	        		'</li>';
	        		$("#activity").append(html);
	        	}
	        	recentObj.init('activity','activity-stream',3000,2,true);
	        	setTimeout("recentObj.animateFeed(recentObj)", recentObj.delay);
	        }
	    });



});

	/*data = title.split(":");
date = data[0];
dateArray = date.split(",");

dateHtml ='<div class="datebg">'+dateArray[0]+"\n"+	        				
		  '<br>'+ "\n" +
		  '<b class="datebg_date">'+dateArray[1]+'</b></div>';
*/


/* RECENT ACTIVITY SLIDER*/
function RecentActivitySlider(){
	 	this.delay = 3000;
		this.numCardsToShow = 2;
		this.toHide = '';
		this.numCardsDownloaded = '';
		this.nextToShow = '';
		this.ulId = '';
		this.liClassName = '';
		this.updates = '';
		this.obj='';
		this.isRun = true;
}

RecentActivitySlider.prototype.init = function(ulId, liClassName, delay, numCardsToShow, isRun) {
		this.ulId = ulId;
		this.liClassName = liClassName;
		this.updates = $("."+liClassName+" li");
		this.numCardsDownloaded = this.updates.length;
		this.nextToShow = this.numCardsDownloaded - 1;
		this.delay = delay;
		this.numCardsToShow = numCardsToShow;
		this.toHide ='';
		this.isRun = isRun;
	};
			
RecentActivitySlider.prototype.animateFeed = function (ref) {
        if(this.isRun == true){
			 this.toHide = (this.nextToShow + this.numCardsToShow) % this.numCardsDownloaded;
			 this.updates.eq(this.nextToShow)
		         .remove()
		         .prependTo('#'+this.ulId)
		         .slideDown(1000);
			 this.updates.eq(this.toHide)
		         .slideUp(1000);
			 this.nextToShow = (this.nextToShow + this.numCardsDownloaded - 1) % this.numCardsDownloaded;
        }
	     setTimeout(function() { ref.animateFeed(ref); }, this.delay);
	 };
