function LoadSmallBanners(token){
	jQuery.ajax({		
		type: "POST",
		url: "system/ajaxcontroller/ajax_request.php",
		data: "ajax=1&controller=get_banner&module=home_small_featurebox&security_token=" + token,
		success: function(result){
			var banners = result.split(';');
			var banner_array = new Array();
			jQuery.each(banners,function(){
				var banner_data = this.split("|");
				banner_array.push(banner_data);
			});
			
			if(banner_array.length > 1)
				StartSmallRotation(banner_array,token);
		}
	});	
}

function SmallBannerPreload(banners){
	jQuery.each(banners,function(){
		jQuery('<img />').attr('src', this[0]).load(function(){
			jQuery('#small_banner_preload').append( jQuery(this) );
		});
	});
}

function StartSmallRotation(banners,token){
	SmallBannerPreload(banners);
	SmallBannerPE(banners);
}

var feature_small_handler = false;

function SmallBannerPE(banners){
	new PeriodicalExecuter(function(featurePE){
		SmallRotate(banners);			
		feature_handler = featurePE;
	},5);
}

function SmallRotate(banners){
	jQuery('#home_small_featurebox').fadeOut();
	jQuery('#home_small_featurebox').queue(function(){
		SelectNextSmallBanner(banners);
		jQuery(this).dequeue();
	});	
	
	jQuery('#home_small_featurebox').queue(function(){
		jQuery('#home_small_featurebox').fadeIn();
		jQuery(this).dequeue();
	});	
		
}

function SelectNextSmallBanner(banners){
	var last_image = jQuery('#home_small_feature_picture').attr('src');
	var x = 0;
	var last_image_key;
	var next_image;
	var num_images = banners.length;	
	
	jQuery.each(banners,function(){
		if(this[0] == last_image){
			last_image_key = x;			
		}
		x++;		
	});
	
	if(last_image_key == (num_images - 1)){
		next_image = 0;
	}
	else{
		next_image = last_image_key + 1;
	}
		
	jQuery('#home_small_feature_picture').attr('src',banners[next_image][0]);
}
