$(function() {
    
/* dropdown menu */

    $('#nav li').hover(function(e){
        $(this).addClass('hover');
        $('ul:first', this).css('visibility', 'visible');
        
    }, function(){
        $(this).removeClass('hover');
        $('ul:first', this).css('visibility', 'hidden');
    });
    
/* menu styling adjestment */
    $('ul.submenu, ul.submenu li ul').find('li:last a').addClass('noborder');
    $('#nav > li:last ul').css({'left': 'auto', 'right': '0'});
    
/* interactive map */
    var spotClass = [];
    var mapName = '';
    
    $('#column_3 #map_detail .redchris').show();
    $('#column_3 #map_home span.redchris').show();
    
    var config = {
        over: function() {$('#column_3 .desc').hide();
                          $('#column_3 span.label').hide();
                          spotClass = $(this).attr('class');
                          mapName = spotClass.substr(5);
        
                          $('#column_3').find('.' + mapName).show();
                          $(this).next('span.label').show()},
        timeout: 200,
        out: function() {},
        sensitivity: 7,
        interval: 300
    };
    $('#map_home .spot').hoverIntent(config);
    
    
// Initiate Slideshow
rotator();
    
});

function rotator() {
        $('#homeBanner div').css('opacity', 0)
                            .eq(0).css('opacity', 1).addClass('active');
        
        setInterval('rotateIt()', 5000);
}

function rotateIt() {
    // Get the first image
    var currentImg = $('#homeBanner div.active') ? $('#homeBanner div.active') : $('#homeBanner div:first');

	// Get next image, when it reaches the end, rotate it back to the first image
    var nextImg = (currentImg.next().length) ? (currentImg.next().hasClass('active')) ? $('#homeBanner div:first') : currentImg.next() : $('#homeBanner div:first');	
	
	// Set the fade in effect for the next image, the active class has higher z-index
	nextImg.css('opacity', 0)
	       .addClass('active')
	       .animate({opacity: 1}, 1500);

	// Hide the current image
	currentImg.animate({opacity: 0}, 1500)
	          .removeClass('active');
                  
}

