
var imgCnt;
var sliderTimeout = 8000; //time between carousel spinning
var leftCnt = 0;

var interval;
var currentLink = null;

$(function(){
	
	//$('#fborder_br').css('z-index', '1000');

	imgCnt = 1;
	
	//assignImg();
	
	//preloaderFeatureImages();
	
	$("#slideBtn").click(function() {
		runEffect();
		return false;
	});
	
	loadFeatureFooterContent(1);
	
	interval = setTimeout("runEffect()", sliderTimeout);
	
	$('#featureLink').click(function() { window.location = currentLink; });
});


// right arrow to advance to next slide
function nextSlide()
{
	clearInterval(interval);
	runEffect();
}

// left arrow to go to previous slide
function previousSlide()
{
	clearInterval(interval);
	runEffectBackwards()
}

function runEffect()
{
	var options = { direction:"left", distance:"600" };
	
	if(leftCnt >= 2400)
	{
		var leftAct = '+=2400';
		leftCnt = -600;
	}
	else
	{
		var leftAct = '-=600';
	}
	
	$('#featureImage').animate({
		left: leftAct
	}, 1000, function() {
		// Animation complete
	});
	
	leftCnt = leftCnt + 600;
	
	// 0 = 1
	// 600 = 2
	// 1200 = 3
	// 1800 = 4
	// 2400 = 5
	
	if(leftCnt == 0) imgCnt = 1;
	else if(leftCnt == 600) imgCnt = 2;
	else if(leftCnt == 1200) imgCnt = 3;
	else if(leftCnt == 1800) imgCnt = 4;
	else if(leftCnt == 2400) imgCnt = 5;
	
	//$('#leftCnt').html('#featureAnchor_' + String(imgCnt));
	
	loadFeatureFooterContent(imgCnt);
	
	interval = setTimeout("runEffect()", sliderTimeout);
}

function runEffectBackwards()
{
	
	
	if(imgCnt == 1)
	{
		var leftAct = '-=2400';
		leftCnt = 3000;
	}
	else
	{
		var leftAct = '+=600';
	}
	
	$('#featureImage').animate({
		left: leftAct
	}, 1000, function() {
		// Animation complete
	});
	
	leftCnt = leftCnt - 600;
	
	// 0 = 1
	// 600 = 2
	// 1200 = 3
	// 1800 = 4
	// 2400 = 5
	
	if(leftCnt == 0) imgCnt = 1;
	else if(leftCnt == 600) imgCnt = 2;
	else if(leftCnt == 1200) imgCnt = 3;
	else if(leftCnt == 1800) imgCnt = 4;
	else if(leftCnt == 2400) imgCnt = 5;
	
	//$('#leftCnt').html(String(leftCnt) +':' + String(imgCnt));
	
	//alert(leftCnt);
	
	loadFeatureFooterContent(imgCnt);
	
	interval = setTimeout("runEffect()", sliderTimeout);
}

function loadFeatureFooterContent(cnt)
{
	var artTitle = $('#featureAnchor_' + String(cnt)).attr('title');
	
	var artExc = $('#featureAnchor_' + String(cnt)).attr('rel');
	
	var href = $('#featureAnchor_' + String(cnt)).attr('href');
	
	$('#featureTitle').html(artTitle + artExc);
	
	currentLink = href;
	//$('#featureLink').attr('onclick', "window.location='" + href + "';");
}

// callback function to bring a hidden box back
function callback() {
	setTimeout(function() {
		$( "#effect" ).removeAttr( "style" ).hide().fadeIn();
	}, 1000 );
};

function assignImg()
{
	//$('#featureImage').html("<img src='" + $('#featImg_' + imgCnt).val() + "'>");
	//$('#featureTitle').html( $('#featTitle_' + imgCnt).val());
}

/**
* preloads all feature carousel images
*/
function preloaderFeatureImages() 
{
	i = 1;
	
	while (i <= 5)
	{
		//$('<img/>')[0].src = $('#featImg_' + i).val();
	i++;
	}
}
