﻿$(function() {

    HighlightLinks();
    InitiatejFlow();
    
    // default selected work
    ShowSelectedWorkInformation('01');

    // generate loading for work
    $.cacheImage('/content/img/loading.gif');    
    PreLoadWorkImg();

    // preload work images for jFlow by hiding default then showing when all are loaded
    LoadWorkImg();

    AssignWork();
});

function AssignWork() {

    $('.jFlowControl').click(function() {
    
        ShowSelectedWorkInformation($(this).attr('rel'));
    });
}

function HighlightLinks() {

    var fullpath = location.pathname;
    var path = fullpath.split('/');

    // remove empties
    path = $.grep(path, function(val) { return val != ""; });

    if (path.length > 0) {
        // add to primary nav
        $('a[href$="' + path[0] + '"]').addClass("selected");

        // add to secondary nav
        $('a[href$="' + fullpath + '"]').addClass("selected");
    }
}

function InitiatejFlow() {

    $('#controller').jFlow({
        slides: "#slides",
        width: "850px",
        height: "243px",
        easing: "linear"
    });
}

function ShowSelectedWorkInformation(num) {

    // hide all
    $('.workInformation').hide();

    // show associated info
    $('.i' + num + '').show();
}

function PreLoadWorkImg() {
    $('<div class="loading"/>').css({
        width: '850px',
        height: '243px',
        top: '0px',
        left: '0px',
        position: 'absolute',
        background: 'white url("/content/img/loading.gif") no-repeat center'
    }).appendTo('#slides');
}

function LoadWorkImg() {
    $(window).load(
    function() {
        $('.loading').remove();
        $('#slides .hide').show();
    }
    );
}

