jQuery(document).ready(function () {
  defaultOpt1 = jQuery("select[optitle=plaque] option:selected").text();
  defaultOpt2 = jQuery("select[optitle=inscription] option:selected").text();
  //Update On Option change
  jQuery(".product-custom-option").change(function() {
    updateTitle();
  });

  //Update on page Load
  updateTitle();


});

/* Martin - THIS IS WHERE WE UPDATE THE TITLES ON THE DROP DOWNS */
/* Martin - Hide images with class == Hidden - special Hack for Ociel */
function updateTitle() {
  //alert(g_productid);
  if(jQuery("select[optitle=plaque]").length !=0) {
    opt1 = jQuery("select[optitle=plaque] option:selected").text();
    opt2 = jQuery("select[optitle=inscription] option:selected").text();

    // If this is Ociel then insert quotes around the Inscription
    if (g_productid == 24) {
       opt2 = trim(opt2);
       opt2 = opt2.replace(/ /, " \"");
       opt2 += "\"";
    }
    optclass = opt1 + "- " + opt2.replace(/\s+$/,"");
    //alert(opt2);

    jQuery(".product-shop .title_option1").text(opt1+" | ");
    jQuery(".product-shop .title_option2").text(opt2);

    if((defaultOpt1) && (defaultOpt2)) {
      if((opt1 == defaultOpt1) && (opt2 == defaultOpt2)) {
		jQuery(".product-view .product-img-box .more-views li.Hidden").hide();
		jQuery(".product-view .product-img-box .more-views li[style='display: list-item;']").eq(0).hide();
		jQuery(".product-view .product-img-box .more-views li.Side").show();
		jQuery(".product-view .product-img-box .more-views li.Front").show();
		jQuery(".product-view .product-img-box .more-views ul").css('marginLeft', 18);
      } else {
		jQuery(".product-view .product-img-box .more-views li.Hidden").hide();
		jQuery(".product-view .product-img-box .more-views li.Side").hide();
		jQuery(".product-view .product-img-box .more-views li.Front").hide();
		jQuery(".product-view .product-img-box .more-views li[style='display: list-item;']").eq(0).hide();
		jQuery("li[class*='"+optclass+"']").show();
		jQuery(".product-view .product-img-box .more-views ul").css('marginLeft', 56);
      }
    } else {
      defaultOpt1 = opt1;
      defaultOpt2 = opt2;
    }
  }
}


/* Martin - THIS IS WHERE WE UPDATE THE TITLES ON THE DROP DOWNS */
/* Martin - Hide images with class == Hidden - special Hack for Ociel */
/* Martin - Special Hack for Ociel to show names after click on image */
function updateTitleAlternate(opt1, opt2) {
    var topt2;

    // If this is Ociel then insert quotes around the Inscription
    if (g_productid == 24) {
       topt2 = trim(opt2);
       topt2 = topt2.replace(/ /, " \"");
       topt2 += "\"";
    }

    optclass = opt1 + "- " + opt2.replace(/\s+$/,"");
    //alert(g_productid);

    /* change the title text now */
    jQuery(".product-shop .title_option1").text(opt1+" | ");
    jQuery(".product-shop .title_option2").text(topt2);

    /* Change the drop down lists now - this will butcher the lists */
    jQuery("select[optitle=plaque] option:selected").text(opt1);
    jQuery("select[optitle=inscription] option:selected").text(opt2);

    if((defaultOpt1) && (defaultOpt2)) {
      if((opt1 == defaultOpt1) && (opt2 == defaultOpt2)) {
		jQuery(".product-view .product-img-box .more-views li.Hidden").hide();
		jQuery(".product-view .product-img-box .more-views li[style='display: list-item;']").eq(0).hide();
		jQuery(".product-view .product-img-box .more-views li.Side").show();
		jQuery(".product-view .product-img-box .more-views li.Front").show();
		jQuery(".product-view .product-img-box .more-views ul").css('marginLeft', 18);
      } else {
		jQuery(".product-view .product-img-box .more-views li.Hidden").hide();
		jQuery(".product-view .product-img-box .more-views li.Side").hide();
		jQuery(".product-view .product-img-box .more-views li.Front").hide();
		jQuery(".product-view .product-img-box .more-views li[style='display: list-item;']").eq(0).hide();
		jQuery("li[class*='"+optclass+"']").show();
		jQuery(".product-view .product-img-box .more-views ul").css('marginLeft', 56);
      }
    } else {
      defaultOpt1 = opt1;
      defaultOpt2 = opt2;
    }
}

function trim(strText) { 
    // this will get rid of leading spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
} 



