/**
 * Function will be called on click of previous button
 * Depending on the current situation it will call different function
 * to enable or disable next or previous button and calls function to change quad image
 * @param totalQuad: total number of quad image
 **/
function tilePrevOnclick(totalQuad)
{
  var initialQuadNum = 1;
  if(quadNumber == totalQuad && totalQuad != initialQuadNum)
  {
    QuadTiles.enableButton('tile_next', 'btn_next_enabled.gif');
  }
  if(quadNumber <= totalQuad && quadNumber > initialQuadNum)
  {
    quadNumber -= 1;
    YAHOO.util.Dom.get("quadNumber").innerHTML = quadNumber;
    changeQuadImage(quadNumber);
  }
  if(quadNumber == initialQuadNum)
  {
    QuadTiles.disableButton('tile_prev', 'btn_previous_disabled.gif');
  }
}

/**
 * Function will be called on click of next button
 * Depending on the current situation it will call different functions
 * to enable or disable next or previous button and calls function to change quad image
 * @param totalQuad: total number of quad image
 **/
function tileNextOnclick(totalQuad)
{
  var initialQuadNum = 1;
  if(quadNumber == initialQuadNum && totalQuad != initialQuadNum)
  {
    QuadTiles.enableButton('tile_prev', 'btn_previous_enabled.gif');
  }
  if(quadNumber < totalQuad)
  {
    quadNumber += 1;
    YAHOO.util.Dom.get("quadNumber").innerHTML = quadNumber;
    changeQuadImage(quadNumber);
  }
  if(totalQuad == quadNumber)
  {
    QuadTiles.disableButton('tile_next', 'btn_next_disabled.gif');
  }
}

/**
 * Function contains enable and disable button functions for quad
 **/
var QuadTiles = new function()
{
  /**
   * Private function to disable next or previous button
   * @param {Object} tileId : Id of the tile
   * @param {Object} buttonName: Name of the button image
   */
  this.disableButton = function(tileId, buttonName)
  {
    YAHOO.util.Dom.get(tileId).src = urlPath+'/themes/foc/images/'+buttonName;
    YAHOO.util.Dom.get(tileId).style.cursor = "default";
  }
  /**
   * Private function to enable next or previous button
   * @param {Object} tileId: Id of the tile
   * @param {Object} buttonName: Button image name
   */
  this.enableButton = function(tileId, buttonName)
  {
    YAHOO.util.Dom.get(tileId).src = urlPath+'/themes/foc/images/'+buttonName;
    YAHOO.util.Dom.get(tileId).style.cursor = "pointer";
  }
}

/**
 * Function to change the quad image according to the quad number
 * @param quadNumber - quad number that is to be shown at present
 **/
function changeQuadImage(quadNumber)
{
  var nodes = YAHOO.util.Dom.getElementsBy(function() {return true;}, "A", "quadImageStyle");
  for(var i=0; i<nodes.length; i++)
  {
    nodes[i].style.display = "none";
  }
  nodes[quadNumber-1].style.display = "inline";
  return;
}
