if (typeof window["console"] == 'undefined') {
    var console = {};
    console.log = function () {};
}
/*
*************************************************

INSTRUMENT v.2
Master Javascript

*************************************************

/*- STATIC GLOBALS
----------------------------------------------------------------------*/


/*- MAIN APPLICATION
----------------------------------------------------------------------*/

var INSTRUMENT = {
    
    common: {
        
        init: function(){
            Cufon.replace('.knockout_27', { fontFamily: 'Knockout 27 Junior Bantamwt', hover: 'true' });
            Cufon.replace('.knockout_29', { fontFamily: 'Knockout 29 Junior Ltweight' });
            Cufon.now();
        }
        
    },
    
    /*- Global Slideshow Methods
    ----------------------------------------------------------------------*/
    
    slideshow: {
        init: function(){
            
        }
    },
    
    /*- Home Page Methods
    ------------------------------------------------------------------*/
    
    home: {
        
        init: function(){
            INSTRUMENT.home.ss = new Slideshow("#slideshow_1");
        },
        
        list: function(){}
        
    },
    
    /*- Work Page Methods
    ------------------------------------------------------------------*/
    
    work: {
        
        init: function(){},
        
        list: function(){},
        
        detail: function(){
            projectSlideshow.init($('#project_slideshow'));
        }
        
    },
    
    /*- About Page Methods
    ------------------------------------------------------------------*/
    
    about: {
        
        init: function() {
            // added > into slector to ignore child ul and li items
            var members = $('#team > ul > li').not('#profilebox'),
                containerWidth = $('#team ul').width(),
                halfContainerWidth = containerWidth / 2;
            
            // simplified the logic by itterating through members and 
            // testing offset against half of the container width
            for (var i = 0; i < members.length; i++) {
                var xPosition = members[i].offsetLeft;
                if (xPosition >= halfContainerWidth) {
                    $(members[i]).addClass('balloon-left');
                }
            }
        },
        
        list: function(){}
        
    },
    
    /*- Blog Page Methods
    ------------------------------------------------------------------*/
    
    blog: {
        
        init: function(){
          Cufon.replace('article.quote blockquote, h1', { fontFamily: 'Knockout 27 Junior Bantamwt', hover: 'true' });
          $('#pattern_bar').addClass('pattern_'+Math.floor(Math.random()*4));
          
          $('.video-contain').fitVids();
        },
        
        list: function(){},
        
        detail: function(){}
        
    },
    
    /*- Contact Page Methods
    ------------------------------------------------------------------*/
    
    contact: {
        
        init: function(){
            INSTRUMENT.contact.ss = new Slideshow("#slideshow_1", true);
        },
        
        list: function(){}
        
    },
    
    /*- Jobs Page Methods
    ------------------------------------------------------------------*/
    
    jobs: {
        
        init: function(){

        },
        
        list: function(){},
        
        detail: function(){}
        
    },
    
    /*- Merger Page Methods
    ------------------------------------------------------------------*/
    
    merger: {
        
        init: function(){
            
            var current_page = '#page_1';
            
            $('a.arrow').click(function (e) {
                e.preventDefault();
                $('html, body').animate({ scrollTop: $($(this).attr('href')).position().top }, 1500, 'easeInOutExpo');
                return false;
            });
            
            $('#merger').bind('mousewheel', function(event, delta) {
                $('#merger').stop();
            });
            
        },
        
        list: function(){
            
        }
        
    }
    
};

/*- UTIL
----------------------------------------------------------------------*/

var UTIL = {
    
    exec: function( controller, action ) {
        var ns = INSTRUMENT;
        
        action = ( action === undefined ) ? "init" : action;
        
        if ( controller !== "" && ns[controller] && typeof ns[controller][action] == "function" ) {
            ns[controller][action]();
        }
    },
    
    init: function() {
        var body = document.body,
            controller = body.getAttribute( "data-controller" ),
            action = body.getAttribute( "data-action" );
        
        UTIL.exec( "common" );
        UTIL.exec( controller );
        UTIL.exec( controller, action );
    }
    
};

// kick it all off here 
$( document ).ready( UTIL.init );

