/*############################################################################*/
/*# Initialize */

function Main_Initialize()
{
	ROLLOVER_Init();
	Catalog_Product_Initialize();
	Catalog_TAF_Initialize();
	
  var oForm = WHITE_GetElementFlex('search');
  if ('object' == typeof oForm)
  {
    WHITE_InitFieldExplanation('searchfield', 'zoeken');
    WHITE_AddEvent(oForm, 'submit', WHITE_FormRemoveEplanationsEvent);
  }
}

if ('function' == typeof WHITE_AddBodyLoadFunction)
{
  WHITE_AddBodyLoadFunction(Main_Initialize);
}

/*# /Initialize */
/*############################################################################*/
/*# ROLLOVER */

function ROLLOVER_Init()
{
	//Grouppage products
	WHITE_AddEventToClass('group_holder', 'rollover', 'mouseover', showImageTwo, 'a');
	WHITE_AddEventToClass('group_holder', 'rollover', 'mouseout', showImageOne, 'a');

	//Matching products
	WHITE_AddEventToClass('matching_foldout', 'rollover', 'mouseover', showImageTwo, 'a');
	WHITE_AddEventToClass('matching_foldout', 'rollover', 'mouseout', showImageOne, 'a');
}

function showImageOne(oEvent)
{
	var oRollover 			= this;
	var aImage 					= WHITE_GetElementsByClass(oRollover, 'productphoto', 'img');
	var oImage					= aImage[0];
	var aPreLoadImages 	= WHITE_GetElementsByTagName('imagepreload1', 'img');
	
	for (var iP=0; iP < aPreLoadImages.length; iP++)
	{
		var oPreloadImage = aPreLoadImages[iP];
		if (oPreloadImage.id == oImage.id)
		{
			oImage.src = oPreloadImage.src;
		}
	}
}

function showImageTwo(oEvent)
{
	var oRollover 			= this;
	var aImage 					= WHITE_GetElementsByClass(oRollover, 'productphoto', 'img');
	var oImage					= aImage[0];
	var aPreLoadImages 	= WHITE_GetElementsByTagName('imagepreload2', 'img');
	
	for (var iP=0; iP < aPreLoadImages.length; iP++)
	{
		var oPreloadImage = aPreLoadImages[iP];
		if (oPreloadImage.id == oImage.id)
		{
			oImage.src = oPreloadImage.src;
		}
	}
}

/*# /ROLLOVER */
/*############################################################################*/
/*# SNIP_PRODUCT */

document.iCurrentImage = 0;

function Catalog_ThumbPhotoClick(oEvent)
{
  if (this && this.src)
  {
    Catalog_ThumbSelect(this.src);
  }
}

function Catalog_ThumbSelect(sThumbUrl)
{
  var oImageElement = WHITE_GetElementFlex('detailimage');
  if (sThumbUrl && oImageElement)
  {
    var sNewDetailSrc = sThumbUrl;
    sNewDetailSrc = sNewDetailSrc.replace('/detailthumb/','/detail/');
    sNewDetailSrc = sNewDetailSrc.replace('/detailzoomthumb/','/detailzoom/');
    if (oImageElement.src != sNewDetailSrc)
    {
      oImageElement.src = sNewDetailSrc;
    }
  }
}

function isIE()
{
  return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}

// FLASH START
function gotoImageNr(iNr)
{
  //debugger;
  if ( 'number' == typeof document.iCurrentImage && document.aImageList )
  {
    if ('undefined' != typeof(iNr))
    {
      document.iCurrentImage = iNr;
    }

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

function getMovie(movieName)
{
  var oFlashElement = false;
  var bIsIE = isIE();
  if (!oFlashElement)
  {
    try
    {
      if (bIsIE)
      {
        oFlashElement = document.getElementById(movieName);
      }
      else
      {
        // there is no difference in behaviour: keeping option to implement
        // a different class if necessary.
        oFlashElement = document.getElementById(movieName);
      }
    }
    catch(e) {}
  }
  if (!oFlashElement)
  {
    try
    {
      if (bIsIE)
      {
        oFlashElement = window[movieName];
      }
      else
      {
        oFlashElement = document[movieName];
      }
    }
    catch(e) {}
  }
  return oFlashElement;
}





function Catalog_Product_Initialize()
{
  WHITE_AddEventToClass(document,'thumb_photo','click',Catalog_ThumbPhotoClick,'img');
}

/*# /SNIP_PRODUCT */
/*###########################################################################*/
/*# SNIP_TAF */

function Catalog_TAF_Initialize()
{
  WHITE_AddEventToClass(document,'CaptchaRefresh','click',Catalog_TAF_RefreshEvent,'a');
}

function Catalog_TAF_RefreshEvent(oEvent)
{
  var oNowDate=new Date();
  var oCaptcha = WHITE_GetElementFlex('captcha');
  if (oCaptcha)
  {
    oCaptcha.src = oCaptcha.src+'&'+oNowDate.getTime();
  }
  return WHITE_CancelEvent(oEvent);
}

if ('function' == typeof WHITE_AddBodyLoadFunction)
{
  WHITE_AddBodyLoadFunction(Catalog_TAF_Initialize);
}

/*# SNIP_TAF */
/*############################################################################*/
