/*
_|      _|  _|            _|                            _|  _|              _|      _|            
_|_|  _|_|      _|_|_|        _|_|_|  _|_|      _|_|_|  _|        _|_|_|  _|_|_|_|      _|    _|  
_|  _|  _|  _|  _|    _|  _|  _|    _|    _|  _|    _|  _|  _|  _|_|        _|      _|    _|_|    
_|      _|  _|  _|    _|  _|  _|    _|    _|  _|    _|  _|  _|      _|_|    _|      _|  _|    _|  
_|      _|  _|  _|    _|  _|  _|    _|    _|    _|_|_|  _|  _|  _|_|_|        _|_|  _|  _|    _|

  Website: Minimalistix.be
  Version: 1.0
  Programming: Hulpia Frederik - info at powerplant dot be - http://www.powerplant.be
  
  Filename: contentloader.js
  Info: Ajax content loader
*/

// Function loadContent
function loadContent (page)
{
	// Set ajax handler
	contentLoader = new flexAjax();
	contentLoader.init();
			
	// Set onreadystatechange
	contentLoader.onreadystatechange(setContent);
			
	// Send AJAX request
	contentLoader.send("../includes/ajaxLoadContent.php", "id=" + page);
}

// Function ajax response setcontent
function setContent ()
{
	// Get Ajax Handler
	var ajax = contentLoader.AjaxHandler;

	// Check if ready and get response
	if (ajax.readyState == 4 && ajax.status == 200)
	{
		// Get ajax data
		var result 		= ajax.responseXML.documentElement;
		var pge			= result.getElementsByTagName('page')[0].firstChild.data; 		
		var contentData	= result.getElementsByTagName('content')[0].firstChild.data;
		
		// Get objects
		var theContent = flexGlobal.getObject('content');

		// Set the content
		theContent.innerHTML = contentData;
		
		// Check what script we need
		if(pge == 'contact')
		{
			// Stop photo timer
			if(countID) { clearInterval(countID); }
			
			// Create new instance of inputchecks
			flexInputChecks = new flexInputCheck();

			// Initialize ajax input check
			flexInputChecks.initAjaxCheck();
						
			// Reset values
			document.forms[0].reset();

			// Set focus
			flexGlobal.getObject('inpFirstName').focus();
		}
		else if(pge == 'studio')
		{
			// Get objects
			var prevPhoto 	= flexGlobal.getObject('prev_photo');
			var nextPhoto 	= flexGlobal.getObject('next_photo');
			var autoPhoto 	= flexGlobal.getObject('auto_photo');
			var navbit		= flexGlobal.getObject('navbit');
						
			// Set event handlers
			if(prevPhoto)	{ prevPhoto.onclick	= doPrev; }
			if(nextPhoto)   { nextPhoto.onclick = doNext; }
			if(autoPhoto)	{ autoPhoto.onclick = switchAuto; }
			if(navbit)		{ navbit.onclick	= function() { loadContent(0); }}
			
			// Default photo
			setPhoto(0);
		
			// Start timer
			if(automatic)
			{
				// Set interval
				countID = setInterval("doNext();", interval);
			}
		}
		else if(pge == 'bio' || pge == 'links' || pge == 'news' || pge == 'legal')
		{
			// Stop photo timer
			if(countID) { clearInterval(countID); }

			// Check for news page
			if(pge == 'bio' || pge == 'links' || pge == 'legal')
			{
				// Get objects
				var navbit = flexGlobal.getObject('navbit');
			
				// Set event handlers
				if(navbit) { navbit.onclick	= function() { loadContent(0); }}
			}
			
			// Added for playback whistling drive video - 9/4/7 18u00
			if(pge == 'news')
			{
				var flashvars = false;
				var params = {
					quality: 			"high",
					allowScriptAccess:	"sameDomain",
					menu:				"false",
					wmode:				"opaque",
					bgcolor:			"transparent"
				};
				var attributes = {};
				swfobject.embedSWF("swf/whistlingdrive.swf", "whistlingvideo", "360", "304", "7", "swf/expressinstall.swf", flashvars, params, attributes);
			}			
		}			
	}	
}

// Load the default content
loadContent(0);