var mobounce_id;	 // ID of the slideShow
var mobounce_num;	 // The current picture displayed in the slideShow
var mobounce_array;  // Array of pictures for the slideShow to display 
function mobounce_LoadSite()
{	
	var xmlhttp = ajaxBrowser();
	if (xmlhttp)
	{	
		xmlhttp.open("GET", "scripts/php/intro_loadimages.php");
		xmlhttp.onreadystatechange = function() 
		{
		    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) 
		    {
				var picString = xmlhttp.responseText;

				// If picString.length == 0 then we have no pictures to view...exit function
				if (picString.length == 0)
				{		
					alert('There was an error while loading the Mo\' Bounce web site!');
					return false;
				}
								
				// Split the string that the ajax call returned into array elements
				mobounce_array = picString.split(";");

				// Create a modal dif container where we can place out pictures
				mobounce_id  = 'mobounce_Load';
				mobounce_num = 0;
				
				mobounce_Progressbar(true, 0);
	
				var mobounce_Pics_Loaded = 0;
				var iNum 	= mobounce_array.length - 1;
				var tmp_img = new Image();
				tmp_img.onload = function() 
				{	
					mobounce_Pics_Loaded++;
					var iPercent = (mobounce_Pics_Loaded / iNum) * 100;
					mobounce_UpdateProgress(iPercent);
					tmp_img.src = mobounce_array[mobounce_Pics_Loaded];
					
					if (Math.round(iPercent) == 100)
					{
						var hProgress = document.getElementById('mobounce_Progress');
						mobounce_UpdateProgress(0);
						hProgress.style.display = 'none';
						window.location="http://www.mobounceent.com/mobounce.html";

					}
				}

				tmp_img.src = mobounce_array[0];
				
			}
		}
		
		xmlhttp.send(null);
	}
}

//
// Display the progress bar
//
function mobounce_Progressbar(bVis, iPercent)
{
	var hContainer = document.getElementById('mobounce_Progress');
	var hProgress  = document.getElementById('mobounce_Prog_Bar');
	var hText;
	var hFont;
			

	if (bVis)
	{
		// if 'slideShow_Progress' object does not already exist then create it
		if (!hContainer)
		{										
			// Create progress bar's div container
			hContainer 	= document.createElement('div'); 
			hProgress 	= document.createElement('div'); 
			hText 		= document.createTextNode('Loading...'); 
			hFont 		= document.createElement('font');
			
			// Set the containers 'id' attribute to 'slideShow_Progress'
			hContainer.setAttribute	('id', 'mobounce_Progress'); 
			hProgress.setAttribute	('id', 'mobounce_Prog_Bar'); 
		}
		
		var width 	= 188;
		var height 	= 28;
		var x = (windowSize(true) / 2) - (width / 2);
		var y = (windowSize(false) / 2) - (height / 2) + browser_scrollTop();
	
		// Set the position attributes of the div container
		hContainer.style.width 		= width + "px";
		hContainer.style.height 	= height + "px";
		hContainer.style.left 		= x + "px";
		hContainer.style.top 		= y + "px";
		hContainer.style.zIndex 	= 50;		
		hContainer.style.position 	= "absolute"; 
		hContainer.style.display 	= 'block'; 
		hContainer.style.backgroundImage = "url(" + "/../images/progressbar_bg.gif" + ")";

		// Set the position attributes of the div container
		hProgress.style.width 		= "0px";
		hProgress.style.height 		= (height - 6) + "px";
		hProgress.style.left 		= 3 + "px";
		hProgress.style.top 		= 3 + "px";
		hProgress.style.zIndex 		= 50;		
		hProgress.style.position 	= "absolute"; 
		hProgress.style.display 	= 'block'; 
		hProgress.align 			= 'center';
		hProgress.style.backgroundImage = "url(" + "/../images/progressbar_meter.gif" + ")";

		document.body.appendChild(hContainer);
		hContainer.appendChild(hProgress);

		if (hFont && hText)
		{
			hFont.style.fontSize = 'small';
			hFont.style.color = "white";
			hFont.appendChild(hText);
			hProgress.appendChild(hFont);
		}
	}
	else
	{
		if (hContainer)
			hContainer.style.display = 'none'; // Remove the progress bar
	}
}

//
// Update the progress bar
//
function mobounce_UpdateProgress(iPercent)
{
	var hContainer = document.getElementById('mobounce_Progress');

	if (hContainer)
	{
		var hProgress  = document.getElementById('mobounce_Prog_Bar');
		var hText	   = hProgress.childNodes[0];
		
		// 100% = the main containers width minus 9.
		var iMax   = hContainer.offsetWidth - 6;
		var iWidth = (iPercent / 100) * iMax; 

		hProgress.style.width =  Math.round(iWidth) + "px";		
		hText.innerHTML = Math.round(iPercent) + "%";
	}
}