// JavaScript Document


/*--------------------------------------------------------------------------------
	The following JavaScript is all required.
--------------------------------------------------------------------------------*/

	Event.observe(window, 'load', function(){
			
		// Set all links with a class of 'blank' to open in a new browser
		$$('a.blank').each(function(element){
			element.onclick = function()
			{
				window.open(this.href);
				return false;
			}
			element.onkeypress = function()
			{
				window.open(this.href);
				return false;
			}
		});
		

	/*--------------------------------------------------------------------------------
	
		Mouse events: Over, Down
	
	--------------------------------------------------------------------------------*/

		$$('img.mouseover').each(function(element){
			element.onmouseover = function() { element.src = _cms.update_file_src(this.src, '-o', 'add'); }
			element.onmouseout = function() { element.src = _cms.update_file_src(this.src, '-o', 'remove'); }
		});

		$$('img.mousedown').each(function(element){
			element.onmouseout = function() { element.src = _cms.update_file_src(this.src, '-d', 'add'); }
			element.onmouseout = function() { element.src = _cms.update_file_src(this.src, '-d', 'remove'); }
		});

	/*--------------------------------------------------------------------------------
	--------------------------------------------------------------------------------*/

	});
	
	
	

/*--------------------------------------------------------------------------------

	Global handlers

--------------------------------------------------------------------------------*/

	var lock_ajax_loading = false;
	
	var myGlobalHandlers = {
		
		onCreate: function()
		{
			if (!lock_ajax_loading)
			{
				if (!$('overlay'))
				{
					var objBody = document.getElementsByTagName("body").item(0);
					
					var arrayPageSize = getPageSize();
					
					// Overlay
					var objOverlay = document.createElement('div');
					objOverlay.style.height = arrayPageSize[1]+'px';
					objOverlay.style.paddingTop = (arrayPageSize[1]/2-50) + 'px';
					objOverlay.id = 'overlay';
					objOverlay.style.display = 'none';
					objBody.appendChild(objOverlay);
					
					// Animated image
					var objImg = document.createElement('img');
					objImg.src = '/assets/modules/developmentplatform/m_dev_support/images/ajax-loader.gif';
					objOverlay.appendChild(objImg);
				}
				
				new Effect.Appear('overlay', { duration: 0.2, from: 0.0, to: .3 });
				
			}
		},


		onComplete: function()
		{
			if ($('overlay'))
			{
				new Effect.Fade('overlay', { duration: 0.2});
			}
		}
	};

	Ajax.Responders.register(myGlobalHandlers);




/*--------------------------------------------------------------------------------

	CMS class

--------------------------------------------------------------------------------*/

	var CMS = Class.create();
	
	CMS.prototype = {

	/*--------------------------------------------------------------------------------
	--------------------------------------------------------------------------------*/

		initialize: function()
		{
			
		},

	/*--------------------------------------------------------------------------------
	--------------------------------------------------------------------------------*/

		update_file_src: function(src, suffix, action)
		{
			// Split the src into an array so that we can target the file name
			var array = src.split('/');
			var file_name = array[array.length-1];
			
			// Get the file names name and extension
			var name = file_name.split('.')[0];
			var ext = file_name.split('.')[1];
			
			// Either add or remove the suffix to the name and rebuild the file name
			if (action == 'add')
			{
				var new_file_name = name + suffix + '.' + ext
			}
			else if (action == 'remove')
			{
				var str_length = suffix.length;
				var new_name_str_length = name.length - str_length;
				var new_name = name.substr(0, new_name_str_length);
				
				var new_file_name = new_name + '.' + ext
			}
		
			// Replace the old file name with the new one in the array and re join it
			array[array.length-1] = new_file_name;
			var new_src = array.join('/');
			
			return new_src;
		}

	/*--------------------------------------------------------------------------------
	--------------------------------------------------------------------------------*/
	
	}

/*--------------------------------------------------------------------------------
--------------------------------------------------------------------------------*/

	_cms = new CMS;


