/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 */

/**
 * Images.js
 *
 * File Path: /scripts/
 *
 * $Id: Images.js 174 2007-08-26 20:38:27Z topdog $
 *
 * LICENSE: copyright 2005 - 2007 Edward Vermillion - Doggydoo Codeworks.
 * Unless otherwise stated ALL RIGHTS ARE RESERVED. Use or reuse without prior
 * written permission from the author or Doggydoo Codeworks is prohibited.
 * Visit http://www.doggydoo.net/license/DDJS-V1.X.txt for the full license.
 * Installation and use of this software implies agreement to the full
 * license.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL DOGGYDOO
 * CODEWORKS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * @package     DDJS
 * @author      Edward Vermillion <evermillion@doggydoo.net>
 * @copyright   2005 - 2007 Edward Vermillion, Doggydoo Codeworks
 * @license     http://www.doggydoo.net/license/DDJS-1.x.txt
 * @version     1.0
 */

DDJS.Images = {

    /**
     * @property imageCache
     *
     * An array for loading off-screen images
     * @type {Array}
     */
    imageCache: new Array(),

    /**
     * @property icc
     *
     * The image cache counter, used to keep track of the last index used in the
     * image cache array
     * @type {Number}
     * @private
     */
    _icc: -1,

    /**
     * @method cacheImage
     *
     * This method adds an image to the off-screen browser image cache array
     *
     * @param {String} imgSrc
     * @return void
     */
    addToCache: function (imgSrc) {
    	this._icc++;
        this.imageCache[this._icc] = new Image();
        this.imageCache[this._icc].src = imgSrc;
        return this.imageCache[this._icc];
    },

    /**
     * @method swapImage
     *
     * This method swaps the image src value for a given image object. If the
     * browser is IE and needs the png fix from iemunge.js then the swapPNG
     * method of that object is called, otherwise the src for the image object
     * is reset to the newSrc value.
     *
     * @param {HTMLImageElement} imgObj
     * @param {String} newSrc
     * @return void
     */
    swapImage: function (imgObj, newSrc) {
        imgObj.src = newSrc;
    },
    
    rollImage: function (imgObj, state) {
		
		var oldSrc = imgObj.src;
		var newSrc;
		
		if (imgObj.filters && imgObj.filters.length > 0) {
			oldSrc = imgObj.filters(0).src;
		}
		
		if (state == 'off') {
			newSrc = oldSrc.replace('_on', '_off');
		} else if (state == 'on') {
			newSrc = oldSrc.replace('_off', '_on');
		}
		
        this.swapImage(imgObj, newSrc);
    },

    /**
     * @method toString
     * @return {String}
     */
    toString: function () {
        return '[Object] DDJS.Images';
    }

}; // End DDJS.Images

