  
var topbannerInterval;

function iniTopbannerInterval(){
	topbannerInterval = setInterval('topbannerSlide("next")', 6000);
}

function topbannerSlide(type)
{
	//if no IMGs have the show class, grab the first image  
    var current = $('.header-slide p a.show');
    current.animate({opacity: 0.0}, 1000)  
    current.removeClass('show');
  	
  	if(type == 'next'){
  		//Get next image, if it reached the end of the slideshow, rotate it back to the first image  
	    var next = ((current.next().length != 0) ? current.next() : $('.header-slide p a:first'));
	    next.animate({opacity: 1.0}, 1000);
	    next.addClass('show');
	    
	    var aCurrent = $('.header-slide ul li .current');
	    //alert(aCurrent.);
	    aCurrent.removeClass('current');
	    
	    var aNext = ((aCurrent.parent('li').next().length != 0) ? aCurrent.parent('li').next() : $('.header-slide ul li:first'));
		aNext.find('a').addClass('current');
		
  	}else{
  		var next = $('.header-slide p a:eq('+type+')');
	    next.animate({opacity: 1.0}, 1000);
	    next.addClass('show');
  	}
}

$(function() {
	$('.header-slide p').css('background', 'none');
	$('.header-slide p a').css('opacity', '0.0');
	$('.header-slide p a').css('display', 'block');
	
	var first = $('.header-slide p a:first');
    first.animate({opacity: 1.0}, 1000)  
    first.addClass('show');
    
    iniTopbannerInterval()
    
    $('.header-slide ul li a').click(function(e){
    	e.preventDefault(); //Cancel the link behavior
    	
    	$('.header-slide ul li a').removeClass('current');
    	$(this).addClass('current');
    	
    	topbannerSlide($(this).attr('href').substr(1));
    	clearInterval(topbannerInterval);
    	iniTopbannerInterval()
    });
});
  



