function barTop() {
    $("#header-target").animate({
        top: 0
    });
}

function moveMusic( leftValue, topValue ) {
    $("#music").animate({
        top: topValue,
        left: leftValue
    });
}

function moveSignature() {
    $("#signature").animate({
        top: 10,
        left: 0
    });
}

function hideUpcoming() {
    $("#upcoming").animate({
        left: -800
    });
}

function smallCasey(leftValue) {
    $("#casey").animate({
        width: 280,
        left: leftValue
    });
}

function contentFadeOut() {
	$("#photos").animate({
	        top: -500
	    });

    $("#bio, #about, #contact, #photos, #news").fadeOut();
}

var $nav;
    
$.fn.animationClick = function(callback, target) {

    var stringTarget = target,
        $target = target ? $(target) : null;
    
    return this.click(function(e) {
        
        if (!$(this).hasClass("current")) {
                
            $nav.removeClass("current");
            $(this).addClass("current");
            
            contentFadeOut();
            barTop();
            moveSignature();
            
            callback();
            
            hideUpcoming();
            
            if ($target) $target.fadeIn();
            
            window.location.hash = stringTarget;
            
        }
        
        return false;
                
    });
    
}


soundManager.url = 'swf/'; // directory where SM2 .SWFs live
soundManager.debugMode = false;

$(function() {

$("#photos a").colorbox({ transition:"fade",
							width:"400px" });


	 var $casey = $("#casey"),
         $sign = $("#signature"),
         $tracks = $("#music"),
         $header = $("#header-target"),
         $upcoming = $("#upcoming");

		$nav = $("nav a");

	var origCaseyWidth = 600, // or could test after window.load
        origCaseyLeft = $casey.position().left,
        origMusicTop = $tracks.position().top,
        origMusicLeft = $tracks.position().left,
        origSignTop = $sign.position().top,
        origSignLeft = $sign.position().left,
        origHeaderTop = $header.css("top"),
        origUpcomingLeft = $upcoming.position().left;
        
   $(".home-link").click(function(e) {
        if (!$(this).hasClass("current")) {
            $("nav a").removeClass("current");
            $(".news-link").removeClass("current");
            $("nav .home-link").addClass("current");
            contentFadeOut();
            $casey.animate({
                width: origCaseyWidth,
                left: origCaseyLeft
            });
            $sign.animate({
                top: origSignTop,
                left: origSignLeft
            });
            $tracks.animate({
                top: origMusicTop,
                left: origMusicLeft
            });
            $header.animate({
                top: origHeaderTop
            });
            $upcoming.animate({
                left: origUpcomingLeft
            });
        }
    });
    
    $(".news-link").click(function() {
        if (!$(this).hasClass("current")) {
            $("nav a").removeClass("current");
            $(".news-link").removeClass("current");
            $(".news-link").addClass("current");
            contentFadeOut();
            barTop();
            moveSignature();
	        moveMusic(20, 0);
	        smallCasey(20);
            hideUpcoming();
            $("#news").fadeIn().animate({ left: 375 });  
        }
    }); 
    
    var $newsLoad = $("#news ul").html();
    $("#news-target")
        .append($newsLoad)
        .find("li:gt(1)").remove();
    
    $("#nav-bio").animationClick(function() {
        moveMusic(741, 0);
        smallCasey(700);
    }, "#bio");
    
    $("#nav-photos").animationClick(function() {
	        moveMusic(20, 0);
	        smallCasey(20);
        $("#photos").fadeIn().animate({ top: 0 }); 
    }, "#photos");



 var hash = window.location.hash;
    hash = hash.replace(/^#/, '');
    switch (hash) {
        case 'about':
            $("." + hash + "-link:first").trigger("click");
            break;
        case 'news':
            $("." + hash + "-link:first").trigger("click");
            break;
        case 'contact':
            $("#nav-" + hash ).trigger("click");
            break;
        case 'photos':
            $("#nav-" + hash ).trigger("click");
            break;
        case 'bio':
            $("#nav-" + hash ).trigger("click");
            break;
    }


});
