$(function() {

// web font loader
/*(function() {
    var wf = document.createElement('script');
    wf.src = ('https:' == document.location.protocol ? 'https' : 'http') + '://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
    wf.async = 'true';
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(wf, s);
})();

var fonts_loaded = false;

WebFontConfig = {
    custom: { families: ['League Gothic', 'League Gothic Small', 'ChampionHTFBan', 'Clarendon Light'], urls: [ '/css/style.css' ] },
    
    fontactive: function(fontFamily, fontDescription) {
        fonts_loaded = true;
        web_font_timeout();
    }
};

$(function() {
    setInterval(function(){
        if (fonts_loaded == false) {
            web_font_timeout();
        }
    }, 500);
});

function web_font_timeout() {
    $('h2, h3, h4, h5, a, dl, label, span.text, div.selector, div.checker, iframe, span.copy, span.feat, ul.thumbs, span.league-gothic-sm, span.text').stop().animate({ opacity: 1 }, 250);
    $('li, p, span.meta, span.disc').css({ opacity: '1' });
}*/




// uniform form elements
//$("input, select").uniform();




// external links
$('a[rel=external]').live('click', function(){
    window.open($(this).attr('href'));
    return false;
});






// header/nav
    $('#loc_submit').hover(function() {
        $(this).addClass('active');
    }, function () {
        $(this).removeClass('active');
    });
    
    
    // locations drop-down & active
        $('li#loc').hover(function() {
            $(this).addClass('hover');
            $('#loc_drop').show();
        }, function () {
            $(this).removeClass('hover');
            $('#loc_drop').hide();
        });
        
        $('ul#loc_drop').hover(function() {
            $(this).show();
            $('#loc a').addClass('active');
        }, function () {
            $(this).hide();
            $('#loc a').removeClass('active');
        });
    
    
    // locations drop-down
        var locTimer = 0; // for search box event handling timeout
        
        // handler for search box
        $('#loc_input_nav').keyup(function(e) {
            var self = this;
            var evt = e;
            
            clearTimeout(locTimer);
            locTimer = setTimeout(function() { searchHandler(self, evt); }, 500);
        });
        
        // calls ajax
        var searchHandler = function(el, evt)
        {   
            $input = $(el);
            if (evt.keyCode != 13 && ($input.val().match(/^.{3,}$/) !== null)) {
                $('#loc_drop').html('<li><img class="spinner" src="/img/dropdown-spinner.gif" alt="searching..." /></li>');
                $('li#loc').mouseover();        
                $.get('/locations', { location : $input.val() }, onSearchComplete);
            }
        };
        
        var onSearchComplete = function(data)
        {
            $('#loc_drop').html(data);
        };




// footer
    // flavorhood & online rollovers
        if($('body').attr('id') != 'home') {
            $('a.flavorhood').hover(function() {
                $('span.online').css('background-position','-303px -52px');
                $('span.online_r').css('background-position','-303px -156px');
                $('a.online span.text, a.online_r span.text').css('color','#ff0000');
            }, function () {
                $('span.online').css('background-position','-303px 0');
                $('span.online_r').css('background-position','-303px -104px');
                $('a.online span.text, a.online_r span.text').css('color','inherit');
            });
            
            $('[class^=online]').hover(function() {
                $('#footer span.flavorhood').css('background-position','-250px -52px');
                $('a.flavorhood span.text').css('color','#ff0000');
            }, function () {
                $('#footer span.flavorhood').css('background-position','-250px 0');
                $('a.flavorhood span.text').css('color','inherit');
            });
        }




// location inputs
    // clear input on focus
    $('#loc_input_nav, #loc_input_panel').focus(function() {
        if(this.value == 'ENTER A ZIP CODE OR CITY & STATE') {
            this.value = '';
        } else {
            this.select();
        }
    });

    // refill input if left blank
    $('#loc_input_nav, #loc_input_panel').blur(function() {
        if(this.value == '') {
            this.value = 'ENTER A ZIP CODE OR CITY & STATE';
        }
    });

    $('#loc_input_nav, #loc_input_panel').mouseup(function() { return false; });




// food
    // menu button
        $('#menu #content_cont').hover(function() {
            $(this).addClass('cont_hover');
            $(this).css({'z-index' : '25'});
            $(this).stop().animate({ marginTop: '-4px', marginBottom: '-4px', paddingTop: '4px', paddingBottom: '4px', position: 'absolute'}, 100);
            $('#menu_btn').addClass('btn_hover');
        }, function () {
            $(this).removeClass('cont_hover');
            $(this).css({'z-index' : '0'});
            $(this).animate({ marginTop: '0px', marginBottom: '0px', paddingTop: '0px', paddingBottom: '0px', position: 'relative'}, 0);
            $('#menu_btn').removeClass('btn_hover');
        });




// locations & online
    // promo thumbnails
        $('#promos .thumbs li').hover(function() {
            $(this).toggleClass('hover');
        }, function() {
            $(this).toggleClass('hover');
        });

    // promos
        $('#promos .thumbs li').click(function() {
            $('#promos .thumbs li').removeClass('active');
            $(this).addClass('active');
        });






// corporate
    // logo animation
        setInterval(function() {
            if ($('#corp_r').css('display') === 'none') {
                $('#corp_r, #return_r').fadeIn('slow');
                $('#return_c').hide();
            } else {
                $('#corp_r, #return_r').fadeOut('slow');
                $('#return_c').show();
            }
        }, 7500);

    
    // collapsing content
        $('#collapse > li:first').addClass('open');
        $('#collapse > li:first').find('.details').show('fast');
        
        $('#collapse > li').hover(function() {
             if ($(this).hasClass('open') == false) {
              $(this).addClass('hover');
           }
             }, function () {
                 if ($(this).hasClass('open') == false) {
                  $(this).removeClass('hover');
              }
         });     
        
        $('#collapse > li').bind('click', function() {
            $('#collapse > li .details').hide();
            $('#collapse > li').removeAttr('class');
            $(this).addClass('open');
            $(this).find('.details').show();	
        });
        /*fade_speed = 350;
        $('#collapse > li').each(function(index, value) { 
            fade_speed += 350;
            $(value).fadeIn(fade_speed);
            if (index+1 == $('#collapse > li').length) {
                $(value).fadeIn(350, function() {
                        
                    $('#collapse > li:first').addClass('open');
                    $('#collapse > li:first').find('.details').show('fast');
                    $('#collapse > li').hover(function() {
                        if ($(this).hasClass('open') == false) {
                            //$(this).css({'z-index' : '25'});
                            //$(this).stop().animate({ marginTop: '-8px', paddingTop: '26px', paddingBottom: '19px', position: 'absolute'}, 250);
                            $(this).addClass('hover');
                        }
                    }, function () {
                        if ($(this).hasClass('open') == false) {
                            //$(this).css({'z-index' : '0'});
                            //$(this).animate({ marginTop: '0px', paddingTop: '16px', paddingBottom: '9px', position: 'relative'}, 150);
                            $(this).removeClass('hover');
                        }
                    });
                                    
                });          
            }    	
        });*/




    // image caption hover
        $('.captioned_img').hover(function() {
            $('.caption', $(this)).stop().animate({ padding: '4px 0px' }, 150);
            $('.arrow_circ', $(this)).css({ backgroundPosition: '0px -12px' });
        }, function () {
            $('.caption', $(this)).stop().animate({ padding: '0px 0px' }, 100);
            $('.arrow_circ', $(this)).css('backgroundPosition','0px 0px');
        });

});








// paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function() {
    // store logs to an array for reference
    log.history = log.history || [];
    log.history.push(arguments);
    
    if(this.console){
        console.log( Array.prototype.slice.call(arguments) );
    }
};
