// JavaScript Document
var interval; var speed; var t;
$.fn.slider = function(opts) {
	
	if(typeof(opts) !== 'undefined' && opts != null)
	{
		if(typeof(opts.interval) !== 'undefined' && opts.interval != null)
			interval = opts.interval;
		else interval = 4000;
		if(typeof(opts.speed) !== 'undefined' && opts.speed != null)
			speed = opts.speed;
		else speed = 1000;
	}
	else
	{
		interval = 4000;
		speed = 1000;
	}	
	t = setTimeout ('nextImage()', interval);
	$('#hero-1 a:first').addClass('active');
	$('#hero-1 a:last').addClass('last');
	$('.rotatorNav li:first').addClass('active');
	$('.rotatorNav li:last').addClass('last');

	$('.rotatorNav li').click(function () {
		clearTimeout(t);
		var index = $('.rotatorNav li').index(this);
		$('.rotatorNav li').removeClass('active');
		$(this).addClass('active');
		
		var bgImage = 'url(' + $('#hero-1 a.active img').attr('src') + ')';
		$('#hero-1').css('background', bgImage);
		$('#hero-1 a').hide().removeClass('active');
		$('#hero-1 a').each(function() {
			if($('#hero-1 a').index(this)==index)
			{
				$(this).addClass('active');
				$(this).hide();
				$('.rotatorNav li').show();
				$(this).fadeIn(speed);
			}
		});
		
		clearTimeout(t);
		t = setTimeout ('nextImage(speed,interval)', interval+speed);
	});
	
};
	
function nextImage()
{
	var curr = $('#hero-1 a.active');
	var bgImage = 'url(' + $('#hero-1 a.active img').attr('src') + ')';
	$('#hero-1').css('background', bgImage);
	$(curr).hide().removeClass('active');
	if($(curr).hasClass('last'))
	{
		$('#hero-1 a:first').addClass('active');
		$('#hero-1 a:first').hide();
		$('#hero-1 a:first').fadeIn(speed);
	}
	else
	{
		$(curr).next('a').addClass('active');
		$(curr).next('a').hide();
		$(curr).next('a').fadeIn(speed);
	}
	
	var curr = $('.rotatorNav li.active');
	$(curr).removeClass('active');
	if($(curr).hasClass('last')) $('.rotatorNav li:first').addClass('active');
	else $(curr).next('li').addClass('active');
	
	clearTimeout(t);
	t = setTimeout ('nextImage()', interval+speed);
}	
	
