// RotatePicturesAndText class
// Written by Paul Rosen

/*global Class, $ */
/*global crossfade, cacheImages */

var RotatePicturesAndText = Class.create({
	initialize: function (img_list, img_id, text_list, text_id) {
		// private variables
        var timerID = 0;
        var currPic = 0;
        var currText = 0;
        var secondsBetweenAds = 11; 
		
		// private functions
		function show_next() {
         	
 	        if (timerID) {
 		        clearTimeout(timerID);
 	        }
         	
            crossfade($(img_id), "images/" + img_list[currPic], '2', 'picture of flowers', 285);
 	        if (++currPic >= img_list.length) {
 		        currPic = 0;
 	        }
         	
            $(text_id).hide();
            $(text_id).update(text_list[currText]);
            $(text_id).appear();
            if (++currText >= text_list.length) {
                currText = 0;
            }
            
            timerID = setTimeout(function() { show_next(); }, secondsBetweenAds*1000);			
		};
		
	    setTimeout(function() { cacheImages('images/', img_list); }, 50);
        show_next();
	}
});
