//-------------------------
//
// integrate.co.uk
//
// (c)integrate.co.uk 2009
//
//-------------------------

// Called when any content page loads:
function init(page_id)
{
  // set the current nav tab to active:
  if (page_id)
  {
    try
    {
      document.getElementById("menu_"+page_id).className="active";
    }
    catch (err)
    {
      // The page id supplied is invalid, do not set any tab.
    }
  }

  // TODO: Hide the loading icon?
  // TODO: Ajax page change?
}

var menu_fade = new Array(0,0,0,0,0,0);
var menu_on = new Array("false","false","false","false","false","false");

// display a sub menu:
function show_submenu(id)
{
  // set fade to 100:
  menu_on[id] = true;
  do_fading(id);
}

// display a sub menu:
function hide_submenu(id)
{
  menu_on[id] = false;
  do_fading(id);
}

function do_fading(id)
{
  try
  {
    if (menu_on[id])
    {
      // Menu should be on - so make it fade up to full:
      document.getElementById("submenu_"+id).style.display = "block";

      // If not at full fade, fade in a step now:
      if (menu_fade[id] < 100)
      {
        menu_fade[id] = menu_fade[id]+10;
        document.getElementById("submenu_"+id).style.filter="alpha(opacity="+menu_fade[id]+")";
        document.getElementById("submenu_"+id).style.MozOpacity=(menu_fade[id]/100);
        document.getElementById("submenu_"+id).style.opacity=(menu_fade[id]/100);
        setTimeout("do_fading("+id+");", 20);
      }
      else
      {
        menu_fade[id] = 100;
        // Fade up is complete.
      }
    }
    else
    {
      // Menu should be off - so fade it out and turn it off:
      document.getElementById("submenu_"+id).style.display = "block";

      // If not at zero fade, fade out a step now:
      if (menu_fade[id] > 0)
      {
        menu_fade[id] = menu_fade[id]-5;
        document.getElementById("submenu_"+id).style.filter="alpha(opacity="+menu_fade[id]+")";
        document.getElementById("submenu_"+id).style.MozOpacity=(menu_fade[id]/100);
        document.getElementById("submenu_"+id).style.opacity=(menu_fade[id]/100);
        setTimeout("do_fading("+id+");", 20);
      }
      else
      {
        menu_fade[id] = 0;
        document.getElementById("submenu_"+id).style.display = "none";
        // Fade out is complete.
      }
    }
  }
  catch (err)
  {
    // Maybe the browser js does not allow for fades etc.
  }
}

var image_fade = new Array(0,100,0,0,0,0,0,0,0,0,0,0);
var image_selected = 1;

function display_image(id)
{
  image_selected = id;

  do_select_image();
}

function do_select_image()
{
  var done = true;

  for (var id=1; id<=10; id++)
  {

  try
  {
    if (id==image_selected)
    {
      // should be on - so make it fade up to full:
      document.getElementById("img_"+id).style.display = "block";

      // If not at full fade, fade in a step now:
      if (image_fade[id] < 100)
      {
        image_fade[id] = image_fade[id]+5;
        document.getElementById("img_"+id).style.filter="alpha(opacity="+image_fade[id]+")";
        document.getElementById("img_"+id).style.MozOpacity=(image_fade[id]/100);
        document.getElementById("img_"+id).style.opacity=(image_fade[id]/100);
        done = false;
      }
      else
      {
        image_fade[id] = 100;
        // Fade up is complete.
      }
    }
    else
    {
      // should be off - so fade it out and turn it off:
      document.getElementById("img_"+id).style.display = "block";

      // If not at zero fade, fade out a step now:
      if (image_fade[id] > 0)
      {
        image_fade[id] = image_fade[id]-5;
        document.getElementById("img_"+id).style.filter="alpha(opacity="+image_fade[id]+")";
        document.getElementById("img_"+id).style.MozOpacity=(image_fade[id]/100);
        document.getElementById("img_"+id).style.opacity=(image_fade[id]/100);
        done = false;
      }
      else
      {
        image_fade[id] = 0;
        document.getElementById("img_"+id).style.display = "none";
        // Fade out is complete.
      }
    }
  }
  catch (err)
  {
    // Maybe the browser js does not allow for fades etc.
  }

  }

  if (!done)
  {
    setTimeout("do_select_image();", 20);
  }
}
