$(document).ready(function()
{
	// Home Page Rotating Banner
	$(".tabs").tabs(".panes > div", { effect: 'fade', fadeOutSpeed: 'slow', fadeInSpeed: 'slow', rotate: true }).slideshow({ autoplay: true, autopause: true, interval: 8000, clickable: false });
	$(".tabs a").click( function() {
		$(".tabs").data("slideshow").stop();
	});
	
	// Lightbox
	$("a.lightbox").click( function() {
		var target = $(this).attr("href");
		var content = $(target).html();
		var title = $(this).attr("title");
		
		$('#lightbox').overlay(
		{
		   	expose:
			{
				color: '#000', 
		       	loadSpeed: 200, 
		       	opacity: 0.5 
		   	},
		   	api: true
		}).load();
		$('#lightbox .title').html(title);
		$('#lightbox .content').html(content);
		return false;
	});
	
	// If the sidebar is taller than the main div expand the height of the content div
	var sidebarHeight = $("#sidebar").outerHeight();
	var mainHeight = $("#main").outerHeight();
	var footerHeight = $("#footer").outerHeight() + $("#infoContainer").outerHeight();
	//alert("side:" + sidebarHeight + "\nmain:" + mainHeight);
	if ( sidebarHeight > mainHeight ) {
		$("#content").height( sidebarHeight - footerHeight );
	}
		
	// Info Slider Init
	var height = $("#info").height();
	if ( $("body").hasClass("home") ) {
		$("#info div h3 span").addClass("expanded");
	} else {
		$("#info").height(18);
	}
	
	// Info Slider
	$("#info h3").click( function() {
		if ( $("#info div h3 span").hasClass("expanded") ) {
			$("#info").animate({height: '18'}, 500);
			$("#info div h3 span").removeClass("expanded");
		} else {
			$("#info").animate({height: height}, 500);
			$("#info div h3 span").addClass("expanded");
		}
	});
	
	// Smooth Slide Internal Links
	$('a[href*=#]').click(function() {
    	if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
            var $target = $(this.hash);
            $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
            if ($target.length) {
                var targetOffset = $target.offset().top;
                $('html,body').animate({scrollTop: targetOffset}, 1000);   
                return false;   
            }  
        }  
    });

	// Add Last Class to Lists
	$("ul").each( function() {
		$(this).children("li:last").addClass("last");
	});
});
