/*
 * jQuery hashchange event - v1.3 - 7/21/2010
 * http://benalman.com/projects/jquery-hashchange-plugin/
 * 
 * Copyright (c) 2010 "Cowboy" Ben Alman
 * Dual licensed under the MIT and GPL licenses.
 * http://benalman.com/about/license/
 */
(function($,e,b){var c="hashchange",h=document,f,g=$.event.special,i=h.documentMode,d="on"+c in e&&(i===b||i>7);function a(j){j=j||location.href;return"#"+j.replace(/^[^#]*#?(.*)$/,"$1")}$.fn[c]=function(j){return j?this.bind(c,j):this.trigger(c)};$.fn[c].delay=50;g[c]=$.extend(g[c],{setup:function(){if(d){return false}$(f.start)},teardown:function(){if(d){return false}$(f.stop)}});f=(function(){var j={},p,m=a(),k=function(q){return q},l=k,o=k;j.start=function(){p||n()};j.stop=function(){p&&clearTimeout(p);p=b};function n(){var r=a(),q=o(m);if(r!==m){l(m=r,q);$(e).trigger(c)}else{if(q!==m){location.href=location.href.replace(/#.*/,"")+q}}p=setTimeout(n,$.fn[c].delay)}$.browser.msie&&!d&&(function(){var q,r;j.start=function(){if(!q){r=$.fn[c].src;r=r&&r+a();q=$('<iframe tabindex="-1" title="empty"/>').hide().one("load",function(){r||l(a());n()}).attr("src",r||"javascript:0").insertAfter("body")[0].contentWindow;h.onpropertychange=function(){try{if(event.propertyName==="title"){q.document.title=h.title}}catch(s){}}}};j.stop=k;o=function(){return a(q.location.href)};l=function(v,s){var u=q.document,t=$.fn[c].domain;if(v!==s){u.title=h.title;u.open();t&&u.write('<script>document.domain="'+t+'"<\/script>');u.close();q.location.hash=v}}})();return j})()})(jQuery,this);





//Functions --------------------------------------------------------

//globals
var docW;
/*
//Change the page based on the navigation id
function changePage(e) {
	var page = e.attr("id");
	$(".page-on").fadeOut(800).removeClass("page-on");
	$("#page-"+page).delay(800).fadeIn(800).addClass("page-on");

}

function switchPage(e) {

	$(".page-on").fadeOut(800).removeClass("page-on");
	$("#page-"+page).delay(800).fadeIn(800).addClass("page-on");

}
*/
//on DOM load --------------------------------------------------------
$(function() {

	
	//Setup the gallery lightbox
	$(".gallery a").click( function(){ 
		var contents = $(this).children(".workdesc").html();
        $("#lightbox-content").html(contents);
        //$("#lightbox-content").html($(this).children());     
		var vidref;
        vidref = $(this).attr("href");
        $("#earth-lightbox-holder, #earth-lightbox").fadeIn(1200, function(){
        $("#lightbox-video").html("<embed bgcolor=\"#000000\" src=\"" + vidref +"\" width=\"512\" height=\"304\">");
		$("#lightbox-content").jScrollPane();
        });
        $("#work-col > div, .work-gallery p, #works-selected-directors").animate({opacity:0.3}, 1000);
        return false; 
	});
	$("#lightbox-close, #earth-lightbox-holder").click( function() {
	    $("#lightbox-video").html("&nbsp;");
	    $("#earth-lightbox-holder, #earth-lightbox").fadeOut(400);
	    $("#work-col > div, .work-gallery p, #works-selected-directors").animate({opacity:1}, 1000);
	    return false;
	});


    var j = 0;
    var s = "";
    var ss = "";
    var post = "";
    
    $(window).bind("hashchange", function () {
        
		
		
        var hash = window.location.hash || "home";
        s = hash.split("/")[0].replace("#","");
        ss = hash.split("/")[1];
        post = hash.split("/")[2];
        
        // If this is the 2nd time through
        if(j > 0) {
        	if (s == "home"){
        		$("#cont").addClass("hider");
        		$(".bigslide").css("position", "relative");
        	} else {
        		$("#cont").removeClass("hider");
        		$(".bigslide").css("position", "static");
        	}
        	
        	 if(post !== undefined) {
                // if we are displaying a post
            
                // Show section
                $("div#content > div").hide();
                $("#page-"+s).show();
        
                $("#nav a").removeClass("on");
                $("#nav a[hash=#" + s + "]").addClass("on");
                
                var _this = $("div#content > div:visible");
                
                // Show subsection
                $("div#content").fadeOut(400, function(){
                	$(_this).find("div.left-col > div").hide();
                	$(_this).find("div.left-col > div").filter(".work-"+ss).show();
                	$("div#content").fadeIn(400, function(){
                	    $("div#content > div:visible > div.left-col:visible > div:visible").find("li#"+ post +" a").click();
                	});
                });
            	        
                $("div#content > div:visible > div.right-col a").removeClass("on");
                $("div#content > div:visible > div.right-col a[hash=#" + s + "/" + ss + "]").addClass("on");
                
                            
            } else if (ss !== undefined) {
                // if we are displaying a subsection
        
                // Show section
                $("div#content > div").hide();
                $("#page-"+s).show();
        
                $("#nav a").removeClass("on");
                $("#nav a[hash=#" + s + "]").addClass("on");
                        
                // Show subsection
                $("div#content > div:visible > div.left-col").fadeOut(400, function(){
                	var _this = $("div#content > div:visible");
                	$(_this).find("div.left-col > div").hide();
                	$(_this).find("div.left-col > div").filter(".work-"+ss).show();
                	$(_this).find("div.left-col").fadeIn(400);
                });
            	

                $("div#content > div:visible > div.right-col a").removeClass("on");
                $("div#content > div:visible > div.right-col a[hash=#" + s + "/" + ss + "]").addClass("on");
        
            } else { 
					
				// we are displaying a section
				var _this = $("div#content > div:visible");
				
                // Show section
                $("div#content").fadeOut(400, function(){
                    $(_this).find("div.left-col > div.tab-me").hide();
         			$(_this).find("div.left-col > div.tab-me:first").show();
					
                    $(_this).find("div.right-col a").removeClass("on");
                    $(_this).find("div.right-col a:first").addClass("on");

                	$(_this).hide();
            		$("div#content").find("#page-"+s).show();
            		$("div#content").fadeIn(400);
                });
          	
                $("#nav a").removeClass("on");
                $("#nav a[hash=#" + s + "]").addClass("on");

            }
		
        }
        j++
    });
    
    $(window).trigger("hashchange");
    $(window).hashchange();
    

});





//on document load animate footer  ------------------------------
function bodyLoad() {
	
	//$("#footer-detail-3").fadeIn(500);
//	$("#footer-detail-2").delay(450).fadeIn(500);
	//$("#footer-detail-1").delay(900).fadeIn(500);
	//$("#footer").delay(1100).animate({width : "1090"}, 2000);

// Endlessly loop through homepage slide divs
function homeSlides() {	
	$("#home-slides div:first").delay(4000).slideUp(1000, function(){
	   $(this).appendTo("#home-slides").show();
	   homeSlides();
	});
} homeSlides();

}
