var styleManager = (function () {

    /*
    * Constructor
    */
    $(document).ready(function () {
        styleManager.styleButton($("#twitter_button"),
					   "images/buttons/twitter.png",
					   "images/buttons/twitter_hover.png");
        styleManager.styleButton($("#book_button"),
					   "images/buttons/ourbook.png",
					   "images/buttons/ourbook_hover.png");
        styleManager.styleButton($("#think_button"),
					   "images/buttons/thinktank.png",
					   "images/buttons/thinktank_hover.png");
        styleManager.styleButton($("#more_button"),
					   "images/buttons/more.png",
					   "images/buttons/more_hover.png");
        styleManager.styleButton($("#contact_button"),
					   "images/buttons/contact.png",
					   "images/buttons/contact_hover.png");
        styleManager.styleButton($("#jobs_button"),
					   "images/buttons/jobs.png",
					   "images/buttons/jobs_hover.png");
        styleManager.styleButton($("#seework_button"),
					   "images/buttons/seework_off.png",
					   "images/buttons/seework_on.png");
    });


    return {
        /*
        * Add handlers for image swapping to give a button basic up/over/down/disabled states
        * overState, downState and disabledState are optional
        */
        styleButton: function (button, upState, overState, downState, disabledState) {
            if (button) {
                
                // UP STATE
                if (upState) {
                    button.attr({ src: upState });
                }

                // OVER STATE
                if (upState && overState) {
                    button.hover(
						function () {
						    if (button.attr("src") !== disabledState) {
						        $(this).attr({ src: overState });
						    }
						},
						function () {
						    if (button.attr("src") !== disabledState) {
						        $(this).attr({ src: upState });
						    }
						}
					);
                }

                // DOWN STATE
                if (overState && downState) {
                    button.mousedown(
						function () {
						    if (button.attr("src") !== disabledState) {
						        $(this).attr({ src: downState });
						    }
						}
					);
                    button.mouseup(
						function () {
						    if (button.attr("src") !== disabledState) {
						        $(this).attr({ src: overState });
						    }
						}
					);

                }

                // DISABLED STATE
                if (upState && disabledState) {
                    button.bind("disable", function () {
                        if (button.attr("src") !== disabledState) {
                            button.attr({ src: disabledState });
                        }
                    });

                    button.bind("enable", function () {
                        if (button.attr("src") === disabledState) {
                            button.attr({ src: upState });
                        }
                    });
                }
            }
        }
    };
} ());
