arrProductImages = new Array();
arrProductVideoImages = new Array();
arrProductVideoPlayListImages = new Array();

function switchImage(id)
{
  idtype = 'product_thumb_image_';
  x = id.substring(idtype.length,id.length);
  if (document.getElementById('product_image'))
  {
    if (typeof(arrProductImages[x]) != 'undefined')
    {
      if($('#product_video_object'))
      {
        $('#product_video_object').remove();
      }
      $('#product_image').show();
      document.getElementById('product_image').src = arrProductImages[x];
    }
  }

  return false;
}

function switchVideo(id)
{
  idtype = 'product_thumb_image_';
  x = id.substring(idtype.length,id.length);
  if (document.getElementById('product_image'))
  {
    if (typeof(arrProductImages[x]) != 'undefined' && typeof(arrProductVideoImages[x]) != 'undefined')
    {
      if($('#image_left') && arrProductVideoImages[x] != "")
      {
        if($('#product_video_object'))
        {
          $('#product_video_object').remove();
        }
        $('#product_image').hide();
        $('#image_left').append('<object id="product_video_object" width="'+($('#product_image').attr("width"))+'" height="'+($('#product_image').attr("height"))+'"><param name="movie" value="http://www.youtube.com/v/'+arrProductVideoImages[x]+'&hl=en&fs=1&rel=0&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+arrProductVideoImages[x]+'&hl=en&fs=1&rel=0&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'+($('#product_image').attr("width"))+'" height="'+($('#product_image').attr("height"))+'"></embed></object>');
      }
    }
    if (typeof(arrProductImages[x]) != 'undefined' && typeof(arrProductVideoPlayListImages[x]) != 'undefined')
    {
      if($('#image_left') && arrProductVideoPlayListImages[x] != "")
      {
        if($('#product_video_object'))
        {
          $('#product_video_object').remove();
        }
        $('#product_image').hide();
        $('#image_left').append('<object id="product_video_object" width="'+($('#product_image').attr("width"))+'" height="'+($('#product_image').attr("height"))+'"><param name="movie" value="http://www.youtube.com/p/'+arrProductVideoPlayListImages[x]+'&hl=en&fs=1&rel=0&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/p/'+arrProductVideoPlayListImages[x]+'&hl=en&fs=1&rel=0&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'+($('#product_image').attr("width"))+'" height="'+($('#product_image').attr("height"))+'"></embed></object>');
      }
    }
  }

  return false;
}

function setImages()
{
  var x;

  if (document.getElementById('product_image'))
  {
    for(x = 0; x < 12; x++)
    {
      if (document.getElementById('product_thumb_image_'+x) && typeof(arrProductVideoImages[x]) != 'undefined')
      {
        document.getElementById('product_thumb_image_'+x).onclick = function() { return switchVideo(this.id); };
      }
      else if (document.getElementById('product_thumb_image_'+x))
      {
        document.getElementById('product_thumb_image_'+x).onclick = function() { return switchImage(this.id) };
      }
    }
  }
}
