/**
 * Same as {@link TuneUpDispatcher.trigger}
 * 
 * @addon TuneUpDispatcher
 * @returns void
 */
function tuTrigger( )
{
  console.debug("[Proxy]: tuTrigger(", arguments, ")");
  tuDispatcher.trigger.apply(arguments);
  return tuDispatcher;
}

/**
 * This function will delegate the specified string to the TUService
 * 
 * @deprecated use tuDispatcher.call(args) instead
 * @param string
 * @returns void
 */
function call(string)
{
  console.error("[Proxy]: call(", arguments, ")");
  tuDispatcher.send(string);
}

/**
 * @deprecated
 * @addon Tuningmode
 * @param mode
 * @returns void
 */
function highspeedDone(mode)
{ // used for backwards compatibility
  console.debug("[Proxy]: highspeedDone(", arguments, ")");
  updateTuningmode(mode);
}

/**
 * Scheduled from TUU service when mode switch is done.
 * 
 * @addon Tuningmode
 * @param mode
 *          real mode state from service
 * @returns void
 */
function updateTuningmode(mode)
{ // tuningmodeActive(mode)
  console.debug("[Proxy]: updateTuningmode(", arguments, ")");
  tuDispatcher.trigger('updateTuningmode', mode);
}

/**
 * Scheduled from TUU service during each progress update
 * 
 * @addon Tuningmode
 * @param mode
 * @param progress
 *          optional
 * @returns void
 */
function updateTuningmodeProgress(mode, progress)
{
  console.debug("[Proxy]: updateTuningmodeProgress(", arguments, ")");
  tuDispatcher.trigger('updateTuningmodeProgress', mode, progress);
}

/**
 * @addon Tuningstatus
 * @param cur
 *          number of options who are currently enabled
 * @param max
 *          number of options who could be enabled
 * @returns void
 */
function updateTurboIndex(cur, max)
{
  console.debug("[Proxy]: updateTurboIndex(", arguments, ")");
  tuDispatcher.trigger('updateTurboIndex', cur, max);
}

/**
 * @addon Tuningstatus
 * @param cur
 *          number of options who are currently enabled
 * @param max
 *          number of options who could be enabled
 * @returns void
 */
function updateEcoIndex(cur, max)
{
  console.debug("[Proxy]: updateEcoIndex(", arguments, ")");
  tuDispatcher.trigger('updateEcoIndex', cur, max);
}

/**
 * @addon Tuningstatus
 * @param tuArray
 * @param activeIndex
 * @returns void
 */
function updateTuningStatus(obj)
{
  console.debug("[Proxy]: updateTuningStatus(", arguments, ")");
  tuDispatcher.trigger('updateTuningStatus', obj);
}

/**
 * @addon Program Deactivator
 * @param type
 * @param text
 */
function updateSystemload(type, text)
{
  console.debug("[Proxy]: updateSystemload(", arguments, ")");
  tuDispatcher.trigger('updateSystemload', type, text);
}

/**
 * If we got a text than show the trial button
 * 
 * @param text
 * @returns void
 */
function showShopbox(text)
{
  console.debug("[Proxy]: showShopbox(", arguments, ")");
  tuDispatcher.trigger('enableTrial', text);
}

/**
 * Triggered by TUService after a Delphi-Controlled Drop-Down was closed
 * 
 * @param id
 *          ID of the element who should be hidden
 * @returns void
 */
function releaseLock(id)
{
  console.debug("[Proxy]: releaseLock(", arguments, ")");
  if (id != 'performancemode') {
    jQuery.LayerButton.hideLayer(document.getElementById(id), 'selected');
  } else {
    // dirty hack :O
    jQuery('.tuningmode > .settings > button').removeClass('pressed');
  }
  mouseDownPressed = false;
  tuDispatcher.trigger('releaseLock', id);
}

/**
 * @param tabId
 * @returns void
 */

function selectTab(tabId)
{
  console.debug("[Proxy]: selectTab(", tabId, ")");
  tuDispatcher.trigger("tabSelected", tabId);
}

/**
 * Update the Live-Optimization text
 * 
 * @addon Live-Optimization
 * @param sidebar
 * @param newValue
 * @returns void
 */
function updateSidebar(sidebar, newValue)
{
  console.debug("[Proxy]: updateSidebar(", arguments, ")");
  tuDispatcher.trigger('updateLiveOptimization', sidebar, newValue);
}

/**
 * Update the last used settings in Style on panel 5
 * 
 * @addon Styler
 * @param imgs
 * @param texts
 * @param links
 * @param type
 * @returns void
 */
function updatePillarStyles(imgs, texts, links, type)
{
  console.debug("[Proxy]: updatePillarStyles(", arguments, ")");
  var l = texts.length, i = 0, linkList = new Array(l), img = text = link = regex = match = tObj = null;

  for (; i < l; i++) {
    img = imgs[ i ];
    text = texts[ i ];
    link = links[ i ];
    // link = String.format( "tuDispatcher.trigger('style', '%s')", match[ 1 ] );
    // link = String.format("tuDispatcher.send('%s')", link);
    tObj = {
      image : img,
      text : text,
      link : link
    };
    linkList[ i ] = tObj;
  }

  return tuDispatcher.trigger('updateStyleSettings', type, linkList);
}

/**
 * Updates the pillar data for Panel 1
 * 
 * @param data
 * @returns void
 */
function updatePillar(data)
{
  console.debug("[Proxy]: updatePillar(", arguments, ")");
  tuDispatcher.trigger('updatePillar', data);
}
