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

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

function smallFront(leftValue) {
    $("#front").animate({
        width: 280,
        left: leftValue
    });
	$("#front").attr("src", "images/front_paper.png");
}

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

function contentFadeOut() {
    $("#collection").animate({
        top: -500
    });
    $("#aboutcol, .jScrollPaneContainer, #contact, #collection, #shops, #pdfs").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();
            
            callback();
            
            hideShops();
            
            if ($target) $target.fadeIn();
            
            window.location.hash = stringTarget;
            
        }
        return false;
    });
}

$(function() {

    $("#collection a").colorbox({
				slideshow:true,
				transition:"none", 
				speed:1500, 
				width:"75%", 
				height:"75%",
				slideshowStart:"START SLIDESHOW",
				slideshowStop:"STOP SLIDESHOW"
				
				});

	$(".shoploc").colorbox({width:"950", height:"500", iframe:true});

	
    var $front = $("#front"),
        $call = $("#sample"),
        $header = $("#header-target"),
        $upcoming = $("#upcoming"),
        $joker;
    
    $nav = $("nav a");

    var origFrontWidth = 549, // or test after window.load
        frontLeft = $front.position().left,
        origSampleTop = $call.position().top,
        origSampleLeft = $call.position().left,
        origHeaderTop = $header.css("top"),
        origUpcomingLeft = $upcoming.position().left;
    
    $(".about-link").click(function() {
        if (!$(this).hasClass("current")) {
            $("nav a").removeClass("current");
            $("nav .about-link").addClass("current");
            
			contentFadeOut();
            barTop();
            moveSample(541,0);
            smallFront(520);
            hideShops();
            $(".jScrollPaneContainer").fadeIn(); 
        }
    });

    $(".home-link").click(function(e) {
        if (!$(this).hasClass("current")) {
            $("nav a").removeClass("current");
            $("nav .home-link").addClass("current");
            //replace the front
			$("#front").attr("src", "images/front.png");
			contentFadeOut();
            
			$front.animate({
                width: origFrontWidth,
                left: frontLeft
            });
            $call.animate({
                top: origSampleTop,
                left: origSampleLeft
            });
            $header.animate({
                top: origHeaderTop
            });
            $upcoming.animate({
                left: origUpcomingLeft
            });
        }
    });
    
    var $showLoad = $("#shops ul").html();
    $("#show-target")
        .append($showLoad)
        .find("li:gt(1)").remove();
        
    $("#nav-aboutcol").animationClick(function() {
        moveSample(541, 0);
        smallFront(520);
    }, "#aboutcol");
    
    $("#nav-contact").animationClick(function() {
        moveSample(541, 0);
        smallFront(520);
        $("#pdfs").fadeIn();
    }, "#contact");
    
    $("#nav-collection").animationClick(function() {
        moveSample(20, 0);
        smallFront(20);
        $("#collection").fadeIn().animate({ top: 0 }); 
    }, "#collection");
    
    $(".shops-link").animationClick(function() {
        moveSample(20, 0);
        smallFront(20);
        $("#shops").fadeIn().animate({ left: 375 }); 
    }, "#shops");
    

       
   //$('#found').jScrollPane();
	
    
    $(".jScrollPaneContainer").hide();
    
    var hash = window.location.hash;
    hash = hash.replace(/^#/, '');
    switch (hash) {
        case 'about':
            $("." + hash + "-link:first").trigger("click");
            break;
        case 'shops':
            $("." + hash + "-link:first").trigger("click");
            break;
        case 'contact':
            $("#nav-" + hash ).trigger("click");
            break;
        case 'collection':
            $("#nav-" + hash ).trigger("click");
            break;
        case 'aboutcol':
            $("#nav-" + hash ).trigger("click");
            break;
    }
});

$("#stores").hide();
