jQuery.fn.specialAwards = function() {    
    var wrapper = jQuery("#recognition-body-inner");
    var groupWidth = 590;
    
    var ajaxStatus = null;
    
    var hash = window.location.hash.substr(1);
        var testHash = "credendo2009";
        var placeOf2 = hash.indexOf(2);
    
    if(hash.length > 2){
        var curGroup = hash.slice(0,placeOf2);
        var curYear = hash.slice(placeOf2,hash.length);
    } else {
        var curGroup = "credendo";
        var curYear = "2009"
    };
    
    jQuery("."+curGroup).addClass("active");
    jQuery("."+curGroup+" a[title='"+curYear+"']").addClass("active");
    
    var curType = 1;
    
    var listPath = "special-awards-list.aspx";
    var loading = false;
    
    function addListClass(){
        jQuery("#recognition-body").removeAttr("class");
        jQuery("#recognition-body").addClass(curGroup);
    };

    jQuery("#recognition")
        .ajaxSend(function(){ajaxStatus = "Send"; showLoading()})
        .ajaxSuccess(function(){ajaxStatus = "Success"});
    
    function loadList(){
        showContent(false);
        jQuery("#load-list")
            .load(getListURL());
        
        showContent(true);
        
        window.location.hash = "#";
        window.location.hash = "#"+(curGroup+curYear);
    };
    loadList();
    addListClass();
    highlightActiveAnchor();
    
    jQuery(".recAnchor a").click(function(){
        if(ajaxStatus == "Success"){
            if(!jQuery(this).hasClass("inactive")){
                curGroup = jQuery(this).parent().attr("title");
                curYear = jQuery(this).attr("title");
                listPath = jQuery(this).attr("href");
                loadList();
                addListClass();
                highlightActiveAnchor();
                highlightActiveSubAnchor(jQuery(this));
            };
        };
        return false;
    });
    
    function highlightActiveAnchor(){
        jQuery("#recognition-head .recAnchor a").each(function(){
            jQuery(this).parent().removeClass("active");
            if(jQuery(this).parent().attr("title") == curGroup){
                jQuery(this).parent().addClass("active");
            };
        });
    };
    function highlightActiveSubAnchor(obj){
       jQuery("#recognition-head .recAnchor a").each(function(){
            jQuery(this).removeClass("active");
        });
        obj.addClass("active");
    };
    
    jQuery(".overlay-close").click(function(){
        if(ajaxStatus == "Success"){
            hideOverlay();
        };
        return false;
    });
    
    function showOverlay(url) {
        jQuery("#recognition-overlay")
            .fadeIn("slow")
            .find("#load-content")
            .html("<img class=\"loading-bars\" src=\"../../App_Themes/images/loading/bars.gif\" width=\"36\" height=\"38\" alt=\"loading\" />")
            .load(url);
    };
    
    function hideOverlay() {
        jQuery("#recognition-overlay").fadeOut("slow");
    };
    /*=================================================================================
        Bind and Rebind all Elements
    =================================================================================*/ 
    
    function bindGetName(){
        jQuery("a.getName").click(function(){
            if(ajaxStatus == "Success"){
                var url = jQuery(this).attr("href");
                showOverlay(url);
            };
            return false;
        });
        if(jQuery("#qTotal").html() != 0){
            $(".special-awards #load-list ul")
                .ninjaGallery({
		            verticalOffset: -50,
		            smallSize: 130,
		            largeSize: 165,
		            startOn: "first",
		            extraContentId: ".additional-content", 
		            offActiveCss: {top: "45px", display: "none"}, 
		            onActiveCss: {top: "-45px", display: "block"}, 
		            offActiveAnimation: {opacity: 0}, 
		            onActiveAnimation: {opacity: 1} 
	            });
	    } else {
	        $(".special-awards #load-list ul").html("<li class=\"no-results\">No Results</li>");
	    };
    };
    
    function reBind(){
        bindIt = function(){
            if(ajaxStatus == "Success"){
                bindGetName();
                clearInterval(ID);
            };
        };
        ID = setInterval(bindIt, 100);
    };
    
    /*=================================================================================
        Transitions Content & Shows Loading Graphic
    =================================================================================*/
  
    function showContent(boo){
        
        if(boo){
            loading = false;
            hideLoading();
            jQuery("#load-list")
                .css({display: "block", opacity: 0})
                .stop()
                .animate({opacity: 1}, 50, reBind);
        } else {
            loading = true;
            if(ajaxStatus == "Success"){
                jQuery("#load-list")
                    .stop()
                    .animate({opacity: 0}, 500)
                    .css({top: 0});
            };
        };
    };
    
    function hideLoading(){
        jQuery("#recognition-body .loading-bars")
            .stop()
            .animate({opacity: 0})
            .css({display: "none"});
    };
    
    function showLoading(){
        jQuery("#recognition-body .loading-bars")
            .css({display: "block", opacity: 0})
            .stop()
            .animate({opacity: 1});
    };
    
    /*=================================================================================
        Generate URL Used To Pull List Info
    =================================================================================*/
    
    function getListURL(obj){
        var rankId = getRankInfo(curGroup);
            //curType = rankInfo[0];
        
        var url = listPath + "?awardTypeId=" + rankId + "&year=" +  curYear;
        
        //##################################################################################
        //$.trace(url);
        //##################################################################################
        
        return url;
    };
    
    /*=================================================================================
        Grab Info On Current Rank
    =================================================================================*/

    function getRankInfo(type){
        var rankId;
        switch (type) {
            case "credendo":
                rankId = 1;
                break;
            case "silver":
                rankId = 2;
                break;
            case "presidents":
                rankId = 3;
                break;
            case "heart":
                rankId = 4;
                break;
            case "super":
                rankId = 5;
                break;
            default:
                rankId = 0;
                break;
        };
        
        return rankId;
    };
    
};
