/**
 * ecomm1-items.front.home.featuredrotator.js
 *
 * @author James Ryan <james@infinityprosports.com>
 * @date 2006-02-01
 * @package ISM3
 *
 */
 
HTMLItemRotator = function(rotatorId) {
	this.rotatorId = rotatorId;
	this.items = new Array();
	this.numItems = 0;
	this.curRotation = -1;
	this.timeout = 0;
	this.rotationStatus = 1;
	this.targetPage = 'index.html';
	
	this.addItem = function(name, description, image, price, id) {
		invItem = new Array();
		invItem["name"] = name;
		invItem["description"] = description;
		invItem["image"] = image;
		invItem["price"] = price;
		invItem["id"] = id;
		this.items.push(invItem);
		this.numItems++;
	}

	this.rotate = function() {
		window.clearTimeout(this.timeout);
		this.curRotation += 1;
		if (this.curRotation == this.numItems) {
			this.curRotation = 0;
		}
		curitem = this.items[this.curRotation];
			
		nameElem = document.getElementById(this.rotatorId + "_name");
		descriptionElem = document.getElementById(this.rotatorId + "_description");
		priceElem = document.getElementById(this.rotatorId + "_price");
		imageElem = document.getElementById(this.rotatorId + "_image");
		titleElem = document.getElementById(this.rotatorId + "ar" + this.curRotation);
				
		// Load the item
		if (nameElem) {
			nameElem.innerHTML = curitem["name"];
		}
		if (imageElem) {
			imageElem.innerHTML = '<img src="' + curitem["image"] + '" />';
		}
		if (priceElem) {
			priceElem.innerHTML = curitem["price"];
		}
		if (descriptionElem) {
			descriptionElem.innerHTML = curitem["description"];
		}
		
		// If we are displaying titles
		if (titleElem) {
			for (var i = 0; i < this.numItems; i++) {
				stitleElem = document.getElementById(this.rotatorId + "ar" + i);
				stitleElem.className = 'homerotatorlink';
			}
			titleElem.className = 'homerotatorlink_on';
		}

		if (this.rotationStatus == 1) {
			this.timeout = window.setTimeout(this.rotatorId + '.rotate()', this.duration * 1000);
		}
		
	}
	
	this.jumpTo = function(node) {
		this.curRotation = node - 1;
		this.rotate();
	}
	
	this.readMore = function() {
		window.location = this.targetPage + this.items[this.curRotation]["id"];
	}
	
	this.navStart = function(elem) {
		if (!this.rotationStatus) {
			this.rotationStatus = 1;
			this.rotate();
		}
	}
	
	this.navStop = function(elem) {
		this.rotationStatus = 0;
		window.clearTimeout(this.timeout);
	}
	
	this.navPrev = function(elem) {
		window.clearTimeout(this.timeout);
		this.curRotation -= 2;
		if (this.curRotation == -2) {
			this.curRotation = this.numItems - 2;
		}
		this.rotate();
	}

	this.navNext = function(elem) {
		window.clearTimeout(this.timeout);
		this.rotate();
	}


}

