function explodeArray(item,delimiter) {
  var tempstring=new String(item);
  tempArray=new Array(1);
  var Count=0; 

  while (tempstring.indexOf(delimiter)>0) { 
    tempArray[Count]=tempstring.substr(0,tempstring.indexOf(delimiter)); 
    tempstring=tempstring.substr(tempstring.indexOf(delimiter)+1,tempstring.length-tempstring.indexOf(delimiter)+1);
    Count=Count+1 
  } 
  tempArray[Count]=tempstring; 
  return tempArray; 
}

var sdiak = "áäčďéěíĺľňóô öŕšťúů üýřžÁÄČĎÉĚÍĹĽŇÓÔ ÖŔŠŤÚŮ ÜÝŘŽ";
var bdiak = "aacdeeillnoo-orstuu-uyrzAACDEEILLNOO-ORSTUU-UYRZ";

function bezdiak(txt)
{
  var tx = "";
  for(p = 0; p < txt.length; p++)
  {
    if (sdiak.indexOf(txt.charAt(p)) != -1)
	{
	  tx += bdiak.charAt(sdiak.indexOf(txt.charAt(p)));
	}
	else tx += txt.charAt(p);
  }
  return tx;
}

jQuery(document).ready(function() {
    jQuery("#imageShowcase img#productImg").hide();
    jQuery("#imageShowcase img").hide();
    jQuery("#productImgDefault").show();
    
    jQuery(".product-custom-option:first").change(function() {  
        jQuery("#imageShowcase img#productImg").hide();
        jQuery("#imageShowcase img").hide();  
        var optionValue = jQuery(this).attr('value');
        var optionValueText = jQuery.trim(jQuery(".product-custom-option:first :selected").text());
        var baseText = explodeArray(optionValueText,' +');
        var baseText = explodeArray(baseText,' ');
        if (baseText[0]!='-- Please select --' && baseText[0]!='--' && baseText[0]!='') {
          baseText[0] = bezdiak(baseText[0]);
          var imgSrc = jQuery("#productImg" + baseText[0]).attr('src');
          if (imgSrc) {
            jQuery("#productImg" + baseText[0]).show();
          } else {
            jQuery("#productImgDefault").show();
          }
        } else {
          jQuery("#productImgDefault").show();
        }
    });
});