function initBanner () {
	var $on = $("#bannernav a.on");
	if ( $on.length == 0 ) $on = $("#bannernav a:first");
	
	$on.addClass("on");
	
	
	//On Click
	$("#bannernav a").click(function() {
		$("#bannernav a.on").removeClass( 'on' );
		$on = $(this); //Activate the clicked paging
		$on.addClass("on");
		
		var targetNum = Number( $on.attr('rel') ) - 1;
		var $target = $('.slideshow-fade img').eq(targetNum);
		
		swapToRelatedImage( $on );
		
		clearInterval(play); //Stop the rotation
		return false; //Prevent browser jump to link anchor
	});
	
	function swapToRelatedImage( $link ) {
		var targetNum = Number( $link.attr('rel') ) - 1;
		var $new = $('.slideshow-fade img').eq(targetNum);
	
		$active = $('.slideshow-fade img.active');
		$active.addClass('last-active');
		
		$new.css({opacity: 0.0})
			.addClass('active')
			.animate({opacity: 1.0}, 1000, function () { 
				$active.removeClass('active last-active');
			});
	}

	function slideshowFade( ) {
		var $on = $("#bannernav a.on");
		if ( $on.length == 0 ) $on = $("#bannernav a:first");
		
		$on.removeClass("on");
		
		var $next = $on.next().length ? $on.next() : $('#bannernav a:first' ); // if there's a next link, go there, otherwise go to the first one
		
		$next.addClass("on");
		 swapToRelatedImage( $next );
	}
	
	function startSlideshow() {
		play  = setInterval( slideshowFade, 4000 ); //start slideshow

	}
	
	startSlideshow();
	
}


/*------------------------------------------------------------------------------*/

function initMenu() {
	$("ul.dropmenu li").hover(function() { 
			$("ul:first", this ).css('visibility', 'visible' ).css('z-index', '1000');
			$("#social a").css('display', 'inline');
		}, function () {
			$('ul:first', this).css('visibility', 'hidden' );
		} );
}


/*------------------------------------------------------------------------------*/

function initScrollPane() {
	$('#locations-pane').jScrollPane({showArrows:true, scrollbarWidth: 15, arrowSize: 16});
}



/*------------------------------------------------------------------------------*/

function initLocations() {
	
	function clickLocation() {
		clearInterval( locationInterval );
		clearTimeout( locationTimeout );
		$('#locationsnav a').removeClass('on');
		$("#locations .activeLocation").animate({opacity: 0.5}, 500, function() {$("#locations .activeLocation").removeClass('activeLocation');});
		
		//ar targetNum = Number($(this).attr('rel')) - 1;
		$(this).addClass('on');
		var $target = $('#' + $(this).attr('rel') );
		$('.location').css({opacity: 0.5});
		$target.addClass('inMotion').animate({opacity: 0.0}, 500, fadeToTop);
		return false;
	}
	
	function hoverLocation() {
		clearInterval( locationInterval );
		clearTimeout( locationTimeout );
		$('#locationsnav a').removeClass('on');
		$("#locations .activeLocation").removeClass('activeLocation');
		//ar targetNum = Number($(this).attr('rel')) - 1;
		$(this).addClass('on');
		var $target = $('#' + $(this).attr('rel') );
		$('.location').css({opacity: 0.5});
		$target.addClass('inMotion');
		jumpToTop();
		return false;
	}
	
	function fadeToTop(  ) {
		$target = $('#locations .inMotion').remove();
		$('#locations').prepend( $target );

		$target.removeClass( 'inMotion' );
		
		$('.location').removeClass( 'activeLocation' );
		
		$target.animate({opacity: 1.0}, 1000).addClass('activeLocation');
	}
	
	
	function jumpToTop() {
		$target = $('#locations .inMotion').remove();
		$('#locations').prepend( $target );

		$target.removeClass( 'inMotion' );
		
		$('.location').removeClass( 'activeLocation' );
		
		$target.css('opacity', 1.0 ).addClass('activeLocation');
	}
	
	
	
	function rotateLocation() {
		var $active = $('#locationsnav a.on');
		
		var $next = $active.next('a').length? $active.next('a') : $('#locationsnav a:first')
		
		$active.removeClass('on').addClass('inactive');
		$('#' + $active.attr('rel') ).animate({opacity: 0.5}, 500);
		
		$next.addClass('on');
		
		var $target =  $('#' + $next.attr('rel') );
		$target.addClass('inMotion').animate({opacity: 0.0}, 200, fadeToTop);
	}
	
	function startLocationRotation() {
		$('.location').animate({opacity: 0.5}, 500, 
			function () {$('.location:first').css({opacity:0.0}).addClass('activeLocation').animate({opacity:1.0}, 500)}

			
			); //hack at end for ie6
		
		$('#locationsnav a:first').addClass( 'on' );
		locationInterval = setInterval( rotateLocation, 3000 );
	}
	
	var locationInterval;
	$('#locationsnav a').hover( hoverLocation, function() {} ).click(hoverLocation);
	var locationTimeout = setTimeout( startLocationRotation, 3000 );
}



/*------------------------------------------------------------------------------*/

function initTestimonials() {
	function testimonialsFader() {
		var $active = $("#testimonials .active");
		$active.removeClass('active').animate( {opacity: 0.0}, 1000 );
		
		var $next = $active.next().length ? $active.next() : $(".testimonial-group:first");
		
		$next.css({opacity: 0.0, visibility:'visible'}).animate( {opacity: 1.0}, 2000 ).addClass('active')
	}
	
	setInterval( testimonialsFader, 7000 );

}

/*------------------------------------------------------------------------------*/
function initMapsPopup() {


	//$('a.mapLink').nyroModal();
	
}
