// JavaScript Document openWindows
/* Chayne Walsh : 2007 08 01 */
var globalAjaxId = '';
var Ajax = 
{
	init: function()
	{
		var ajaxMe = WStarCore.getElementsByClass("ajaxMe");
		for (var i = 0; i < ajaxMe.length; i++)
		{
			WStarCore.addEventListener(ajaxMe[i], "click", Ajax.onclickHandlerAjaxMe);
		}
		
		
		var ajaxGallery = WStarCore.getElementsByClass("ajaxGallery");
		for (var i = 0; i < ajaxGallery.length; i++)
		{
			WStarCore.addEventListener(ajaxGallery[i], "click", Ajax.onclickHandlerAjaxGallery);
		}
	},
	
	onclickHandlerAjaxMe: function()
	{
		globalAjaxId = "ajaxContainer";
		document.getElementById(globalAjaxId).innerHTML = '<img src="../../../assets/scripts/js/assets/images/loading/loading.gif" />';
		setTimeout( "Ajax.timeOutRequest('"+globalAjaxId+"')", 15000);
		var httpRequest = WStarCore.createXHR();
		httpRequest.onreadystatechange = function()
		{  
			if (httpRequest.readyState == 4)
			{
				if (httpRequest.status == 200)
				{
					try
					{
						document.getElementById(globalAjaxId).innerHTML = UTF8.decode(httpRequest.responseText);
						abortTimeOutRequest = false;
						AddRollovers.init();
						OpenWindows.init();
						Ajax.init();
					}
					catch (e){document.getElementById(globalAjaxId).innerHTML = "Failed to load content!"}
				}
				else
				{
					/* */
				}
			}
		}
		httpRequest.open('GET', this.rel, true);
		httpRequest.send(null);
		
		WStarCore.preventDefault(event);
		return;		
	},
	
	onclickHandlerAjaxGallery: function()
	{
		globalAjaxId = "ajaxContainer";
		document.getElementById(globalAjaxId).innerHTML = '<img src="../../../assets/scripts/js/assets/images/loading/loading.gif" />';
		setTimeout( "Ajax.timeOutRequest('"+globalAjaxId+"')", 15000);
		var httpRequest = WStarCore.createXHR();
		httpRequest.onreadystatechange = function()
		{  
			if (httpRequest.readyState == 4)
			{
				if (httpRequest.status == 200)
				{
					try
					{
						document.getElementById(globalAjaxId).innerHTML = httpRequest.responseText;
						abortTimeOutRequest = false;
						AddRollovers.init();
						OpenWindows.init();
						Ajax.init();
					}
					catch (e){document.getElementById(globalAjaxId).innerHTML = "Failed to load content!"}
				}
				else
				{
					/* */
				}
			}
		}
		httpRequest.open('GET', this.rel, true);
		httpRequest.send(null);
		
		
		WStarCore.preventDefault(event);
		return;	
	}
}
var abortTimeOutRequest = true;
Ajax.timeOutRequest = function (id)
{
	if (abortTimeOutRequest) document.getElementById(id).innerHTML = 'The page failed to load. <a href="javascript:history.back();">Please try again</a>.';
}
WStarCore.start(Ajax);