
/********************************************
 *
 * Copyright (c) 2003-2010 XML-INTL Ltd.
 *
 * All Rights Reserved
 *
 ********************************************/

function fillModulesSelect()
{
	$('.module').each(function(index)
	{
		if (this.id)
		{
			$('#xtmsuiteSelect').append("<option value='" + this.id + "' >" + this.id + "</option>");
		}
	});
	
}

function loadModule()
{
	var moduleId = $('#xtmsuiteSelect option:selected').attr('value');
	
	updateSelect("xtmsuiteSelect", "modules-select");

	insertContent(moduleId);
	
	updateLayout(moduleId);
}

function insertContent(moduleId)
{
	if(moduleId == 'empty')
	{
		if($('#module-image-container')[0])
		{
			$('#module-image-container').remove();
			$('#module-title-container').remove();
			$('#module-abstract-container').remove();
		}
	}
	else
	{
		$('.module').each(function(index)
		{
			if (this.id == moduleId)
			{
				if(!$('#module-image-container')[0])
				{
					$('#selectModulePanel').append(
							'<div id="module-image-container"></div>'+
							'<div id="module-title-container"></div>'+
							'<div id="module-abstract-container">'+
								'<span id="module-abstract-content"></span>'+
								'<br/><span id="read-more-container" class="read-more"></span>'+
							'</div>'
							
					);
				}
				
				$('#module-title-container').text(moduleId);
				
				var moduleAbstractText = $(this).children('#abstract').text();
				$('#module-abstract-content').text(moduleAbstractText);
				
				var moduleLinkPath = $(this).children('#link').text();
				var moduleReadMoreText = $('#module-read-more-text').text();
				$('#read-more-container').text('');
				$('#read-more-container').append('<a href="' + moduleLinkPath + '">' + moduleReadMoreText + '</a>');
				
				var moduleImagePath = $(this).children('#image').text();
				$('#module-image-container').text('');
				$('#module-image-container').append('<img class="module-image" src="' + moduleImagePath + '"/>');
			}
		});
	}
}

function updateLayout(moduleId)
{
	var $background_colors = {
						"default": "#ccf2fc",//"#99e5fa",
						tmmanager: "#e7e6f2",//"#cfcde5",
						engine: "#fbd1d3", //"#f8a4a7",
						workbench: "#fbcce8",//"#f899d1",
						qamanager: "#ffe79f",//ok
						terminology: "#ddeec5",//"#d2e8b2",
						openapis: "#e4f4f4",//"#caeae9",
						workflow: "#ede9dd",//"#e7e1d1",
						empty: "#ffe79f",
						portal: "#e0e0e0"
						};
	
	var $moduleLink;
	
	if(moduleId == 'empty')
	{
		$moduleLink = moduleId;
	}
	else
	{
		$('.module').each(function(index)
		{
			if (this.id == moduleId)
			{
				$moduleLink = $(this).children('#link').text();
			}
		});
	}
	
	$.each($background_colors, function(key, value)
	{
		if($moduleLink.indexOf(key) >= 0)
		{
			$('#selectModulePanel').css("background-color", value);
		}
	});
}

