
    // default easing
    jQuery.easing.def = "easeOutSine";

    // skybox functions
    var skybox = {

        // google track code
        trackpage: function(){
            var page = window.location.href;
            //console.log(page);
            pageTracker._trackPageview(page);
        },

        // page nudge
        pageNudge: function(){
            // nudge page
            $("#main_wrapper").stop().animate({'padding-top':0}, {queue:false, duration:400, easing:'easeOutSine'});
        },

        // static navigation
        staticNav: function(){
            var windowPosition = $(window).scrollTop();
            if(navPosition > windowPosition){
                $("#sidenav").css({'top' : (navPosition-windowPosition)});
            }else{
                $("#sidenav").css({'top' : 0});
            }
        },

        gotoAnchor: function(){
            var elementClick = $(this).attr("href");
            var destination = $(elementClick).offset().top;
            var duration = 1000;
            var easing = 'easeInOutSine';
            var callback = function(){
                            window.location.hash = '#'+elementClick.split("#").join("/");
                            skybox.trackpage();
                        };

            $("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, duration, easing, callback);
            return false;
        },

        loadWork: function(dataID){

            $contentHolder = $("#work_content");
            $mainContent = $("#work_content_loader");
            $contentCloser = $("#closer");

            // keep content on last scrollposition
            $currentScrollPosition = $(window).scrollTop();

            // add bottom border
            $contentHolder.css('border-bottom', 'solid 1px #000000');

            $contentCloser.fadeOut(300);
            $mainContent.fadeOut(300, function() {

                $mainContent.hide().load('php/hardcoded_demodata_'+dataID+'.php', 'var=blah&var=bleh', function(responseText, textStatus, XMLHttpRequest) {
                    if(textStatus == 'error'){
                        // page not found
                        $mainContent.html("<h1>whoops, page not found...</h1>");
                        $mainContent.fadeIn(200);
                        $contentCloser.fadeOut(200);
                    }else{
                        //
                        // show page
                        $contentHolder.animate({height: $mainContent.height()}, {queue:false, duration:500, easing:'easeInOutSine'});
                        $mainContent.delay(300).fadeIn(300);
                        $contentCloser.delay(300).fadeIn(300);
                    }

                });
            });
        },

        closeWork: function(){
            $contentHolder = $("#work_content");
            $mainContent = $("#work_content_loader");
            $contentCloser = $("#closer");

            $contentCloser.fadeOut(300);
            $mainContent.fadeOut(300, function(){
                //alert('unload stuff');
                $mainContent.empty();
                $contentHolder.animate({height: 0}, {queue:false, duration:500, easing:'easeInOutSine'});
                $contentHolder.css('border-bottom', 'solid 0px #000000');
            });
        },

        workClick: function(){

            var currentItem = $(this).attr('id');
            var dataID = currentItem.split('_')[1];

            var elementClick = $(this).attr("href");
            var destination = $(elementClick).offset().top;
            if($(window).scrollTop()-destination == 0){
                var duration = 0;
            }else{
                var duration = 500;
            }
            var easing = 'easeInOutSine';
            var callback = function(){
                                skybox.loadWork(dataID);
                                //window.location.hash = currentItem;
                                window.location.hash = '/'+currentItem;
                                skybox.trackpage();
                            };

            $("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, duration, easing, callback);
            return false;

        },

        animateWork: function(){
            $('#work_items #imageholder').each(function() {
                //$(this).delay(delayImageFadein).fadeIn(200);
                $(this).delay(delayImageFadein).animate({opacity: 1}, 500);
                delayImageFadein += 200;
            });
        }

    }


    // hash change
    $(function(){

      // Bind an event to window.onhashchange that, when the history state changes,
      // gets the url from the hash and displays either our cached content or fetches
      // new content to be displayed.
      $(window).bind( 'hashchange', function(e) {

        // Get the hash (fragment) as a string, with any leading # removed. Note that
        // in jQuery 1.4, you should use e.fragment instead of $.param.fragment().
        var url = $.param.fragment();

        //console.log(url);
      })

      // Since the event is only triggered when the hash changes, we need to trigger
      // the event now, to handle the hash the page may have loaded with.
      $(window).trigger( 'hashchange' );

    });




    // variables for sticky menu
    var navOffset;
    var navPosition;

    // variables for image animation
    var delayImageFadein = 500;

    $(document).ready(function(){

        // all work images invisible
        $('#work_items #imageholder').each(function() {
            $(this).css({ opacity: 0 });
        });


        // position sticky menu and set variables
        navOffset = $('#about').offset();
        navPosition = navOffset.top-41;
        $("#sidenav").css({'top' : navPosition});

        // start loader and init site | nudge site
        QueryLoader.init();

        // nudge links
        $('a.nudge').hover(function() { //mouse in
            $(this).animate({backgroundColor: "#FF00AA", 'padding-bottom':7}, 200);
        }, function() { //mouse out
            $(this).animate({backgroundColor: "#FFFFFF", 'padding-bottom':3}, 200);
        });

        // nudge sidebar
        $('a.nudge_high').hover(function() { //mouse in
            $(this).animate({backgroundColor: '#FF00AA', 'padding-bottom':20}, 200);
        }, function() { //mouse out
            $(this).animate({backgroundColor: "#000000", 'padding-bottom':0}, 200);
        });

        // nudge about links
        $('#about a').hover(function() { //mouse in
            $(this).animate({backgroundColor: "#000000", 'padding-left':5, 'color':"#FFFFFF"}, 200);
        }, function() { //mouse out
            $(this).animate({backgroundColor: "#FFFFFF", 'padding-left':0, 'color':"#000000"}, 200);
        });

        // nudge workitems
        $('#work_items li').hover(function() { //mouse in
            if($(this).hasClass("active")){
                $(this).animate({backgroundColor: "#000000"}, 200);
                $(this).find("h2").css({backgroundPosition: '-195px bottom'});
                $(this).find("h2, p").animate({color: "#FFFFFF"}, 200);
                $(this).find("#imageholder").animate({backgroundPosition: '-195px 0px'}, {queue:false, duration:200, easing:'easeInOutSine'});
            }


        }, function() { //mouse out
            if($(this).hasClass("active")){
                $(this).animate({backgroundColor: "#FFFFFF"}, 200);
                $(this).find("h2").css({backgroundPosition: '0px bottom'});
                $(this).find("h2, p").animate({color: "#000000"}, 200);
                $(this).find("#imageholder").animate({backgroundPosition: '0px 0px'}, {queue:false, duration:200, easing:'easeInOutSine'});
            }
        });

        // set featured link and highlite
        $('#featured_work a, #featured_mail a').find("span").css("backgroundColor","transparent");
        $('#featured_work a, #featured_mail a').hover(function() {
            //$(this).find("span").css("backgroundColor","#FF00AA");
            $(this).find("span").animate({backgroundColor: "#FF00AA"}, 500);
        }, function() { //mouse out
            $(this).find("span").stop().css("backgroundColor","transparent");
            //$(this).find("span").animate({backgroundColor: "transparent"}, 200);
        });

        // page anchor linking
        $('a[rel="anchor"]').click(skybox.gotoAnchor);

        // work clicks
        $("#work_items a, #featured_work a, #whatsup_content a").click(skybox.workClick);

        // close workitem
        $("#closer").click(skybox.closeWork);

        // window resizer
        //$(window).resize(function () {
            //
        //});

        // window scroller
        $(window).scroll(function () {
            // sticky panel
            skybox.staticNav();
        });



    });
