if (!this.GF) {
    GF = {};
}

GF.app = function()
{
    return {
        init: function()
        {
            //Bind the main header click event to redirect home
            $('h1#main-header').bind('click', function(e){
                window.location = $('a', this).attr('href');
                return false;
            });            
            $('.js').show();           
            $('.js').show();
            $('.js-hide').hide();
            GF.app.submitDirections();
            GF.app.ajaxSetup();
            GF.app.ourWork();
            GF.app.partners();
        },
        
        submitDirections: function()
        {
            $("#get-studio-directions").bind('click', function(){
                var directions_href = $(this).attr('href');
                var directions_from = escape($('#saddr').val());
                var href = directions_href.replace("+++", directions_from);
                window.open(href);
                return false;
            });
        },
        
        ajaxSetup: function()
        {
            jQuery("#loading").ajaxStart(function(){
                jQuery(this).show();
            }).ajaxStop(function(){
                jQuery(this).hide();
            });
        },
        
        ourWork : function()
        {
            //Find the parent of the active subnav item (for example, brand identity)
            //and add a distinguishing class for a styling hook
            $('#primary-nav ul:nth-child(2) li a.active')
                .parents('li.parent')
                .addClass('active-parent');
                            
            $('#flashfile ul li').live('click', function(){
                $("#flashfile").load($('a', this).attr('href') + " #flashfile");   
                
                //This is specific to the case studies section
                //Modifies the active link color based on the current slide
                var slide = $(this).attr('class');
                $('body.case-studies #primary-nav li.active-parent li a').removeClass('active');
                $('body.case-studies #primary-nav li.active-parent li.' + slide + ' a').addClass('active');
                             
                return false;    
            }); 
        },
        
        partners : function()
        {
            $('div.partner-info').html($('dl dd:first div:first').html());
            $('div.partner-list dd span').bind('click', function(e){  
                var html = $(this).parents('dd').children('div').html();
                $('div.partner-info').removeClass('hide').html(html);   
            });
        }

    };
    
}();

$(document).ready(function() {
    GF.app.init();
});