document.write('<scr' + 'ipt type="text/javascript" src="../includes/gallery/tween.js"></scr' + 'ipt>');	

var currentFeature = 2; //start this at two since feature #1 is always visible initially
var intervalID = 0;
var featureCount = 0;

var featureTween = null;
var pointer = null;
var styleProperty = '';
var locations = new Array();
var imagesMain = new Array();
var imagesThumb = new Array();
var imagesThumbGray = new Array();

function initFeatureRotation(NumFeatures, PointerID, PointerStyleProperty, 
		PointerLocations, ImagesMain, ImagesThumb, ImagesThumbGray) {
		
	featureCount = NumFeatures;
	pointer = document.getElementById(PointerID);
	styleProperty = PointerStyleProperty;
	locations = PointerLocations;	
	imagesMain = ImagesMain;
	imagesThumb = ImagesThumb;
	imagesThumbGray = ImagesThumbGray;	
	featureTween = new Tween(pointer.style, styleProperty, '', locations[0], locations[featureCount], 1, 'px');
	
	swapFeature();
}


function moveArrow(imageID)
{
	//if the user has rolled over an item stop the rotation and reset
	stopRotation();	
	
	//reset all thumbnail images
	resetThumbnails();
	
	//turn on the item that is being hovered over
	document.getElementById('thumbnail-' + imageID).src = imagesThumb[imageID-1];
	
}

function swapFeature() {		
	intervalID = setInterval('rotate()', 7000);	
}

function rotate() 
{			
	//reset and select current
	resetFeatures();	
	setFeature(currentFeature);
	
	//move to the next one	
	if (currentFeature < featureCount) { 
		currentFeature = currentFeature + 1; 
	} else { 
		currentFeature = 1; 
	}
}

function resetThumbnails() 
{
	for (var x=1; x<=featureCount; x++) 
	{		
		document.getElementById('thumbnail-' + x).src = imagesThumbGray[x-1];		
	}
}

function resetFeatures() 
{
	for (var x=1;x<=featureCount;x++) {
		// set all thumbs to gray and hide all text
		document.getElementById('thumbnail-' + x).src = imagesThumbGray[x-1];
		document.getElementById('featureText-' + x).style.display = 'none';
	}
}

function setFeature(feature) 
{
	// set main pic
	var currFeaturePic = document.getElementById('mainPicture').src = imagesMain[feature-1];	
	currFeaturePic.src = imagesMain[feature-1];	
	
	// set selected thumb
	document.getElementById('thumbnail-' + feature).src = imagesThumb[feature-1];
	
	// set correct text
	document.getElementById('featureText-' + feature).style.display = 'block';
	
	/*
	//opacity
	var currFeaturePic		=	document.getElementById('mainPicture-'+feature);	
	var currOpacityTween	=	new OpacityTween(currFeaturePic, Tween.regularEaseIn, 50, 100, 1);
	currOpacityTween.start();*/

	//move the arrow
	featureTween.func	=	eval(Tween.backEaseOut);	
	featureTween.continueTo(locations[feature-1], 1);
}

function selectFeature(selection) {		
	//select clicked feature and then continue rotation		
	currentFeature = selection;
	resetFeatures();
	setFeature(selection);			
}

function selectFeatureAndStop(selection) {
	//stop the rotation and select clicked feature
	clearInterval(intervalID);	
	resetFeatures();
	setFeature(selection);
}

function stopRotation() {
	clearInterval(intervalID);
}

function nextFeature() {
	if (currentFeature < featureCount) { 
		currentFeature = currentFeature + 1; 
	} else { 
		currentFeature = 1; 
	}
	resetFeatures();
	setFeature(currentFeature);
}

function previousFeature() {
	if (currentFeature <= 1) { 
		currentFeature = featureCount; 
	} else { 
		currentFeature = currentFeature - 1; 
	}
	resetFeatures();
	setFeature(currentFeature);
}