/**
 *  ****************************************************************************
 *  File : design/previmer/javascript/previmer_application.js
 *  vers : 1.1
 *  build: 20070731
 *  Author : Virtualys
 *  ****************************************************************************
 **/

/**
 * ============================================================================= 
 * Application
 * Application Previmer 
 * ============================================================================= 
 */ 
Application = function(domNode,forTheme) {
	this._themeID = $(domNode).attr('theme');
	this._id = $(domNode).attr('id');
	
	this._rootArea = new AreaGeoItem( $('areas > area:first-child', domNode));
	this._variables = { };
	var that = this;
	var initVariable = function(i)
	{
		that._variables[$(this).attr('id')] = new Variable(this, forTheme);
	}
	if (!forTheme)
	{
		$('variables > variable', domNode).each(initVariable);
	}else
	{
		$('variable', domNode).each(initVariable);
	}
}
Application.prototype = {
/**
 * -----------------------------------------------------------------------------
 * Obtient l'emprise principale.
 */ 
	'getRootArea' : function() {
		return this._rootArea;
	},
/**
 * -----------------------------------------------------------------------------
 * Obtient une emprise.
 * @param areaID identifiant de l'emprise recherchée 
 */ 
	'getArea' : function(areaID)
	{
		return this._rootArea.getArea(areaID);
	},
/**
 * -----------------------------------------------------------------------------
 * Obtient la liste des variables disponibles dans l'application.
 */ 
	'getVariables' : function()
	{
		return this._variables;
	},
/**
 * -----------------------------------------------------------------------------
 * Obtient la liste des geoitems disponibles pour variables
 * et le type de résultat demandé
 * @param variable identifiant de la variable
 * @param resultType identifiant du type de résultat
 */
	'getGeoItemList' : function(variable, resultType) {
	   var variableObject = this._variables[variable] ;
	   if (!variableObject) return false;
	   var resultTypeObject = variableObject.resultTypes[resultType] ;
	   if (!resultTypeObject) return false;
	   
	   return resultTypeObject.geoItems ;
	}
}
