// JavaScript Document
function FeaturedSlider(id, args)
{
	var interval = -1;
	var divId = id;
	var count = jQuery(".ref-image-item", divId).length;
	var isTweening = false;
	
	var props = args == undefined ? new Object() : args;
	if(props.auto == undefined) props.auto = false;
	if(props.autoDelay == undefined) props.autoDelay = 5000;
	if(props.tweenTime == undefined) props.tweenTime = 500;
	if(props.startImage == undefined) props.startImage = 0;
	if(props.ref == undefined) props.ref = false;
	if(props.auto) interval = setInterval(autotween, props.autoDelay);
	
	var actualIndex = props.startImage;
	jQuery('.ref-navi', divId).find('li:nth('+actualIndex+')').addClass('active');
	
	jQuery(".ref-image-item", divId).each(function(i)
	{
		if(i != props.startImage) jQuery(this).css("left", 644);
	});
	
	if(!props.ref){
		jQuery(".ref-headline-item", divId).each(function(i)
		{
			if(i != props.startImage) jQuery(this).css("left", 650);
		});
	}
	
	jQuery("li", divId).each(function(i)
	{
		jQuery(this).bind("click", { id:i }, function(e)
		{
			fadeTo(e.data.id, false);
		});
	});
	
	function fadeTo(index, fromAuto)
	{
		if(isTweening || actualIndex == index) return;
		isTweening = true;
		jQuery('.ref-navi', divId).find('li:nth('+index+')').addClass('active');
		jQuery('.ref-navi', divId).find('li:nth('+actualIndex+')').removeClass('active');
		if(!fromAuto && props.auto){
			clearInterval(interval);
			interval = setInterval(autotween, props.autoDelay);
		}
		jQuery(divId).find('.ref-image-item:nth('+index+')').css("left", 644);
		if(!props.ref) jQuery(divId).find('.ref-headline-item:nth('+index+')').css("left", 650);
		jQuery(divId).find('.ref-image-item:nth('+actualIndex+')').animate({left:-644}, {duration:props.tweenTime});
		if(!props.ref) jQuery(divId).find('.ref-headline-item:nth('+actualIndex+')').animate({left:-650}, {duration:props.tweenTime});
		actualIndex = index;
		jQuery(divId).find('.ref-image-item:nth('+actualIndex+')').animate({left:0}, {duration:props.tweenTime, complete:tweenFin});
		if(!props.ref) jQuery(divId).find('.ref-headline-item:nth('+actualIndex+')').animate({left:10}, {duration:props.tweenTime, complete:tweenFin});
	};
	
	function tweenFin()
	{
		isTweening = false;
	};
	
	function autotween()
	{
		var tweenTo = actualIndex;
		if(++tweenTo>count-1) tweenTo = 0;
		fadeTo(tweenTo, true);
	};
};
