/************************************************
* Image Fader by ITDev 22/07/2009
*************************************************
* Based on BlendTrans code - http://brainerror.net/scripts/javascript/blendtrans/
************************************************/

// Configuration Variables
var text = new Array();
text[0] = 'fixed price or consultancy contracts';
text[1] = 'on time every time';
text[2] = 'high quality zero defects';
var index = 1;                   // The current image index
var seconds_to_display = 5;      // Number of seconds to show an image
var span_id = 'text_fade_span';  // The ID of the <span> element
var div_id = 'text_fade';        // The ID of the <div> element
var seconds_to_fade = 1;         // Number of seconds taken for a fade

// Add the onload function
if (window.addEventListener)
{
  window.addEventListener("load", delay_text_load, false);
}
else if (window.attachEvent)
{
  window.attachEvent("onload", delay_text_load);
}
else if (document.getElementById)
{
  window.onload = delay_text_load;
}

function delay_text_load()
{
    setTimeout("trigger_change_text()", 3000);
}

function trigger_change_text()
{
  // Change Text
  fade_out();
  setTimeout("change_text()", seconds_to_fade * 1000);

  // Set callback
  setTimeout("trigger_change_text()", seconds_to_display * 1000);
}

function change_text()
{
  // Get Text
  var current_text = text[index];
  index++;

  // Change Text
  document.getElementById(span_id).innerHTML = current_text;
  fade_in();

  // Make index wrap around
  if (index >= text.length)
  {
    index = 0;
  }
}

function change_opacity(opacity)
{
  // Get Object
  var object = document.getElementById(span_id).style;

  // Set opacity
  object.opacity = (opacity / 100); // CSS
  object.MozOpacity = (opacity / 100); // Old Mozilla
  object.KhtmlOpacity = (opacity / 100); // KHTML/Safari
  object.filter = "alpha(opacity=" + opacity + ")"; // MSIE
}

function fade_out()
{
  var time_per_change = Math.round((seconds_to_fade * 1000) / 100);
  
  // Fade out image
  for (i = 0; i <= 100; i++)
  {
    var timeout = i * time_per_change;
    setTimeout("change_opacity(" + (100 - i) + ")", timeout);
  }
}

function fade_in()
{
  var time_per_change = Math.round((seconds_to_fade * 1000) / 100);
  
  // Fade in image
  for (i = 0; i <= 100; i++)
  {
    var timeout = i * time_per_change;
    setTimeout("change_opacity(" + i + ")", timeout);
  }
}