/**
 *
 * a reversed, customized form of James Ryan's
 * news.front.homerotator.js
 *
 * @author Jason McLaughlin <jasonm@infinityprosports.com>
 * @date 2008-05-13
 * @package ISM3
 *
 */
 
HTMLNewsRotator = function(rotatorId, staticImage) {
	this.rotatorId = rotatorId;
	this.articles = new Array();
	this.staticImage = staticImage;
	this.numArticles = 0;
	this.curRotation = 0;
	this.timeout = 0;
	this.rotationStatus = 1;
	this.targetPage = 'index.html';
	
	this.imgPlay = '';
	this.imgPlayOver = '';
	this.imgPause = '';
	this.imgPauseOver = '';
	
	if (document.getElementById(this.rotatorId + '_playgraphic')) {
		this.imgPlay = document.getElementById(this.rotatorId + '_playgraphic').value;
	}
	if (document.getElementById(this.rotatorId + '_playgraphic_over')) {
		this.imgPlayOver = document.getElementById(this.rotatorId + '_playgraphic_over').value;
	}
	if (document.getElementById(this.rotatorId + '_pausegraphic')) {
		this.imgPause = document.getElementById(this.rotatorId + '_pausegraphic').value;
	}
	if (document.getElementById(this.rotatorId + '_pausegraphic_over')) {
		this.imgPauseOver = document.getElementById(this.rotatorId + '_pausegraphic_over').value;
	}


	/**
	 * Functions
	 */
	
	this.addArticle = function(headline, teaserText, image, id, source) {
		article = new Array();
		article["headline"] = headline;
		article["teaserText"] = teaserText;
		article["image"] = image;
		article["id"] = id;
		article["source"] = source;
		this.articles.push(article);
		this.numArticles++;
	}

	this.rotate = function() {
		window.clearTimeout(this.timeout);
		this.curRotation -= 1;
		if (this.curRotation < 0) {
			if (this.numArticles < 9) {
				this.curRotation = this.numArticles - 1;
			} else {
				this.curRotation = 7;
			}
		}
		article = this.articles[this.curRotation];
		
		titleElem = document.getElementById(this.rotatorId + "ar" + article["id"]);
		
		// Block placement
		//headlineElem = document.getElementById(this.rotatorId + "_headline");
		bodyElem = document.getElementById(this.rotatorId + "_body");
/*		
		// Source element
		sourceElem = document.getElementById(this.rotatorId + "_source");
		if (sourceElem) {
			if (article["source"] != 'http://') {
				sourceElem.innerHTML = '<a target="_blank" href="' + article["source"] + '">Source</a>';
			}
			else {
				sourceElem.innerHTML = '';
			}
		}
*/		
		// No block placement
		teaserElem = document.getElementById(this.rotatorId + "_teaser");
		imageElem = document.getElementById(this.rotatorId + "_image");
				
		// Load the article
		if (this.staticImage) {
			//headlineElem.innerHTML = article["headline"];
			if (imageElem) {
				imageElem.innerHTML = '<img src="' + article["image"] + '" />';
			}
			//teaserElem.innerHTML = article["teaserText"];
		}
		else {
			//headlineElem.innerHTML = article["headline"];
			bodyElem.innerHTML = article["teaserText"];
		}
	
		// If we are displaying titles
		if (titleElem) {
			if (this.prev) {
				stitleElem = document.getElementById(this.rotatorId + "ar" + this.prev);
				stitleElem.className = 'homerotatorlink';
			}
			titleElem.className = 'homerotatorlink_on';
			this.prev = article["id"];
		}

		if (this.rotationStatus == 1) {
			this.timeout = window.setTimeout(this.rotatorId + '.rotate()', this.duration * 1000);
		}
		
	}
	
	this.jumpTo = function(i) {
		a = i - 1;
		this.curRotation = this.numArticles - a;
		this.rotate();
	}
	
	this.readMore = function() {
		window.location = this.targetPage + this.articles[this.curRotation]["id"];
	}
}