/**
 * KScope Application Definition
 *
 * @package  Kscope
 * @version  0.1
 */
 
/**
 * Define globals
 */
var TARGET          = {};
 
/**
 * DOM loaded (duh)
 */
$(document).ready(function () {
    bindNavigation();
});

/**
 * Handles animation and control of the persistent header navigation.
 *
 * @param  
 *
 * @return  void
 */
function bindNavigation()
{
    // Set selected state
    var location 	= document.location.href.split('/')[3];
    var target;
    if (location === 'article' || location === 'keyword' || location === 'work') {
        target 		= $('#nav_work');
    } else if (location === 'stuffwelike' || location === 'stuffwelikearticle' || location === 'stuffwelikebymonth') {
        target 		= $('#nav_news');
    } else if (location !== '') {
        target 		= $('#nav_' + location);
    } else {
        target		= $('#nav_home');
    }
    target.addClass('selected');
    
    // Bind pill menu
    var navigation  = new PillMenu('nav', {
        duration: 300,
        transition: Fx.Transitions.Quad.easeOut
    });
}

// ###############################
// ###############################

/**
 * Application dispatcher.
 *
 * @param  string  Page identifier
 * 
 * @return  void
 */
function dispatch(id)
{	
    switch(id.toLowerCase())
    {	
        case 'work':
            loadWork();
            break;
        case 'our work':
            loadServices();
            break;
    }
}

/**
 * Loader for "home" template.
 *
 * @param  void
 *
 * @return  void
 */
function loadHome()
{
    // Init feature (NivooSlider)
    new NivooSlider($('feature'), {
        animSpeed: 750,
        effect: 'sliceDownLeft',
        interval: 6000,
        orientation: 'vertical',
        slices: 10
    }).addEvents({
    	'onStart': function() {
    		// Reset
    		$('feature_overlay').getChildren().setStyle('display', 'none');
    	
    		// Update current
    		var index 	= this.currentSlide + 1;
    		var target  = document.getElementById('overlay_' + index);
    		target.style.display = 'block';
    	}
    });
    
    // Init Request.Twitter
    var html    = '';
    var twitter;
    
    twitter     = new Request.Twitter('kscopecreative', {
        onComplete: function(tweets, user) {
            tweets.each(function(tweet,i) {
                new Element('div',{
                    html: '<img src="' + tweet.user.profile_image_url.replace("\\",'') + '" align="left" alt="' + tweet.user.name + '" /><h6>' + tweet.user.screen_name + ' says:</h6><p>' + tweet.text + '</p><div class="clear">&nbsp;</div>',
                    'class': 'tweet'
                }).inject('twitter');
            });
        }
    });
    twitter.send();
    
    twitter     = new Request.Twitter('rreillyjr', {
        onComplete: function(tweets, user) {
            tweets.each(function(tweet,i) {
                new Element('div',{
                    html: '<img src="' + tweet.user.profile_image_url.replace("\\",'') + '" align="left" alt="' + tweet.user.name + '" /><h6>' + tweet.user.screen_name + ' says:</h6><p>' + tweet.text + '</p><div class="clear">&nbsp;</div>',
                    'class': 'tweet'
                }).inject('twitter');
            });
        }
    });
    twitter.send();
}

/**
 * Loader for "services" template.
 *
 * @param  void
 *
 * @return  void
 */
function loadServices()
{
    // Init feature (NivooSlider)
    new NivooSlider($('feature'), {
        animSpeed: 750,
        effect: 'sliceDownLeft',
        interval: 6000,
        orientation: 'vertical',
        slices: 10
    });
}
