﻿/**
* Fix jQuery fadeTo() so it can bring back something after hide() or fadeOut()
*/
(function($) {
    var proxied = $.fn.fadeTo;
    $.fn.fadeTo = function() {
        if ($(this).is(':hidden')) {
            $(this).css('opacity', 0).show();
        }

        return proxied.apply(this, arguments);
    }
})(jQuery);

// All pages

var inVisualsDropDown = false;
var inVisualsButton = false;

function setupVisualsDropDown() {
    $('.bbvisual').mouseenter(function() { inVisualsButton = true; $('.ddvisuals').fadeTo("fast", 1.00); });
    $('.bbvisual').click(function() { $('.ddvisuals').fadeTo("fast", 1.00); });
    $('.ddvisuals').mouseenter(function() { inVisualsDropDown = true; });
}

function leaveVisualsDropDown() {
    if (!inVisualsDropDown && !inVisualsButton) $('.ddvisuals').hide();
}

function setupYearButtons(year, pos, callback) {
    $('.bb' + year).mouseenter(function() { hidecallout(); activate(year, 'bb' + year, (720 + (80 * pos))); });

    $('.bb' + year).mouseleave(function() {
        deactivate(year, 'bb' + year, (720 + (80 * pos)));
        if (callback != null)
        { clearTimeout(callback); }
        resetTimerCallback = setTimeout('showall()', 200);
    });
}

// Front page
function setupYearHandlers(year, pos, callback) {
    if (!($.browser.msie && $.browser.version == "6.0")) {
        $('.bb' + year).click(function() {
            currentYear = year;
            fadein(year);
            $('.yearbutton').trigger('mouseleave');
            $.ajax({
                type: 'GET',
                url: 'AsyncHandler.json?method=GetYearIntro&year=' + year,
                contentType: 'application/json; charset=utf-8',
                data: {},
                dataType: 'json',
                success: function(res) { $('#introtext').html(eval(res).Content); },
                error: function() { }
            });
            return false;
        });
    }
}

function setupInducteeHandlers(row, year, guid, name, url, pos) {
    $('#galleryinactive .nominee_' + row).mouseenter(function() { showcallout(year, guid, name, url, pos, $(this)); });
    $('.gallerynomineedetail').mouseleave(function() { $('.gallerynomineedetail').attr('style', 'position:absolute; display: none;'); });
}

function showall() {
    fadein(currentYear);
    hidecallout();
}

function fadein(_year) {
    $(".gallery_" + _year).fadeTo(200, 1.00);
    $(".year:not(.gallery_" + _year + ")").fadeTo(200, 0.00);
    hidecallout();
}

function activate(year, ele, pos) {
    $("." + ele).attr("style", "background-position: -" + pos + 'px -28px');
}

function deactivate(year, ele, pos) {
    if (year == currentYear)
        $("." + ele).attr("style", "background-position: -" + pos + 'px -56px');
    else
        $("." + ele).attr("style", "background-position: -" + pos + 'px -1px');
}

function showcallout(year, nguid, nname, uname, pos, obj) {
    if (year == currentYear || currentYear == '0') {
        $('.gallerynomineedetail').attr('style', 'position: absolute; left: ' + (obj.position().left - 47) + 'px; top: ' + (obj.position().top - 47) + 'px; display: none; background: url(images/CalloutImage.jpg) no-repeat 0px -' + pos + 'px');
        $('.gallerynomineedetaillink').attr('href', 'inductees/' + year + '/' + uname + '.aspx');
        $('.gallerynomineename').text(nname);
        $('.gallerynomineedetail').show();
    }
}

function hidecallout() {
    $(".gallerynomineedetail").attr("style", "position:absolute; display: none;");
}

// Academy page
function setuphandlers(row, panellistguid) {
    //$('.link_' + row).mouseenter(function() { enterpanellist(panellistguid); });
    //$('.link_' + row).mouseleave(function() { leavepanellist(panellistguid); });
    $('.link_' + row).click(function() { currentPanellist = panellistguid; $('.panellist').removeClass('panellistselected'); $('.panel_' + row).addClass('panellistselected'); requestpanellist(currentPanellist); return false; });
}

function requestpanellist(panellistguid) {
    requestPanellistCallback = null;
    if (panellistguid != '') {
        $('#rightside').show();
        $.ajax({
            type: 'GET',
            url: 'AsyncHandler.json?method=GetPanellistInfo&panellist=' + panellistguid,
            contentType: 'application/json; charset=utf-8',
            data: {},
            dataType: 'json',
            success: function(res) { showpanellist(eval(res)); },
            error: function() { }
        });
    }
    else
        $('#rightside').hide();
}

function enterpanellist(panellistguid) {
    if (requestPanellistCallback != null) {
        clearTimeout(requestPanellistCallback);
        requestPanellistCallback = null
    }

    requestPanellistCallback = setTimeout("requestpanellist('" + panellistguid + "')", 200);
}

function leavepanellist(panellistguid) {
    requestPanellistCallback = setTimeout("requestpanellist('" + currentPanellist + "')", 200);
}

function showpanellist(panellist) {
    $('.biography').html(panellist.BiographyCleaned);
    $('.panellistname').text(panellist.NomineeName + ' ' + panellist.Surname);
    $('.title').html(panellist.Title);
    if (panellist.Inductee == true)
        $('.inductee').html('<br/>IP Hall of Fame inductee in ' + panellist.Year);
    else
        $('.inductee').html('');
    $('#rightside').show();
}

function navmouseover(img) {
    //if (img.parentNode.href.toLowerCase().equals('<%= Request.Path.ToLower() %>') == -1)
    img.src = img.src.replace('inactive', 'active');
}

function navmouseout(img) {
    //if (img.parentNode.href.toLowerCase().equals('<%= Request.Path.ToLower() %>') == -1)
    img.src = img.src.replace('active', 'inactive');
}