//#############################################################################
//# Add onload events
//#############################################################################
if ('function' == typeof WHITE_AddLoadEvent)
{
  //# Create overimages in links
  if ('function' == typeof WHITE_ChangeOverImagesInit)
  {
    WHITE_AddLoadEvent(WHITE_ChangeOverImagesInit);
  }

  //# Create link on print button
  if ('function' == typeof LEVANTO_AddPrintButton)
  {
    WHITE_AddLoadEvent(LEVANTO_AddPrintButton);
  }

  //# Init projectphoto fader
  if ('function' == typeof LEVANTO_ProjectPhotoFaderInit)
  {
    WHITE_AddLoadEvent(LEVANTO_ProjectPhotoFaderInit);
  }
}

/*#############################################################################
# Create printbutton
#############################################################################*/
function LEVANTO_AddPrintButton()
{
  var oPrintButton = WHITE_GetElementFlex('printbutton');
  if ('object' == typeof oPrintButton)
  {
    var oHeaderLogo = WHITE_GetElementFlex('logo_levanto');
    if ('object' == typeof oHeaderLogo)
    {
      var sPrintLogo = '<div id="printlogo"><img src="/images/printlogo.gif" alt="" /></div>';
      WHITE_InsertBeforeElement(oHeaderLogo, sPrintLogo);
    }
    WHITE_AddEvent(oPrintButton, 'click', LEVANTO_PrintWindow);
  }
}

function LEVANTO_PrintWindow()
{
  window.print();
}

/*#############################################################################
# Project foto fader functions
#############################################################################*/
//# This function needs a global var aProjectFiles with the full URL of the image
function LEVANTO_ProjectPhotoFaderInit()
{
  if ('number' == typeof iMaxPhoto)
  {
    var oProjectPhoto = WHITE_GetElementFlex('projectphoto');
    if ('object' == typeof (oProjectPhoto))
    {
      oProjectPhoto.src = aProjectFiles[0];
    }

    var sContent = '';
    for (var iNr = 0; iNr < aProjectFiles.length; iNr++)
    {
      sContent += '<img src="' + aProjectFiles[iNr] + '" alt="" width="1" height="1" style="display:none;" />';
    }
    var oSiteDiv = WHITE_GetElementFlex('site');
    if ('object' == typeof oSiteDiv)
    {
      WHITE_InsertAfterElement(oSiteDiv, sContent);
    }

    if (1 < iMaxPhoto)
    {
      var oInterval = setInterval('LEVANTO_ProjectPhotoFader()', 4000);
    }
  }
}

function LEVANTO_ProjectPhotoFader()
{
  iPhotoNr++;
  if (iPhotoNr >= iMaxPhoto)
  {
    iPhotoNr = 0;
  }
  
  LEVANTO_BlendImage('content_photo', 'projectphoto', aProjectFiles[iPhotoNr], 800);
}

function LEVANTO_BlendImage(sDivId, sImageId, sImageFile, iMilliSec)
{
  //# Set fade speed
  var iSpeed = Math.round(iMilliSec / 100);
  var iTimer = 0;

  //# Set the current image as background
  var oDivElement   = WHITE_GetElementFlex(sDivId);
  var oImageElement = WHITE_GetElementFlex(sImageId);
  if ('object' == typeof oDivElement
      && 'object' == typeof oImageElement)
  {
    oDivElement.style.backgroundImage = "url(" + oImageElement.src + ")";
  }

  //# Make image transparent
  setTimeout("LEVANTO_ChangeOpac(0, '"+sImageId+"')", 100);

  //# Set new src on image
  setTimeout("LEVANTO_ChangeImage('"+sImageId+"','"+sImageFile+"')", 100);

  //# Fade in image
  for(var iNr = 0; iNr <= 100; iNr++) {
    setTimeout("LEVANTO_ChangeOpac(" + iNr + ",'" + sImageId + "')",(iTimer * iSpeed));
    iTimer++;
  }
}

function LEVANTO_ChangeImage(sImageId, sImageFile)
{
  var oElement = WHITE_GetElementFlex(sImageId);
  if ('object' == typeof oElement)
  {
    oElement.src = sImageFile;
  }
}

function LEVANTO_ChangeOpac(iOpacity, sId) {
  var oElement = WHITE_GetElementFlex(sId);
  if ('object' == typeof oElement)
  {
    oElement.style.opacity      = (iOpacity / 100);
    oElement.style.MozOpacity   = (iOpacity / 100);
    oElement.style.KhtmlOpacity = (iOpacity / 100);
    oElement.style.filter       = "alpha(opacity=" + iOpacity + ")";
  }
}

