var App = function(){
	this.factDiv = '#factContent';
	this.factImage = 'factoid';
	this.totalFacts = 5;
	this.factImagesDir = 'images/facts/';
	this.startImage;
}

App.prototype.randomFact = function(){
	$(this.factDiv).animate({opacity: 1.0}, 800).fadeOut(1000);
	var obj = this;
	
    this.intervalID = setTimeout(function(){obj.newFact();}, 1800);
}

App.prototype.newFact = function(){
	this.nextImage();
	$(this.factDiv).fadeIn(1000);
	var obj = this;
    this.intervalID = setTimeout(function(){obj.randomFact();}, 10000);
}

App.prototype.randImage = function(){
	$('#factoid').empty();
	var newImage = App.prototype.randomNumber(this.totalFacts);
	$('#factoid').append("<img src='"+this.factImagesDir+newImage+".gif' />");
	this.startImage = newImage;
	
}

App.prototype.nextImage = function(){
	$('#factoid').empty();
	this.startImage++;
	if(this.startImage > this.totalFacts)
	{	
		this.startImage = 1;
	}
	$('#factoid').append("<img src='"+this.factImagesDir+this.startImage+".gif' />");
	

}

App.prototype.randomNumber = function(total){
    if((typeof(total) == 'number')&&(total > 0)){
        var range = 1/total;
        var index = Math.floor(Math.random()/range);
    }else
    {
        return 1;
    }
    return index+1;  
}

var app = new App();