// ================== Main Feature Loading  ==========================
// Set variables
var currentFeature = 1;
var featureActive = 0;
var rotateInterval = 5000;
var delayTimer = 0;
var nextFeature = 1;
var prevFeature = 0;
var numFeatures = $(".rotator_banner").length;

function delayFeatureTimer(){
		delayTimer = 1;
}

function changeFeature(feature_id){
		if(feature_id != currentFeature){
				prevFeature = currentFeature;
				currentFeature = feature_id;

				$("#rotator_image_"+currentFeature).show();
				//$("#rotator_button_"+currentFeature).attr("src", "/images/nav_"+currentFeature+"_active_bg.png");
				$("#rotator_button_"+currentFeature).css("background", "url('/images/nav_active_bg.png')");
				$("#rotator_image_"+prevFeature).hide();
				//$("#rotator_button_"+prevFeature).attr("src", "/images/nav_"+prevFeature+"_inactive_bg.png");
				$("#rotator_button_"+prevFeature).css("background", "url('/images/nav_inactive_bg.png')");

		}
}

function rotateFeatureBox(){
		if(delayTimer == 0){
				nextFeature++;
				if(nextFeature>numFeatures){
						nextFeature = 1;
				}
				changeFeature(nextFeature);
		} else {
				delayTimer = 0;
		}
		setTimeout ("rotateFeatureBox()", rotateInterval);
}

function gotoFeature(feature_id){
		changeFeature(feature_id);
		delayTimer = 0;
		delayFeatureTimer();
}

//                                                      $(document).ready(function(){
var featuresSearch = document.getElementsByTagName('div');
var featureCounter = 0;
$(".rotator_banner").each(function(){
	var bannerId = $(this).attr("id").substr(12);
	$("#rotator_button_"+bannerId).parents("a").attr("href", $(this).children("div").children("a").attr("href")); //Set button links and show them
	$("#rotator_button_"+bannerId).show();
});

setTimeout ("rotateFeatureBox()", rotateInterval);

//                                                      });
// *******************************************************************************
