
/**
 * Top level namespace for all Gaia Resources functions
 */
Gaia = {
    /**
     * The init_solution_model is invoked once at page load and will attach
     * hover events to each mapped area of the solution model. The event
     * triggers a class insertion into the parent that changes the
     * display of the solution model via css.
     */
    init_solution_model: function() {
        jQuery("#solutions_model a").hover(
            function() {
                // When hovering over the element, set the appropriate class
                // for the parent.
                anchor_element = jQuery(this);
                anchor_element.parent().addClass(anchor_element.attr("id")+"_priority");
            },
            function() {
                // When exiting the element remove the class set when entering
                // the hover.
                anchor_element = jQuery(this);
                anchor_parent = anchor_element.parent();
                default_class = jQuery("#solutions_model_default").attr("class");
                anchor_parent.removeClass(anchor_element.attr("id")+"_priority");
                anchor_parent.addClass(default_class);

            }
        );
    },

    /**
     * Calls the constructor for the lightbox plugin that will add appropriate
     * handlers to the related images.
     */
    init_lightbox: function() {
        jQuery.Lightbox.construct({
                baseurl: "{{ MEDIA_URL }}lightbox",
                show_helper_text: true,
                ie6_upgrade: false,
                speed: 150,
                rel: "lightbox-image",
                auto_relify: true
			});
    },

    /**
     * Adds a height attribute to the scroll wrapper around the images based
     * on the height of the detail content. This has to be done dynamically
     * because the height of the content changes. When javascript is not
     * enabled, the content simply will not scroll and the page will get long,
     * but not break.
     */
    init_detailed_images_scrollbar: function() {
        j_detail_container = jQuery("#detail_content_container #detail_content_wrapper");
        j_images_container = jQuery("#detail_images_container #detail_img_scroll_container");
        j_images_container.height(j_detail_container.height());
    },

    /**
     * Invoked once at page load, this function is the top level 'constructor'.
     */
    init: function() {
        Gaia.init_solution_model();
        Gaia.init_lightbox();
        Gaia.init_detailed_images_scrollbar();

        jQuery("#client_login_selection").change(function(){
            var value = jQuery("#client_login_selection").val();
            // This is to eliminate the default "Select Client" option.
            if(value.indexOf("http://") > -1)
            {
                document.location=jQuery("#client_login_selection").val();
            }
        });
    }
};

// When the document has loaded, initialise.
jQuery(Gaia.init);

