var client_show;
var client_index = {};

$(function() {
    var id = 'csi';
    $('div#all_clients > div').each(function(i,j) {
        client_index[$(j).attr('id')] = 'div.' + $(j).attr('class');
    }); 
    if(document.location.href.match('#.+')) {
        var id = document.location.href.match('#.*').toString().replace('#', '');
    }
    var region = client_index[id] || 'div.client1';
    client_show = parseInt(region.replace('div.client', ''));
    $('div#mid_contents').html('<div class="client">' + $(region).html() + '</div>');
    $('a#fclients_left').click(function() { shift_left(); return false; });
    $('a#fclients_right').click(function() { shift_right(); return false; });
})

var animate_and_shift = function(client_show) {
    var new_client = 'div.client' + client_show;
    $('div#inner_fclients div#right_contents').html('<div class="client">' + $(new_client).html() + '</div>');
    $('div#inner_fclients div#left_contents').animate({
        width: '0px'
    }, 250, 'swing', function() {
        $('div#inner_fclients').html('<div id="left_contents" class="shifter"></div>' + 
            '<div id="mid_contents" class="shifter">' + $('div#right_contents').html() + '</div>' +
            '<div id="right_contents" class="shifter"></div>');
        document.location.href = document.location.href.split('#')[0] + '#' + $(new_client).attr('id');
    });
};

var shift_right = function() {
    client_show++;
    if($('div.client' + client_show).length < 1) { client_show = 1; }
    animate_and_shift(client_show);
    if($('input#in_production').length > 0) {
        pageTracker._trackEvent('Client Page Featured Clients', 'Client Right Shift', $('div.client' + client_show).attr('id'));
    } 
};
var shift_left = function() {
    client_show--;
    if(client_show < 1) { client_show = $('div#all_clients').children('div').length; }
    $('div.clients div.shifter').css('float', 'right');
    animate_and_shift(client_show);
    if($('input#in_production').length > 0) {
        pageTracker._trackEvent('Client Page Featured', 'Client Left Shift', $('div.client' + client_show).attr('id'));
    } 
};

