/**
 * Class ShowcaseImage
 */
function ShowcaseImage(name, image, href){
    // initialize the member variables for this instance
    this.name = name;
    this.image = image;
    this.href = href;
    this.target = "_self";
    
    // initialize the member function references 
    // for the class prototype
    if (typeof(_SHOWCASETAB_CALLED_) == 'undefined') {
        _SHOWCASETAB_CALLED_ = true;
        ShowcaseImage.prototype.getName = getName;
        ShowcaseImage.prototype.setName = setName;
        ShowcaseImage.prototype.getImage = getImage;
        ShowcaseImage.prototype.setImage = setImage;
        ShowcaseImage.prototype.getHref = getHref;
        ShowcaseImage.prototype.setHref = setHref;
        ShowcaseImage.prototype.getTarget = getTarget;
        ShowcaseImage.prototype.setTarget = setTarget;
    }
    
    function getImage(){
        return (this.image);
    }
    function setImage(value){
        this.image = value;
    }
    function getHref(){
        return (this.href);
    }
    function setHref(value){
        this.href = value;
    }
    
    function getTarget(){
        return (this.target);
    }
    function setTarget(value){
        this.target = value;
    }
    function getName(){
        return this.name;
    }
    function setName(value){
        this.name = value;
    }
}

/**
 * Class Showcase
 */
function Showcase(){
    this.items = new Array();
    this.rootPath = "Images/";
    this.currentIndex = 0;
    this.showcaseName = "showcaseImage";
    this.showDelay = 2000;
    
    
    // Object construction
    if (typeof(_SHOWCASE_CALLED_) == 'undefined') {
        _SHOWCASE_CALLED_ = true;
        Showcase.prototype.setRootPath = setRootPath;
        Showcase.prototype.getRootPath = getRootPath;
        Showcase.prototype.addShowcaseImage = addShowcaseImage;
        Showcase.prototype.getShowcaseImage = getShowcaseImage;
        Showcase.prototype.showShowcaseImage = showShowcaseImage;
        Showcase.prototype.getCurrentIndex = getCurrentIndex;
        Showcase.prototype.run = run;
        Showcase.prototype.load = load;
        Showcase.prototype.setShowDelay = setShowDelay;
        Showcase.prototype.getShowDelay = getShowDelay;
        Showcase.prototype.showNext = showNext;
    }
    
    function setShowDelay(value){
        this.showDelay = value;
    }
    function getShowDelay(){
        return (this.showDelay);
    }
    function getCurrentIndex(){
        return (this.currentIndex);
    }
    function setRootPath(path){
        this.rootPath = path;
    }
    function getRootPath(){
        return (this.rootPath);
    }
    function addShowcaseImage(tab){

      //  if (this.items.length > 2)             tab.setLast(true);
        this.items.push(tab);

    }
    
    /**
     * Resituisce la tab alla posizione specificata
     * @param {Number} position
     * @return {ShowcaseTab}
     */
    function getShowcaseImage(position){
        return (this.items[position]);
    }
    
    /**
     * Show the tab having index {index}
     * @param {Number} index. The zero-based index of the tab
     */
    function showShowcaseImage(index){
        var scImage = this.getShowcaseImage(index);
        var filename = this.getRootPath() + "/" + scImage.getImage();
        var href = scImage.getHref();
        
        // id in XHTML
        var showcaseImage = document.getElementById("showcaseImage");
        var showcaseLink = document.getElementById("showcaseLink");
        
        showcaseImage.src = filename;
        showcaseLink.href = href;
    }
    
    /**
     * Loads image
     */
    function load(){
        var currentImage = null;
        var currentFile = null;
        
        for (index = 0; index < this.items.length; index++) {
            currentImage = new Image();
            currentImage.src = this.getRootPath() + "/" + currentFile;
            currentImage.src = currentFile;
        }
    }
    
    /**
     * Run showcase
     */
    function run(){
    
        this.load();
        this.showNext();
        setInterval('showcase.showNext();', this.getShowDelay());
    }
    
    /**
     * Show next image
     */
    function showNext(){
        var currentIndex = this.getCurrentIndex();
        if (currentIndex < this.items.length - 1) 
            this.currentIndex = currentIndex + 1;
        else 
            this.currentIndex = 0;
        this.showShowcaseImage(this.getCurrentIndex());
    }
    
}
