﻿$(function() {
    $('.toggleLoginBox').click(function(ev) {
        ev.stopPropagation();
        $('#loginBox').toggle();
        var $box = $('#emailLoginLinkBox');
        if ($box.hasClass('active')) {
            $box.removeClass('active');
        } else {
            $box.addClass('active');
            $('#loginBox #Email').focus();
        }
    });

    // hide login box when body is clicked EXCEPT if login-box-div is clicked
    $('#loginBox').click(function(ev) {
        ev.stopPropagation();
    });

    /* Cufon stuff */
    Cufon.replace('.Gotham1', { fontFamily: 'Gotham1' });
    Cufon.replace('.Gotham2', { fontFamily: 'Gotham2' });

    /* Profile bubble */
    $('.bub').live('mouseover', function(event) {
        var href = $(this).attr('href') + 'Bubble';
        $(this).qtip({
            overwrite: false, // Make sure the tooltip won't be overridden once created
            content: {
                text: 'Loading...', // The text to use whilst the AJAX request is loading
                ajax: {
                    url: href,
                    type: 'GET', // POST or GET
                    success: function(data, status) {
                        // Process the data

                        // Set the content manually (required!)
                        this.set('content.text', data);
                    }
                }
            },
            style: {
                classes: 'ui-tooltip-blue ui-tooltip-shadow'
            },
            show: {
                event: event.type, // Use the same show event as the one that triggered the event handler (probably "mouseover")
                ready: true // Show the tooltip as soon as it's bound, vital so it shows up the first time you hover!
            },
            hide: {
                event: 'mouseout',
                delay: 250,
                fixed: true
            }
        }, event); // Pass through our original event to qTip
    })
});

Date.prototype.isNonHolidayWeekday = function() {
    //code.google.com/p/datejs/wiki/APIDocumentation#compareTo
    var isMemorialDay = new Date('5/30/2011').compareTo(this.clearTime()) == 0;
    var isJuly4th = new Date('7/4/2011').compareTo(this.clearTime()) == 0;
    var isLaborDay = new Date('9/5/2011').compareTo(this.clearTime()) == 0;

    if (isMemorialDay || isJuly4th || isLaborDay)
        return false;

    var day = this.getDay();
    return (day < 6 && day > 0);
}

function showMsgForm(golferID) {
    $.fancybox({
        'type': 'iframe',
        'href': '/Golfer/QtipMsg/' + golferID
    });
}
