/* SVN $Id: flashzoomer.js 186 2010-04-13 15:17:42Z masaki $ */
/* SVN $URL: file:///T:/SOURCE_SVN/WHITE_WebShop/trunk/httpdocs/js/flashzoomer.js $ */

/*############################################################################*/
/*# FLASHZOOM */

document.iCurrentImage = 0;

//Flash displayed on the foreground (product content text will hide behind the image)
function showFlashZoom()
{
  var oFlashDiv  = document.getElementById('photoDiv');
  var oDetailDiv = document.getElementById('infoDiv');

  oFlashDiv.style.zIndex = 100;
  oDetailDiv.style.zIndex = 10;
}

//Flash detail image will hide and the product content text displays
function hideFlashZoom()
{
    var oFlashElement = getMovie("detailflashobject");
    
    var oFlashDiv  = document.getElementById('photoDiv');
	  var oDetailDiv = document.getElementById('infoDiv');
	
	  oFlashDiv.style.zIndex = 10;
	  oDetailDiv.style.zIndex = 100;
		  
    if (oFlashElement)
    {
      //oFlashElement.hideDetails();
    }
}

//Activates the animation when clicked on the flash object
function getMovie(movieName)
{
  var oFlashElement = false;
  var bIsIE = isIE();
  if (!oFlashElement)
  {
    try
    {
      oFlashElement = document.getElementById(movieName);
    }
    catch(e) {}
  }
  if (!oFlashElement)
  {
    try
    {
      if (bIsIE)
      {
        oFlashElement = window[movieName];
      }
      else
      {
        oFlashElement = document[movieName];
      }
    }
    catch(e) {}
  }
  return oFlashElement;
}

// Tests if the browser is IE. Used to cover the difference in behaviour of browsers
function isIE()
{
  return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}

// Load another image based on the Javascript array defined in the catalog PHP page.
function gotoImageNr(iNr)
{
  //debugger;
  if ( 'number' == typeof document.iCurrentImage && document.aImageList )
  {
    if ('undefined' != typeof(iNr))
    {
      document.iCurrentImage = iNr;
    }

    var oFirstButton = WHITE_GetElementFlex('detailphotofirst');
    var oPrevButton = WHITE_GetElementFlex('detailphotoprev');
    var oNextButton = WHITE_GetElementFlex('detailphotonext');
    var oLastButton = WHITE_GetElementFlex('detailphotolast');

    var oCurrentImageIndicator = WHITE_GetElementFlex('detailphotocurrent');
    if ('object' == typeof oCurrentImageIndicator)
    {
      oCurrentImageIndicator.innerHTML = document.iCurrentImage + 1;
    }

    var oImageElement = WHITE_GetElementFlex('detailimage');
    if ('object' == typeof oImageElement)
    {
      if (oImageElement.src != document.aImageList[document.iCurrentImage])
      {
        oImageElement.src = document.aImageList[document.iCurrentImage];
      }
    }

    if ( WHITE_GetWindowLoadCompleted() )
    {
      var oFlashElement = getMovie("detailflashobject");
      if (oFlashElement && document.aImageList[document.iCurrentImage] && document.aImageListDetail[document.iCurrentImage])
      {
        //debugger;
        oFlashElement.setImageUrl(document.aImageListDetail[document.iCurrentImage], document.aImageList[document.iCurrentImage]); // aImageList[iCurrentImage]
      }
    }

    //add index to zoom link
    var oZoomLink = WHITE_GetElementFlex('zoom-1');
    if ('object' == typeof oZoomLink)
    {
      if (-1 == oZoomLink.href.indexOf('index='))
      {
        oZoomLink.href += '&index=' + document.iCurrentImage;
      }
      else
      {
        oZoomLink.href = oZoomLink.href.replace(/index=([0-9]+)/, 'index=' + document.iCurrentImage);
      }
    }
  }
}
/*# /FLASHZOOM */
/*############################################################################*/
