/**
 * MainCarouselSwitch
 *
 * @author Micha Horn <horn@burdadirect.de><info@michahorn.de>
 * @version $Id$
 */
var mainCarouselObject = {

	imageId: 'bdi_carouselImage', 
	
	/* ImageId <img src="" id="bdi_carouselImage"/> for example */
	
	classNames:null,
	defaultClassName:null,
	maskClassName:null,
	imageClassName:null,
	imagesPaths:new Array('default image path'), 
	altTitles:new Array('default altTitle'), 
	linksPaths:new Array('default link path'), 
	
	/* Array of background images/links paths starts with 1 / 0 =  default image or link path if necessary */ 
	
	linkPath:null,
	activePosition:1,
	counter:0,	
	
	/*
		You have to embed an onLoad event handler into the body tag to get a default class name by id.
		For example: onLoad='mainCarouselObject.getDefaultClassName()'.
		The id in this case 'bdi_mainCarouselObject'is mandatory in one of your default classes.
		Your class name is variable but must contain a hyphen (-) following an increment number.
		Your active class must have the expression 'Active' at the end.
	*/
	
	getDefaultClassName: function() {
		this.defaultClassName = document.getElementById('bdi_mainCarouselObject')
		if(this.defaultClassName) {
			this.defaultClassName = this.defaultClassName.className.split("-");
			this.defaultClassName = this.defaultClassName[0];
			this.classNames = document.getElementsByClassName(this.defaultClassName); 
		}
	},
	
	getImageClassNames: function(img, msk) {
		this.imageClassName = document.getElementsByClassName(img);
		this.maskClassName = document.getElementsByClassName(msk);;
	},
	
	/* Images are limited up to 3 */
	
	getImages: function(imagePath, altTitle) {
		if(this.imagesPaths.length < 4) {
			this.imagesPaths.push(imagePath);
			this.altTitles.push(altTitle);
		}
	},
		
	setImages: function(position) {
		if(document.images[this.imageId].complete) {
			document.images[this.imageId].src = this.imagesPaths[position];
			document.images[this.imageId].alt = this.altTitles[position];
			document.images[this.imageId].title = this.altTitles[position];
		}
	},
	
	/* Links are limitedup up to 3 */
	
	getLinks: function(linkPath) {
		if(this.linksPaths.length < 4) this.linksPaths.push(linkPath);
		if(!this.linkPath) this.linkPath = this.linksPaths[1];		
	},

	setLinks: function(position) {
		this.linkPath = this.linksPaths[position];
		if(!this.linkPath) {
			this.maskClassName[0].style.cursor = 'default'
			this.imageClassName[0].style.cursor = 'default'
		} 
		else {
			this.maskClassName[0].style.cursor = 'pointer'
			this.imageClassName[0].style.cursor = 'pointer'
		}
	},
	
	getLocation: function(position) {
		if(this.linkPath) {
			window.location.href = this.linkPath;
		}
	},
	
	setCarouselButtons: function(position) {
		if(!position) var position = this.activePosition;

		if(this.classNames && this.defaultClassName) {
			for (i = 0; i < this.classNames.length; i++) {
				if((i+1) != position){ 
					this.classNames[i].className = this.defaultClassName+'-'+(i+1);
				}
				else {
					this.classNames[i].className = this.defaultClassName+'-'+position+'Active'
					this.activePosition = position;
					this.setImages(position);
					this.setLinks(position);
				}
			}
		}

	},
	
	switchCarousel: function(position) {
		this.counter = position-1;	
		this.setCarouselButtons(position);
	},

	timeFunction: function (calls) {
		if (this.counter < calls) {
			this.setCarouselButtons(this.activePosition);
			this.activePosition++;
			this.counter++;
		} 
		else {
			this.activePosition = 1;
			this.counter = 0;
		}
	},

	startTimer: function (interval, calls) {
		 setInterval('mainCarouselObject.timeFunction('+calls+')', interval);
	}
}

/* Start time function */

mainCarouselObject.startTimer(3000,3);

/*
	First paramter is the iteration time in milliseconds.
	Second paramter is the iteration quantity.
*/	
	

