
Shadowbox.init({
    handleOversize: "resize"
});

$(function() {
    //BLOG ACCORDION
    $('.boxC ul span').click(function() {
        $(this).next('ul').slideToggle('fast');
        if ($(this).html() == '[+]') { $(this).html('[&#8211;]'); }
        else { $(this).html('[+]'); }
    });
    
    //HOMEPAGE TABS
    $('#lvl5-right ul.tabs li a').click(function() {
        var idx = $('#lvl5-right ul.tabs li a').index(this);
        $('#lvl5-right ul.tabs li').removeClass('active')
        $(this).parents('ul.tabs li').addClass('active');
        $('#lvl5-right div.content').removeClass('active');
        $('#lvl5-right div.content:eq('+idx+')').addClass('active');
        return false;
    });   
    
    //SHARETHIS
    var shareThis = SHARETHIS.addEntry({
        title:'share',
        summary: 'Share 50 Back'},{
        button:false
    });
    shareThis.attachButton(document.getElementById('share-this'));
    
    /*NAVIGATION
    $('#nav li.parent').hover(function() {
        if ($('li', this).length > 0)
            $('ul', this).show();
    }, function() {
        if ($('li', this).length > 0)
            $('ul', this).hide();
    });*/
    
    //FORM VALIDATION
    $('form').validate();
    
    //INFIELD LABELS
    $('label').inFieldLabels({
        fadeOpacity: 0.5,
        fadeDuration: 300
    });
    $('input:not(:file)').attr('autocomplete', 'off');
    
    //HOMEPAGE FLICKR CYCLE
    $('#flickr-content').cycle({
        fx: 'scrollHorz',
        timeout: 8000,
        slideExpr: '.container',
        containerResize: 0
    });
    
    //HOMEPAGE FLASH BOTTLE
    $('#lvl4-mid div').flash({
        src: TEMPLATEPATH +'/ui/flash/50back-bottle.swf',
        width: 200,
        height: 730
    },
    {version: 10},
    function(htmlOptions) {
        htmlOptions.wmode = 'transparent';
        $('#lvl4-mid div').prepend($.fn.flash.transform(htmlOptions));
    });
    
    //REMOVE ATTACHED FILE
    $('.removeFile').live('click', function() {
        var fileName = $(this).attr('rel');
        $.ajax({
            url: '/removeFile.php',
            data: {f: fileName},
            type: 'GET',
            dataType: 'html',
            success: function(html) {
                if (html === '1') {
                    $('a[rel="'+ fileName + '"]').parents('li').remove();
                }
            }
        });
        return false;
    })
});

window.onload = function() {
    if (window.location.href.indexOf('?over21=1') > 0) {
        $.cookie('over21', 'yes', 1);
    } else if ($.cookie('over21') == null) {
        Shadowbox.open({
            content: 'http://www.50back.com/age-verify',
            player: 'iframe',
            height: 700,
            width: 960,
            options: {
                overlayOpacity: 0.8,
                modal: true,
                displayNav: false,
                onClose: function() {
                    $.cookie('over21', 'yes', 1);
                }
            }
        });
    }
}

$(function() {
    $('#beer-search').submit(function() {
        Shadowbox.open({
            content: 'http://www.50back.com/finder/find-our-beer.php?'+ $('#beer-search').serialize(),
            player: 'iframe',
            title: 'Search Results',
            width: 900,
            height: 552,
            options: {
                viewportPadding: 0
            }
        });
        return false;
    });
});
