/*
$Id: icons_box.js,v 1.5 2008/10/28 09:31:49 max Exp $
vim: set ts=2 sw=2 sts=2 et:
*/

var saved_product_thumbnail = false;
var outImgTO = false;

/* Icon onmouseover handler */
function dicon_over(w, h) {
	var img = document.getElementById('product_thumbnail');
  if (!img)
    return false;

  if (outImgTO) {
    clearTimeout(outImgTO);
    outImgTO = false;
  }

	if (!saved_product_thumbnail) {
    saved_product_thumbnail = new Image();
		saved_product_thumbnail.src = img.src;
    saved_product_thumbnail.width = img.width;
    saved_product_thumbnail.height = img.height;
  }

  return dicon_set_image(this.href, w, h);
}

/* Icon onmouseout handler */
function dicon_out() {
  outImgTO = setTimeout(
    function() {
      dicon_set_image(saved_product_thumbnail.src, saved_product_thumbnail.width, saved_product_thumbnail.height);
    },
    100
  );
  return true;
}

/* Change product thumbnail (temporary) */
function dicon_set_image(src, w, h) {
  var img = document.getElementById('product_thumbnail');
  if (!img)
    return false;

  img.style.display = 'none';
  img.onload = dicon_show;
  img.width = w;
  img.height = h;

  if ($.browser.msie) {
    var box_h = $(img.parentNode).height();
    img.style.marginBottom = h < box_h ? (box_h - h + 2) : 0;
  }

  setTimeout(
    function() {
      img.src = src;
    },
    20
  );

  return true;
}

/* Icon onclick handler */
function dicon_click(index) {
	if (!det_images_popup_data)
		return true;

  setTimeout(
    function() {
      popup_image('D', det_images_popup_data.productid, det_images_popup_data.max_x, det_images_popup_data.max_y, det_images_popup_data.product, index);
    },
    100
  );
  return false;
}

/* Show delayed product thumbnail */
function dicon_show() {
  var img = document.getElementById('product_thumbnail');
  if (img)
    img.style.display = '';
}

