// Copyright (c) 2010 TrendMedia Technologies, Inc., Brian McNitt. 
// All rights reserved.
//
// Released under the GPL license
// http://www.opensource.org/licenses/gpl-license.php
//
// **********************************************************************
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
// **********************************************************************

$(window).load(function() {	//start after HTML, images have loaded

	var InfiniteRotator = 
	{
		init: function()
		{
			//initial fade-in time (in milliseconds)
			var initialFadeIn = 2500;
			
			//interval between items (in milliseconds)
			var itemInterval = 5000;
			
			//cross-fade time (in milliseconds)
			var fadeTime = 2500;
			
			//count number of items
			var numberOfItems = $('.rotating-item-1').length;

			//set current item
			var currentItem = 0;

			//show first item
			$('.rotating-item-1').eq(currentItem).fadeIn(initialFadeIn);

			//loop through the items		
			var infiniteLoop = setInterval(function(){
				$('.rotating-item-1').eq(currentItem).fadeOut(fadeTime);

				if(currentItem == numberOfItems -1){
					currentItem = 0;
				}else{
					currentItem++;
				}
				$('.rotating-item-1').eq(currentItem).fadeIn(fadeTime);

			}, itemInterval);	
		}	
	};

	InfiniteRotator.init();
	
var InfiniteRotator2 = 
	{
		init: function()
		{
			//initial fade-in time (in milliseconds)
			var initialFadeIn2 = 500;
			
			//interval between items (in milliseconds)
			var itemInterval2 = 4000;
			
			//cross-fade time (in milliseconds)
			var fadeTime2 = 2000;
			
			//count number of items
			var numberOfItems2 = $('.rotating-item-2').length;

			//set current item
			var currentItem2 = 0;

			//show first item
			$('.rotating-item-2').eq(currentItem2).fadeIn(initialFadeIn2);

			//loop through the items		
			var infiniteLoop2 = setInterval(function(){
				$('.rotating-item-2').eq(currentItem2).fadeOut(fadeTime2);

				if(currentItem2 == numberOfItems2 -1){
					currentItem2 = 0;
				}else{
					currentItem2++;
				}
				$('.rotating-item-2').eq(currentItem2).fadeIn(fadeTime2);

			}, itemInterval2);	
		}	
	};

	InfiniteRotator2.init();
	
var InfiniteRotator3 = 
	{
		init: function()
		{
			//initial fade-in time (in milliseconds)
			var initialFadeIn3 = 400;
			
			//interval between items (in milliseconds)
			var itemInterval3 = 3000;
			
			//cross-fade time (in milliseconds)
			var fadeTime3 = 2000;
			
			//count number of items
			var numberOfItems3 = $('.rotating-item-3').length;

			//set current item
			var currentItem3 = 0;

			//show first item
			$('.rotating-item-3').eq(currentItem3).fadeIn(initialFadeIn3);

			//loop through the items		
			var infiniteLoop3 = setInterval(function(){
				$('.rotating-item-3').eq(currentItem3).fadeOut(fadeTime3);

				if(currentItem3 == numberOfItems3 -1){
					currentItem3 = 0;
				}else{
					currentItem3++;
				}
				$('.rotating-item-3').eq(currentItem3).fadeIn(fadeTime3);

			}, itemInterval3);	
		}	
	};

	InfiniteRotator3.init();
	
var InfiniteRotator4 = 
	{
		init: function()
		{
			//initial fade-in time (in milliseconds)
			var initialFadeIn4 = 500;
			
			//interval between items (in milliseconds)
			var itemInterval4 = 4000;
			
			//cross-fade time (in milliseconds)
			var fadeTime4 = 2000;
			
			//count number of items
			var numberOfItems4 = $('.rotating-item-4').length;

			//set current item
			var currentItem4 = 0;

			//show first item
			$('.rotating-item-4').eq(currentItem4).fadeIn(initialFadeIn4);

			//loop through the items		
			var infiniteLoop4 = setInterval(function(){
				$('.rotating-item-4').eq(currentItem4).fadeOut(fadeTime4);

				if(currentItem4 == numberOfItems4 -1){
					currentItem4 = 0;
				}else{
					currentItem4++;
				}
				$('.rotating-item-4').eq(currentItem4).fadeIn(fadeTime4);

			}, itemInterval4);	
		}	
	};

	InfiniteRotator4.init();

});
