if(typeof(Class) != "undefined"){
var BannerRotator = Class.create(); 
BannerRotator.prototype = {
	
	items: [],
	current: -1,
	container: false,
	intervalProcess: false,
	interval: 1000,
	id: false,
	state: '',
	
	

	initialize: function(elementID) {
		this.items = new Array();
		this.id = elementID;
		if(document.getElementById('contentBanner_'+elementID))
			this.container = document.getElementById('contentBanner_'+elementID);

		// clear the container
		this.containerfirstChild = this.container.firstChild;
	},

	start: function() {

	},
	
	stop: function() {

	},	
	
	fadeIn: function() {
		this.state = 'appear';
		Effect.Appear(this.containerfirstChild,  { duration: this.interval * 0.2} ); 	
	
	},
	

	fadeOut: function() {
		this.state = 'fade';
		Effect.Fade(this.containerfirstChild, {delay: this.interval * 0.8,  duration: this.interval * 0.2}); 
		
	},
	
	toggle: function() {
		//console.log(this.state);
		if(this.state == 'appear'){
			this.fadeOut();
			return false;
		}
		
		if(this.state == 'fade'){
			this.showNext();	
			return false;
		}
		
		return false;
	},
		
	removeContent: function ()	{
		// remove all children
		containerfirstChild = this.containerfirstChild;
			$A(containerfirstChild.childNodes).each(function(node) { containerfirstChild.removeChild(node) });	
	},
		
	showNext: function() {
		
		this.removeContent();
		var currentItem = this.next();
		this.state = 'next';
		
		if(currentItem && this.container)
		{			
			if(currentItem["image"].length > 0)
			{
				// create element div [class="bannerImage"]
				var bannerImage = document.createElement("DIV"); 
				bannerImage.className = "bannerImage";
				bannerImage.setAttribute('id', 'bimage');
				
				// create element img
				var image = document.createElement("IMG"); 
				image.src = currentItem["image"];
				bannerImage.appendChild(image);
				
				if(currentItem['url'] != '')
				{
					var url = currentItem['url'];
					bannerImage.onclick = function() { window.location = url; };
					bannerImage.style.cursor = 'pointer';
				}
				
				this.containerfirstChild.appendChild(bannerImage);
			}

			// create element div [class="bannerContent"]
			var bannerContent = document.createElement("DIV");			
			bannerContent.className = "bannerContent";
			bannerContent.setAttribute('id', 'bcontent');
			
			if(currentItem['url'] != '')
			{
				var url = currentItem['url'];
				bannerContent.onclick = function() { window.location = url; };
				bannerContent.style.cursor = 'pointer';
			}
			bannerContent.innerHTML = decodeURIComponent(currentItem["body"]);
			
			this.containerfirstChild.appendChild(bannerContent);
			this.fadeIn();
		}
	},		
		
	next: function() {
		if(this.items.length <= 0)
			return false;
				
		this.current = this.current+1
						
		if(this.current >= this.items.length)
			this.current = 0;

		return this.items[this.current];
	},
	
	add: function(body, image, url) {
		var item = new Array();
		item["image"] = image;
		item["body"] = body;
		item["url"] = url;
		
		this.items[this.items.length] = item;
		
	}
}	
}
