/**
 *  Image slider.
 *
 */
var imageSlider = {
    /**
     * Count of frames inside slider.
     **/
    FRAME_CNT : 2,

    /**
     * Pointer for page data set. Should be assigned before slider working.
     */
    dataSet : new Array(),

    /**
     * Name prefix for images.
     **/
    framePrefix : "",
	
	/**
	 * Frame Position.
	 */
	framePos : 1,
	
	/**
	 * Image index.
	 */
	imageIndex : 0,

    /**
     * Init feats calc with specified page data set and frame name prefix. 
     */
    init : function(dataSet, framePrefix, frameCnt) {
        this.dataSet = dataSet;
        this.framePrefix = framePrefix;
        this.FRAME_CNT = frameCnt;

        this.preload();
    },

    /**
     * Preload images from dataSet. 
     */
    preload : function() {
    	var size = this.getImageCnt();
    	
    	for (var i=0; i<size; i++) {
    		new Image().src = this.dataSet.imageMap[i];
    	}
    },

    /**
     * Init feats calc with specified page data set. 
     */
    getImageCnt : function() {
        return dataSet.imageMap.length;
    },
    
    /**
     * Gets frame position. 
     */
    getFramePos : function() {
		if (this.framePos > this.FRAME_CNT) {
			this.framePos = 1;
		}

		return this.framePos;
    },

    /**
     * Gets image index. 
     */
    getImageIndex : function() {
		if (this.imageIndex == this.getImageCnt()) {
			this.imageIndex = 0;
		}
		
		return this.imageIndex;
    },
    
    /**
     * Next frame. 
     */
    nextFrame : function() {
    	this.framePos++;
    	this.imageIndex++;
    }, 
    
    /**
     * Gets current image id. 
     */
    getFrameId : function() {
    	return this.framePrefix + this.getFramePos();
    }, 
    
    /**
     * Gets current image src. 
     */
    getImageSrc : function() {
    	return this.dataSet.imageMap[this.getImageIndex()];
    } 

    
};

// Map the imageSlider namespace to the 'slider' one.
var slider = imageSlider;

