// resume.js Copyright (c) 2008 Julian M Bucknall
/*global JMBCV window document */

var JMBCV = {
    countJobs: 13,
    countPubs: 4,
    jobAllExplanded: true,
    pubAllExplanded: true,

    hideItem: function(id) {
        var imgId = 'img_' + id;
        document.getElementById(id).className = 'hideItem';
        var image = document.getElementById(imgId);
        if (image) {
            image.src = 'more.png';
            image.alt = "Show this description";
        }
    },

    showItem: function(id) {
        var imgId = 'img_' + id;
        document.getElementById(id).className = 'showItem';
        var image = document.getElementById(imgId);
        if (image) {
            image.src = 'less.png';
            image.alt = "Hide this description";
        }
    },

    expandCollapse: function(id) {
        if (document.getElementById(id).className == 'hideItem') {
            this.showItem(id);
        }
        else {
            this.hideItem(id);
        }
    },

    expandCollapseAll: function(section, expand, count) {
        var id;
        var jobId;
        var imgId = 'img_' + section + 'All';
        if (expand) {
            for (id = 1; id <= count; id++) {
                jobId = section + id;
                this.showItem(jobId);
            }
            document.getElementById(imgId).src = 'lessAll.png';
        }
        else {
            for (id = 1; id <= count; id++) {
                jobId = section + id;
                this.hideItem(jobId);
            }
            document.getElementById(imgId).src = 'moreAll.png';
        }
    },

    expandCollapseAllJobs: function() {
        this.jobAllExplanded = !this.jobAllExplanded;
        this.expandCollapseAll('job', this.jobAllExplanded, this.countJobs);
    },

    expandCollapseAllPubs: function() {
        this.pubAllExplanded = !this.pubAllExplanded;
        this.expandCollapseAll('pub', this.pubAllExplanded, this.countPubs);
    },

    initialize: function() {
        this.expandCollapseAllJobs();
        this.expandCollapseAllPubs();
    },

    print: function() {
        window.print();
    },

    addLoadEvent: function(func) {
        var that = this;
        var oldEventHandler = window.onload;
        window.onload = function() {
            if (oldEventHandler) {
                oldEventHandler();
            }
            func.call(that);
        };
    }
};

JMBCV.addLoadEvent(JMBCV.initialize);

