// MTVNI_EMA: Core codes
function MTVNI_EMA() {	
  var scriptfolder = document.getElementById("MTVNI-EMA-JS").src.replace(/^(.*)\/mtvni\/mtvni.ema_09_01_2009.js(.*)/, '$1');
  MTVNI_COMMON_MODULE_INIT({href: "mtvni.ema", type: "parent", scriptfolder: scriptfolder, object: this, languagecode: null});
  
  this.appsObj = new Array();
};

// Country Dropdown - URL Redirect - functions
MTVNI_EMA.prototype.siteInit = function(list, server) {
  this._siteList = list;
  this._siteServer = server;
};

//Country Dropdown - current site
MTVNI_EMA.prototype.siteSelect = function(el, value) {
  var length = el.length;
  var url = "";
  for (x=0; x<length; x++) {
	url = this.siteBuildUrl(this._siteList[x].url);
	if (value == el[x].value) {
	  el[x].selected = true;
	  break;	// exit loop, found match
	};
  };
};

//Country Dropdown - select onChange
MTVNI_EMA.prototype.dropDownGoto = function(el) {
  var length = this._siteList.length;
  var url = "";
  for (x=0; x<length; x++) {
	if (el[el.selectedIndex].value == this._siteList[x].id) {
	  url = this.siteBuildUrl(this._siteList[x].url);
	  window.location.href = url;
	};
  };
};

MTVNI_EMA.prototype.siteBuildUrl = function(url) {
  return "http://"+url+this._siteServer;
};

// EMA-Applications init
MTVNI_EMA.prototype.initApp = function(type, params) {
  switch(type) {
    case "cogix": 
      this.appsObj[type] = this.add(new MTVNI_COGIX(), this, params);
      mtvni.ema.cogix = this.appsObj[type];
      break;
    case "votes": 
      this.appsObj[type] = this.add(new MTVNI_EMA_VOTES(), this, params);
      mtvni.ema.votes = this.appsObj[type];
      break;
  };
};

MTVNI_EMA.prototype.getApp = function(type) {
  return this.appsObj[type];
};

// Initialize MTVNI_EMA Object
if (mtvni) mtvni.ema = new MTVNI_EMA();