/**
 * global.js
 *
 * Global JavaScript functions and variables for Your Fight Site CMS front-end.
 *
 * @author Martin Bean <martin@yourfightsite.com>
 */
$(document).ready(function() {
    Cufon.replace('h1', { hover: true, textShadow: '0 1px 1px #000' });
    Cufon.replace('ul#navigation>li span', { textShadow: '0 1px 1px #000' });
    $('a[rel="external"]').addClass('external').attr('title', function() {
        return this.title + ' (opens in new window)';
    }).click(function() {
        window.open(this.href);
        return false;
    });
    // $('a[rel="popup"]').fancybox();
    $('#navigation').suckerfish();
    $('#enews_subscribe_form').submit(function() {
        var email = $('input[name="email"]', this).val();
        var response = $('.response', this);
        if (email == '') {
            // alert('Please enter an email address.');
            response.fadeOut('fast', function() {
                response.html('<p class="error">Please enter an email address.</p>').fadeIn('fast');
            });
        }
        else {
            var action = $(this).attr('action');
            var params = {
                ajax: 1,
                email: email,
                subscribe: 1
            };
            $.post(action, params, function(data) {
                response.fadeOut('fast', function() {
                    response.html('<p class="error">' + data + '</p>').fadeIn('fast');
                });
            }, 'json');
        }
        return false;
    });
    $('#features').tabs({ fx: { opacity: 'toggle' } }).tabs('rotate', 8000);
    $('.carousel .inner').jCarouselLite({
        btnNext: '.carousel .next',
        btnPrev: '.carousel .prev',
        circular: true,
        visible: 4
    });
    $('.cycle').cycle({
        fx: 'fade',
        pager: '.cycle .nav',
        slideExpr: 'div[class="slide"]',
        speed: 5000
    });
    $('.vod_tabs').tabs({ fx: { opacity: 'toggle' } });
});

jQuery.fn.suckerfish = function() {
    return this.each(function() {
        $(this.id + ' li').each(function() {
            $(this).hover(
                function() { $(this).addClass('sfhover'); },
                function() { $(this).removeClass('sfhover'); }
            );
        });
    });
};
