

  // on dom ready
  window.addEvent('domready', function(){


    // in popup
    if ($('webshopPopupCloseButton'))
    {
      // close buttons click event :: close popup
      $('webshopPopupCloseButton').addEvent('click', hideWebshopPopup);
      if ($('webshopPopupCloseLink')) $('webshopPopupCloseLink').addEvent('click', hideWebshopPopup);

      // parent links click event :: target parent window
      $$('.parentLink').each(function(parentLink){
        parentLink.addEvent('click', function(event){
          parent.document.location = this.href;
          event.preventDefault();
        });
      });
    }
    else
    {
      // order buttons click event :: open ordering popup
      $$('.buttonOrder').each(function(buttonOrder){
        var element, link;
        if (buttonOrder.tagName.toLowerCase() == 'a') link = buttonOrder.href;
        else if (element = buttonOrder.getParent('a')) link = element.href;
        else if (element = buttonOrder.getParent('form')) link = element.action;

        buttonOrder.addEvent('click', showWebshopPopup.bindWithEvent(buttonOrder, link));
      });
    }

  });


  function showWebshopPopup(event, link)
  {

      if (window.console && window.console.info) console.info('popup');
    if (!window.webshopPopup)
    {
      window.webshopPopup = document.createElement('div');
	  webshopPopup = $(webshopPopup);
      webshopPopup.innerHTML = '<iframe style="width: 100%; height: 100%;" frameborder="0" scrolling="no"></iframe>';
      webshopPopup.id = 'webshopPopup';
      webshopPopup.style.display = 'none';
      webshopPopup.style.position = 'absolute';
      webshopPopup.inject(document.getElement('body'));
    }

		var form = this.getParent('form'), element, versionId;
		if(element = form.getElement('.productId')) link += '?productId=' + element.value;

		// quantity
		if (element = form.getElement('.quantityInput')) link += '&quantity=' + element.value;
		else link += '&quantity=1';
		// version
// make sure a version is selected, default to first
//		if (element = form.getElement('.versionSelect')) link += '&versionId=' + (element.value != '' ? element.value : element.options[1].value);
		if (element = form.getElement('.versionSelect')) link = link.replace(/&versionId=[0-9]*/, '') + '&versionId=' + (versionId = element.value);
		else if (element = $('form_format_div')) link = link.replace(/&versionId=[0-9]*/, '') + '&versionId=' + (versionId = element.className.replace(/.*versionId=([0-9]*)\s?.*?/, '$1'));
// for innotec : color
if (element = $('form_color_' + versionId)) link += '&color=' + urlencode(element.value);
else if (element = $('form_color_div_' + versionId)) link += '&color=' + urlencode(element.innerHTML.replace(/\s\([^\(\)]*\)$/, '') + '::' + element.innerHTML.replace(/.*\(([^\(\)]*)\)$/, '$1'));

		webshopPopup.getElement('iframe').src = link;
		webshopPopup.style.left = event.page.x-230 + 'px';
		webshopPopup.style.top = event.page.y-160 + 'px';
		webshopPopup.style.display = 'block';

		event.preventDefault();
	}

  function urlencode(str) 
  {
    return escape(str).replace(/\+/g,'%2B').replace(/%20/g, '+').replace(/\*/g, '%2A').replace(/\//g, '%2F').replace(/@/g, '%40');
  }


  function hideWebshopPopup()
  {
    var webshopPopup = window.parent.webshopPopup;

//var webshopPopupIframe = webshopPopup.getElement('iframe');
//(webshopPopupIframe.contentWindow.document || webshopPopupIframe.document).location = 'about:blank';
    webshopPopup.getElement('iframe').src = 'about:blank';
    webshopPopup.style.display = 'none';

    if ($('webshopPopupCloseLink')) window.parent.document.location = window.parent.document.location;
  }


  function resizeWebshopPopup(width, height)
  {
    var webshopPopup = window.parent.webshopPopup;

    webshopPopup.style.width = width + 'px';
    webshopPopup.style.height = height + 'px';
  }

