var services = {
    _currentHash: location.hash,
    option: {
        idNavWrapper: 'sub',
        classWrapper: 'article',
        classLinkActive: 'selected',
        classServices: 'services'
    },
    init: function () {
        services._changeService();
        // Start checking the page hash for changes
        setInterval(services._check, 100);
    },
    _changeService: function () {
        // Make sure our hash is an id within the wrapper
        var hash = services._currentHash;
        if ($('.' + services.option.classWrapper + ' ' + services._currentHash + '_service').length == 0) {
            hash = '';
        }
        var service = hash.replace(/^#/, '');
        // If the service is empty set it to the main page
        if (hash.length == 0) {
            service = $('#' + services.option.idNavWrapper + ' li:first').attr('class');
            window.location = window.location.href.replace(location.hash, '') + '#' + service;
        }
        // Set active state of link
        $('#' + services.option.idNavWrapper + ' a').removeClass(services.option.classLinkActive);
        $('#' + services.option.idNavWrapper + ' .' + service + ' a').addClass(services.option.classLinkActive);
        // Show the correct tab
        $('.' + services.option.classServices + ' .service').hide();
        $('.' + services.option.classServices + ' .service#' + service + '_service').show();
        $('body').attr('id', service);
        global.cufon();
        return false;
    },
    _check: function () {
        // If the location hash is different then change services
        if (location.hash != services._currentHash) {
            services._currentHash = location.hash;
            services._changeService();
        }
    }
}

$(document).ready(function () {
    services.init();
});
