﻿/// <reference path="jquery-1.3.2.min.js" />
/// <reference path="jquery.url.packed.js" />

(function($) {
    $(document).ready(function() {

        var items = $("#projList input");
        //get the path of the current url, we'll use this to compare to the paths of the other urls
        var currUrl = $.url.attr("path");
        var prevBtn = $(".projectNav .leftLink");
        var nextBtn = $(".projectNav .rightLink");
//        prevBtn.hide();
//        nextBtn.hide();

        function getItemDetails(jItem) {
            /// <summary>Returns an name/value object with id, sort and url</summary>
            var id = jItem.attr("id");
            var url = jItem.val();
            return { id: id, url: url };
        }

        items.each(function() {
            /// <summary>
            /// Determine which is the next previous project in the list in comparison to this current project and 
            /// configure the next prev buttons to have the correct url.
            /// </summary>
            var item = getItemDetails($(this));
            var index = items.index($(this));
            if (item.url == currUrl) {
                //this is our current item...
                if (index > 0) {
                    prevBtn.show();
                    prevBtn.attr("href", getItemDetails($(this).prev()).url);
                }
                if (index < items.length - 1) {
                    nextBtn.show();
                    nextBtn.attr("href", getItemDetails($(this).next()).url);
                }

            }
        });
    });
})(jQuery);