$(function(){
    $("nav ul li").hover(
        function(){ $(this).addClass('hover');},
        function(){ $(this).removeClass('hover');}
    )
    
    $("nav.subnav ul li a").click(function(e){
        var rel = $(this).attr('rel');
        if(rel){
            $("nav.subnav ul li").removeClass('current');
            $(this).parent('li').addClass('current');
            $('#content_panel').anythingSlider(rel);
            e.preventDefault();
        }
    });
    /*
    $(".overview li a").click(function(e){
        var myIndex = $(this).parent().prevAll().length + 1;
        alert(myIndex);
        e.preventDefault();
    })
    */
    
    
    $(".blank").click(function(e){
        var link = $(this).attr('href');
        window.open(link);
        e.preventDefault();
    })


    $('.print').popupWindow({
        height:700,width:980,centerScreen:1, scrollbars:1,toolbar:1
    }); 


    // detech hash change and trigger slider to load correct slide
    $(window).hashchange(function() { updateSlider(location.hash) });
    
    var urlHash = location.hash;
    // on load jump to correct slide
    var urlElements = urlHash.split("+");
    personDiv = "";
    
    if(urlElements[1]){
       personDiv = urlElements[1];
       urlHash = urlElements[0];
    }

    updateSlider(urlHash)		
    
    
    
    
}) // on ready

/*******
*
* - UpdateSlider - Find out the index that the page you are trying to load and jump tot he slide 
*
*******/
function updateSlider(hash){
    if(location.hash != "undefined" && typeof(link_array) != "undefined" ){
        //var hash = location.hash;
        var mySplitResult = hash.split("_");
        hash = mySplitResult[0].replace("#", "");
        var aIndex = link_array.findIndex(hash) + 1;
        if(typeof(aIndex) == 'number'){ // if has index value
            $('#content_panel').anythingSlider(aIndex);
        }
        if(mySplitResult[1]){
            $("#"+mySplitResult[1]).trigger('click');
        }
    }
}

// find the index of an array item
Array.prototype.findIndex = function(value){
    var ctr = "";
    for (var i=0; i < this.length; i++) {
        // use === to check for Matches. ie., identical (===), ;
        if (this[i] == value) {
            return i;
        }
    }
    return ctr;
};
