// JavaScript Document

// VBTwitterrollout function
// Just a simpel jQuery plugin to roll down some Twitterfeed elements. 
// written	: 05-04-2011
// Author	: Virgial Berveling
// Company	: Freak de la Technique
// usage	: $("ul").VBTwitterroll({speed : 1000});

(function( $ ){

  $.fn.VBTwitterroll = function(options){
	
	twitterRoll = {};
	// default settings. Customizable, or add your specific needs through the options object
	twitterRoll.settings = {
		totallength 	: 4,
		startdelay 		: 1000,
		ul_height 		: 260,
		ul_openingspeed : 1000,
		speed			: 800,
		refreshrate 	: 6000,
		showspeed 		: 700,
		slidespeed		: 700,
		margin			: 7
	};
	// default settings
	if (options != undefined) {
		for (var p in options)  twitterRoll.settings[p] = options.p;
	}
	
	
	twitterRoll.li = [];
	twitterRoll.el = this;
	twitterRoll.twitterCounter = 1;
	$("li",twitterRoll.el).each(function(i){
		twitterRoll.li[i] = { el : $(this), height: $(this).height() + twitterRoll.settings.margin };							  
	});
	$("li",twitterRoll.el).remove();
	this.animate({height: twitterRoll.settings.ul_height},twitterRoll.settings.ul_openingspeed);
	
	twitterRoll.rollout = function()
	{
		
		twitterRoll.el.prepend(twitterRoll.li[twitterRoll.twitterCounter].el.css({opacity: 0, height: '0px'}).show().animate({height : twitterRoll.li[twitterRoll.twitterCounter].height},twitterRoll.settings.showspeed,function(){$(this).animate({ opacity : 1}, twitterRoll.settings.slidespeed)}));
		twitterRoll.twitterCounter++;
		if (twitterRoll.twitterCounter >= twitterRoll.li.length) twitterRoll.twitterCounter = 0;
		if ($("li",twitterRoll.el).length > twitterRoll.settings.totallength)  $("li:last",twitterRoll.el).remove();

		setTimeout(twitterRoll.rollout, twitterRoll.settings.refreshrate);
	}
	
	// start twittering
	setTimeout( twitterRoll.rollout, twitterRoll.settings.startdelay);

}

})( jQuery );
