
var quoteArray=Array();
var backToTopCounter=0;
var fadeTimer=3000;
var repeatRate=6000;



$(function() {
	$('.extra_time_information').each(function(){

		if($(this).html().length>1){
			$(this).parent().find('.time_info').hide();
		}

	})

	$('.extra_date_information').each(function(){

		if($(this).html().length>1){
			$(this).parent().find('H2').html($(this).html());
		}

	})


})





/*
|----------------------------------------------------------------------------------------------------------------------------------
| showQuote
|----------------------------------------------------------------------------------------------------------------------------------
|	
|	Places 3 random quotes at the top, then another ever 600px
|
*/
function showQuotes(numAtTop,repeatHeight,quoteHeight){
	
	if ($('#sidebar').attr('class')=='goto') return

	var n=0;

	$('.sidebarQuote').each(function(){
		quoteArray[n++]=$(this).html();	
	});
	
	numAtTop=numAtTop>n?n:numAtTop;

	$('.sidebarQuote').remove();	

	$('#sidebar').height($('#content').height());

	for (var i=0;i<numAtTop ; i++){
		$('#sidebar').append('<div class="sidebarQuote" id="quote_' + i + '"></div>');
	}
		
	for (var i=numAtTop+1;i<parseInt($('#sidebar').height()); i=i+repeatHeight+quoteHeight){

	//	if (i>n) break;	

		$('#sidebar').append('<div class="sidebarQuote spacedQuotes" id="quote_' + i + '"></div>' );


	}

	populateQuotes();
}




/*
|----------------------------------------------------------------------------------------------------------------------------------
| populateQuotes
|----------------------------------------------------------------------------------------------------------------------------------
|	
|
*/
function populateQuotes(){

	var quotes=quoteArray;
	quotes=quotes.sort(function() {return 0.5 - Math.random()});

	

	var n=0;
	$('.sidebarQuote').each(function(){

		$(this).fadeOut(fadeTimer,function(){


			if (quotes[n]!='undefined'){
			
				var gotoTop='';
				if (n%4==3 && backToTopCounter>1)	gotoTop='<a href="#top" class="gotoTop">Back to top</a>';

				$(this).html(quotes[n++] + gotoTop);	

				if ($(this).html()=='undefined')	{
						$(this).remove();
				}else{
					$(this).fadeIn(fadeTimer);
				}
			}
	
		});	
	});

	backToTopCounter++;	

	setTimeout('populateQuotes()',repeatRate);
}


/*
|----------------------------------------------------------------------------------------------------------------------------------
| rewrite of Javascript's unintuitive replace
|----------------------------------------------------------------------------------------------------------------------------------
|
|
|
*/
function str_replace(str1,str2,str ){

	var s=str.split(str1);
	return s.join(str2);
}
