/**
 * @author darius.kruythoff
 */
hMovieThumbs = {
    'debug':false,
    'currentIndex':0,
    'movieThumbs':new Array(),
    'movieCommands':new Array(),
    'movieTitles':new Array(),
    'setImages':function(images)
    {
		if (typeof images == 'object') {
            for(var i=0;i<images.length;i++) {
				this.movieThumbs.push(images[i]);
				
				var preloader = new Image();
				preloader.src = images[i];
			}
        } else {
            this.movieThumbs.push(images);
			
			var preloader = new Image();
			preloader.src = images;
		}
    },
    'setTitles':function(titles)
    {
    	if (typeof titles == 'object') {
            for(var i=0;i<titles.length;i++) {
                this.movieTitles.push(titles[i]);
            }
        } else {
            this.movieTitles.push(commands);
        }
    },
	'setCommands':function(commands)
    {
		if (typeof commands == 'object') {
            for(var i=0;i<commands.length;i++) {
				this.movieCommands.push(commands[i]);
			}
        } else {
            this.movieCommands.push(commands);
		}
    },
    'turnNext':function()
    {
        setTimeout('hMovieThumbs.doTurn()',1500);
    },
    'doTurn':function()
    {
    	var thumbPath;
    	var thumbElement;
    	var thumbCommand;
    	var movieTitle
    	
        for(var i=1;i<5;i++) {
            thumbPath = this.getNextThumb();
            thumbElement = document.getElementById('moviesThumb'+i);
            thumbCommand = this.getCurrentCommand();
            thumbTitle = this.getCurrentTitle();
            
            thumbElement.setAttribute('title',thumbTitle);
            thumbElement.setAttribute('href','javascript:'+thumbCommand);
            thumbElement.style.backgroundImage = 'url("'+thumbPath+'")';
            $('#moviesThumb'+i).tooltip({
            	showURL: false,
            	extraClass:"movieTitle",
            	fixPNG:false,
            	track:true
            	});
            
            if (thumbElement.style.visibility != 'visible') {
                thumbElement.style.visibility = 'visible';
            }
       }
       if (this.debug) {
           alert('Advanced index to: '+this.currentIndex);
       }
    },
    'getNextThumb':function()
    {
       if (this.currentIndex >= this.movieThumbs.length) {
           this.currentIndex = 0;
       }
       var currentImage = this.movieThumbs[this.currentIndex];
       this.currentIndex++;
       
       return currentImage;
    },
    'getCurrentCommand':function()
    {
       var index = (this.currentIndex-1);
       if (this.currentIndex < 0) {
           index = (this.movieThumbs.length -1);
       }
       
       return this.movieCommands[index];
    },
    'getCurrentTitle':function()
    {
       var index = (this.currentIndex-1);
       if (this.currentIndex < 0) {
           index = (this.movieThumbs.length -1);
       }
       
       return this.movieTitles[index];
    },
    'alertImages':function()
    {
       var alertTxt = 'Got the following images: \n\n';
       for(var i=0;i<this.movieThumbs.length;i++) {
           alertTxt += this.movieThumbs[i]+'\n';
       }
       alert(alertTxt);
    }
}