var links = ['introLink','writingLink', 'infoarchLink', 'interactionLink', 'publishingstyleLink', 'otherLink', 'clientsLink'];
var sections = ['writing', 'infoarch', 'interaction', 'publishingstyle', 'other', 'clients'];



function toggleLinks(link){
    if ($('#' + link).hasClass('selected'))
    {
        $('#' + link).removeClass('selected')
    }
    else
    {
        for(var i=0;i<links.length;i++){
            if (link == links[i])
                $('#' + links[i]).addClass('selected');
            else
                $('#' + links[i]).removeClass('selected');
        }
    }
}

function toggleSections(id){
    var found = false;
    if ($('#'+id).css('display') == 'block')
        $('#'+id).css('display', 'none');
    else
    {
        for(var i=0;i<sections.length;i++){
            if (sections[i] != id){
                var section = $('#'+sections[i]);
                if (section.css('display') == 'block'){
                    section.css('display', 'none');
                    $('#'+id).css('display', 'block');
                    found = true;
                    break;
                }
            }
        }
        if (! found){
            //$('#'+id).css({marginLeft:'2px'});
            $('#'+id).css('display', 'block');
        }
    }
}

$(document).ready(function(){
    // fix for ie where having a smaller page width
    // affects the size of the page
    if (document.body.clientWidth < 1024)
    {
        document.body.style.width = 1024;
    }
    /**
    Slide down the top panel, and move down the panel beneath it.
    */
    $('#introLink').click(function(e){
        toggleLinks('introLink');
        if ($('#topContent').css('display') == 'block')
            $('#topContent').css('display', 'none');
        else
            $('#topContent').css('display', 'block');
        //$('#topContent').slideDown(1000);
    });
    
    /**
    Slide open the relevant panel
    */
    $('#writingLink,#infoarchLink,#interactionLink,#publishingstyleLink,#otherLink,#clientsLink').click(function(){
        toggleLinks(this.id);
        var id = this.id;
        var sectionId = id.substring(0, id.length - 4);
        toggleSections(sectionId);
        return false;
    });
    
    /**
    Reload the page
    */
    $('#logo').click(function(e){
        window.location.reload();
        return false;
    });
    
    $(window).resize(function(){
        if (document.body.clientWidth < 1024){
            document.body.style.width = 1024;
        }
    });

    
});