/// Site Center Implements Ajax
///	Written By: Matthew Gaddis <matthew_gaddis@yahoo.com>
/// Created: 2005-01-07
/// Modified: 2007-02-13

SiteCenter.prototype = new cscAjax();
SiteCenter.prototype.constructor = cscAjax;
SiteCenter.superclass = cscAjax.prototype;


function SiteCenter(strUrl, XmlDOMDoc, objHTTPRequest, intItemNumber)
{
	///
	///	SiteCenter Init
	///
	
	if(arguments.length > 0) 
		this.init(strUrl, XmlDOMDoc, objHTTPRequest, intItemNumber);
}

///
///	SiteCenter Properties
///

SiteCenter.prototype.intItemNumber = null;
SiteCenter.prototype.center = new Object();
SiteCenter.prototype.position = new Array();
SiteCenter.prototype.positionIndex = 0;
SiteCenter.prototype.itemNumberThread = new Object();
SiteCenter.prototype.elemImage = null;
SiteCenter.prototype.elemNews = null;
SiteCenter.prototype.elemHeadline = null;
SiteCenter.prototype.elemCredit = null;
SiteCenter.prototype.elemNext = null;
SiteCenter.prototype.elemPrevious = null;

/// 
/// SiteCenter Methods
///

SiteCenter.prototype.init = function(strUrl, XmlDOMDoc, intItemNumber)
{
	SiteCenter.superclass.init.call(this, strUrl, XmlDOMDoc);

	this.center = new Object();
	this.position = new Array();
	this.positionIndex = 0;
	this.itemNumberThread = new Object();
	
	this.intItemNumber = intItemNumber;
	this.elemImg = document.getElementById('sitecenter_img');
	this.elemNews = document.getElementById('sitecenter_dialog');
	this.elemHeadline = document.getElementById('sitecenter_headline');
	this.elemCredit = document.getElementById('sitecenter_credit');

	this.elemNext = document.getElementById('sitecenter_next');
	this.elemPrevious = document.getElementById('sitecenter_previous');
	
	if(this.intItemNumber == 1)
		this.elemNext.className = 'disabled';
	
	this.load(this.intItemNumber - 1);
	this.load(this.intItemNumber);
	this.load(this.intItemNumber + 1);
};

SiteCenter.prototype.processHTTPRequestChange = function(intIndex)
{
	//This may need to be attached to a object instance...
	
	var i = 0;
	var node = null;
	
	if(typeof siteCenter == 'object')
	{
		SiteCenter.superclass.processHTTPRequestChange.call(this, intIndex);
		
		if(XmlHttp.req[intIndex].readyState == 4)
		{	
			if
				(
					this.doc.documentElement.childNodes.length > 0  //if the response document has data
					&& 
					siteCenter.itemNumberThread[intIndex] != null	//if this is a valid thread
				)
			{
				//push a new item into the position stack
				siteCenter.position[siteCenter.position.length] = siteCenter.itemNumberThread[intIndex];
				
				
				
				siteCenter.center[siteCenter.itemNumberThread[intIndex]] = new Object();
				siteCenter.center[siteCenter.itemNumberThread[intIndex]]['pic'] = document.createElement('img');
				
				for(i; i < this.doc.documentElement.childNodes.length; i++)
				{
					node = this.doc.documentElement.childNodes.item(i);
					
					if(node.nodeName == 'pic')
					{
						
						
						siteCenter.center[siteCenter.itemNumberThread[intIndex]][node.nodeName].setAttribute('src', node.firstChild.data);
					}
					else
					{
						siteCenter.center[siteCenter.itemNumberThread[intIndex]][node.nodeName] = node.firstChild.data;
					}
				}

				//remove the thread pointer from the pool
				siteCenter.itemNumberThread[intIndex] = null;
			}	
		}
	}
};

SiteCenter.prototype.load = function(intItemNumber)
{
	if(typeof this.center[intItemNumber] != 'object')
	{		
		this.url = this.url.replace(/\d+$/, '') + intItemNumber;
		
		var intThread = SiteCenter.superclass.load.call(this);
		
		this.itemNumberThread[intThread] = intItemNumber;
	}
};

SiteCenter.prototype.previous = function()
{
	if(typeof this.position[this.positionIndex + 1] != 'undefined')
	{
		this.elemImg.setAttribute('src', this.center[this.position[++this.positionIndex]]['pic'].getAttribute('src'));
		this.elemNews.innerHTML = 			this.center[this.position[this.positionIndex]]['dialog'];
		this.elemHeadline.innerHTML= 		this.center[this.position[this.positionIndex]]['headline'];
		this.elemCredit.innerHTML= 	this.center[this.position[this.positionIndex]]['credit'];
		
		this.intItemNumber = this.position[this.positionIndex] + 1;
		
		if(this.intItemNumber > 1)
			this.elemNext.className = '';
		
		//preload the next set of data
		this.load(this.intItemNumber);
	}
	
	return false;
}


SiteCenter.prototype.next = function()
{	
	if(typeof this.position[this.positionIndex - 1] != 'undefined')
	{		
		this.elemImg.setAttribute('src', this.center[this.position[--this.positionIndex]]['pic'].getAttribute('src'));
		this.elemNews.innerHTML = 			this.center[this.position[this.positionIndex]]['dialog'];
		this.elemHeadline.innerHTML = 		this.center[this.position[this.positionIndex]]['headline'];
		this.elemCredit.innerHTML = 	this.center[this.position[this.positionIndex]]['credit'];
		
		this.intItemNumber = this.position[this.positionIndex] - 1;
		
		if(this.intItemNumber == 0)
			this.elemNext.className = 'disabled';
		
		//preload the next set of data
		this.load(this.intItemNumber);
	}
	
	return false;
}

SiteCenter.prototype.toString = function() { return 'SiteCenter'; }