/*############################################################################*/
/*# SNIP_SEARCH */

function MAIN_SearchFormGoogleInit()
{
  var oSearchForm = WHITE_GetElementFlex('searchform');
  WHITE_AddEventToElement(oSearchForm, 'submit', MAIN_SearchFormSubmit);
}

function MAIN_SearchFormSubmit(oEvent)
{
  var oSearchForm = this;
  if ('object' == typeof oSearchForm && 'object' == typeof pageTracker)
  {
    var oSearchBox = WHITE_GetElementFlex('searchfield');
    if ('object' == typeof oSearchBox && oSearchBox.value)
    {
      pageTracker._trackEvent('Search', 'SideBar Search', oSearchBox.value);
    }
  }
}

function MAIN_Search_Init()
{
	var oForm = WHITE_GetElementFlex('searchform');
  if ('object' == typeof oForm)
  {
    WHITE_InitFieldExplanation('searchfield', 'zoeken');
    WHITE_AddEvent(oForm, 'submit', WHITE_FormRemoveEplanationsEvent);
    WHITE_ChangeOverImagesInit();
  }
}

/*# /SNIP_SEARCH */
/*############################################################################*/
/*# SNIP_SUNGLASS */

function Sunglass_Initialize()
{
  //# Defined sizes for popupdiv types
  var aPopupDivSizes = new Array;
  aPopupDivSizes['zoom'] = new Array;
  aPopupDivSizes['zoom']['width']  = 474;
  aPopupDivSizes['zoom']['height'] = 600; // 534
  document['aPopupDivSizes'] = aPopupDivSizes;

  //# Create sunglassdiv and add onclick events
  if ('function' == typeof SUNGLASS_CreateSunglassPopup)
  {
    SUNGLASS_CreateSunglassPopup();
  }
  //# Create close popup links
  if ('function' == typeof SUNGLASS_InitClosePopupWindow)
  {
    SUNGLASS_InitClosePopupWindow();
  }
}

/*# /SNIP_SUNGLASS */
/*############################################################################*/

/*###########################################################################*/
/*# BRANDSCROLLER */

function addBrandscroller()
{
  var noCache = String(new Date().getTime())
  var aFlashvars = {
   jsonurl: "http://www.design-meubelen.com/catalog.php?sitecode=li%26show=jsonbrand%26" + noCache
  };

  var aParams = {
    allowscriptaccess: "always",
		scale: "noscale",
    wmode: "opaque"
  };

  swfobject.embedSWF("http://www.design-meubelen.com/flash/brandscroller.swf", "brandscroller", "700", "94", "9.0", "", aFlashvars, aParams);
}

addBrandscroller();

/*# /BRANDSCROLLER */
/*###########################################################################*/

/*# SNIP_PRODUCT */

function Catalog_Product_Initialize()
{
  WHITE_AddEventToClass(document,'thumb_photo','click',Catalog_ThumbPhotoClick,'img');
  WHITE_AddEventToClass(document,'variantoption','click',Catalog_VariantSelect,new Array('option','input'));
  WHITE_AddEventToElement('zoom-1','click',Catalog_ZoomClick);
}

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 Catalog_VariantSelect(oEvent)
{
  var sCurProductCode = this.value;
  var oDetailThumbHolder = WHITE_GetElementFlex('detailthumb_holder');
  if (oDetailThumbHolder)
  {
    var aCurSpans = WHITE_GetElementsByClass(oDetailThumbHolder,'detail_thumb','span');
    for (var iEl=0;iEl<aCurSpans.length;iEl++)
    {
      WHITE_AddClassName(aCurSpans[iEl],'hidden');
    }
    var oVariantDetailThumbSpan = WHITE_GetElementFlex('detail_thumb_'+sCurProductCode);
    if (!oVariantDetailThumbSpan)
    {
      oVariantDetailThumbSpan = WHITE_GetElementFlex('detail_thumb');
    }
    if (oVariantDetailThumbSpan)
    {
      WHITE_RemoveClassName(oVariantDetailThumbSpan,'hidden');
      var aThumbPhotos = WHITE_GetElementsByClass(oVariantDetailThumbSpan,'thumb_photo','img');
      if ('object' == typeof aThumbPhotos
          && 'object' == typeof aThumbPhotos[0]
          && 'string' == typeof aThumbPhotos[0].src)
      {
        Catalog_ThumbSelect(aThumbPhotos[0].src);
      }
    }
  }
}

function Catalog_ZoomClick(oEvent)
{
  var sVariantCode = WHITE_GetFormFieldValue('productcodezoom','cartform');
  var oDetailImage = WHITE_GetElementFlex('detailimage');
  var sCurrentImg = '';
  if (oDetailImage && oDetailImage.src)
  {
    sCurrentImg = oDetailImage.src.replace(/^.*[\/\\]/g, '');
  }
  var sPopupUrl = '/catalog.php?show=popup_zoom&product_code='+sVariantCode+'&img='+sCurrentImg;
  SUNGLASS_SunglassPopupShowType(sPopupUrl,'zoom');
  return WHITE_CancelEvent(oEvent);
}

if ( 'function' == typeof WHITE_AddBodyLoadFunction )
{
	WHITE_AddBodyLoadFunction(Sunglass_Initialize);
  WHITE_AddBodyLoadFunction(Catalog_Product_Initialize);
  
  WHITE_AddBodyLoadFunction(MAIN_Search_Init);
}

/*# /SNIP_PRODUCT */
