jQuery(function() {  
   
     jQuery.fn.extend({
	 selectQuote: function()
	 {
	     if ((this.attr('id') != 'selectedQuote') && (this.attr('id') != 'lastQuote'))
	     {
		 this.stop(false,true).fadeOut(1);  
	     }
	     this.attr('id', 'selectedQuote');
	     this.stop(false,true).fadeIn(3000);  

	     var t = setTimeout('jQuery().nextQuote();', 5000);
	 },

	 deselectQuote: function()
	 {
	     var lastQuote = this.parent().find('#lastQuote');
	     if (lastQuote.length != 0)  //wrap around
	     {
		 this.removeAttr('id');
	     }
	     this.attr('id', 'lastQuote');
	     this.stop(false,true).fadeOut(3000);  
	 },

	 nextQuote: function()
	 {
	     var quote = jQuery('#quotes #selectedQuote');
	     var next = quote.next('blockquote');
	     if (next.length == 0)  //wrap around
	     {
		next = quote.parent().find('blockquote:first');
	     }

	     quote.deselectQuote();
	     next.selectQuote();
	 }
     });

     jQuery('#quotes blockquote:first').selectQuote();
 }); 

