var t;

$(function(){
	
	$('#homeGallery a > img').hide();
	$('#homeGallery  a > img:first').show();
	$('.navi').find('a:first').addClass('selected').addClass('firstselected');

	t = setTimeout("changeBanner()",4000);

	
	$('.navi').find('a').click(function(){		
		clearTimeout(t);
		var current = $('.navi').find('a.selected').attr('rel');
		var next = $(this).attr('rel');
		
		if(next == current)
			return false;
		
		$('.navi').find('a.selected').removeClass('selected').removeClass('firstselected').removeClass('lastselected');
		$(this).addClass('selected');
		
		if($(this).attr('rel') == 5)
			$(this).addClass('lastselected');
		if($(this).attr('rel') == 1)
			$(this).addClass('firstselected');
		
		$('#homeGallery a > img:eq('+ (current-1) +')').fadeOut(1000);
		$('#homeGallery a > img:eq('+ (next-1) +')').fadeIn(1000);
		
		return false;
	});

});

function changeBanner()
{
	var current = parseInt($('.navi').find('a.selected').attr('rel'));
	$('.navi').find('a.selected').removeClass('selected').removeClass('firstselected').removeClass('lastselected');
	
	var next = 1;
	if(current < 5)
		next = current+1;
	
	var sel = $('.navi').find('a[rel='+ next +']');
	
	sel.addClass('selected');
	
	if(sel.attr('rel') == 5)
		$(this).addClass('lastselected');
	if(sel.attr('rel') == 1)
		$(this).addClass('firstselected');
	
	$('#homeGallery a > img:eq('+ (current-1) +')').fadeOut(1000);
	$('#homeGallery a > img:eq('+ (next-1) +')').fadeIn(1000);
	
	t = setTimeout("changeBanner()",4000);
	
}
