﻿////////////////////////////////////////////////////////////////////////////////////////////////////
// Norman Geiersbach
// Eitido (c) 2008
// Version 1.0.0.0
// Created 03/07/2007
//
// Description
//   
//
// History
//   05/14/2008 swapImageLink added
//   03/07/2007 File created
////////////////////////////////////////////////////////////////////////////////////////////////////


// Image utility functions
////////////////////////////////////////////////////////////////////////////////////////////////////

// preloadImage
// Preload an image file
  function preloadImage(imageUrl)
  {
    if( imageUrl == "" )
      return false;
      
    var image = new Image();
    image.src = imageUrl;
    
    return image != null;
  }


// blendImage
// Activate blending in IE for swapImage
  function blendImage(imageElement, duration)
  {  
    // Validate element parameter
    if( typeof imageElement == "string" )
      imageElement = getElement(imageElement);
    
    // Enable blending by setting a blend filter
    if( imageElement.filters ) if( window.createPopup )
    {
      if( duration == null )
        duration = 0.3;
    
      // Define filter for gallery image      
      imageElement.style.filter = 'blendTrans(Duration=' + duration + ')';
      
      // Make sure the filter is not playing.
      if( (imageElement.filters.blendTrans != null) || (imageElement.filters.blendTrans.status != 2) )
      {
        // Apply and play it
        imageElement.filters.blendTrans.apply();
        imageElement.filters.blendTrans.play();
      }
    }
    
    return true;
  }


// swapImage
// Swaps an image source
  function swapImage(imageElement, imageUrl)
  {
    if( imageUrl == "" )
      return false;
  
    // Validate element parameter
    if( typeof imageElement == "string" )
      imageElement = getElement(imageElement);
    
    // Swap image
    imageElement.src = imageUrl;
    
    return true;
  }


// swapImageLink
// Swaps an image link reference
  function swapImageLink(linkElement, imageUrl)
  {
    if( imageUrl == "" )
      return false;
  
    // Validate element parameter
    if( typeof linkElement == "string" )
      linkElement = getElement(linkElement);
    
    // Swap image link
    linkElement.href = imageUrl;
    
    return true;
  }
  
  
// swapImageByDropDown
// Swaps an image source by selected value of a dropdown list
  function swapImageByDropDown(ddlElement, imageElement, imagePath)
  {
    // Validate element parameters
    if( typeof ddlElement == "string" )
      ddlElement = getElement(ddlElement);
    if( typeof imageElement == "string" )
      imageElement = getElement(imageElement);
    
    for( i = 0; i < ddlElement.length; ++i )
    {
      if( ddlElement.options[i].selected == true )
        swapImage(imageElement, imagePath + ddlElement.options[i].value);
    }
  }
