
(function() {


    /**
     * Update the z-index of the picture specified by the top index.
     * Reduce the z-index of the others
     * @param top
     * @param pictures
     */
    var raise = function() {
        for (var i = 0; i < this.pictures.length; i++) {
            if (i !== this.top) {
                var zIndex = YAHOO.util.Dom.getStyle(this.pictures[i], "z-index");
                if (zIndex > 0) {
                    YAHOO.util.Dom.setStyle(this.pictures[i], "z-index", zIndex-1);
                }
            } else {
                YAHOO.util.Dom.setStyle(this.pictures[i], "z-index", this.pictures.length);
            }
        }
    };
    
    /**
    * Enable listeners on the photos
    */
   var initAppWithYUI = function() {
       var pictures = YAHOO.util.Dom.getElementsByClassName("picture", "div", "bd");
       if (pictures && pictures.length > 0) {
           for (var i = 0; i < pictures.length; i++) {
               YAHOO.util.Event.addListener(pictures[i], "click", raise, { top: i, pictures : pictures }, true);
           }
       }
   };


     /**
     * Fetch the YUI dependencies
     */
    var initYUILoader = function() {
        var loader = new YAHOO.util.YUILoader({
            base: "",
            require: ["utilities"],
            loadOptional: false,
            combine: true,
            filter: "MIN",
            allowRollup: true,
            onSuccess: function() {
                initAppWithYUI();
            }
        });
        loader.insert();
    };

    initYUILoader();
})();

