var productImages = [];
// Preloaded image. ID = 4289
productImages[4289] = new Image();
productImages[4289].src="/image/product/medium/serpico_gunmetal_plr-gy_thumbnaill.jpg";
productImages[4289].alt = "Smith Optics Serpico Gunmetal with Grey lenses";
// Preloaded image. ID = 4290
productImages[4290] = new Image();
productImages[4290].src="/image/product/medium/serpico_gunmetal_plr-gy_thumbnaill-1.jpg";
productImages[4290].alt = "Smith Optics Serpico Gunmetal with Polarised Grey lenses";
// Preloaded image. ID = 4291
productImages[4291] = new Image();
productImages[4291].src="/image/product/medium/serpico_matte-black_deep-purple-mrr_thumbnaill.jpg";
productImages[4291].alt = "Smith Optics Serpico Matte Black with Deep Purple Mirror lenses";
// Preloaded image. ID = 4292
productImages[4292] = new Image();
productImages[4292].src="/image/product/medium/serpico_matte-white_plr-gy-grn_thumbnail.jpg";
productImages[4292].alt = "Smith Optics Serpico Matte White with Polarised Gray Green lenses";
// Preloaded image. ID = 4293
productImages[4293] = new Image();
productImages[4293].src="/image/product/medium/serpico_silver_plr-plt_thumbnail.jpg";
productImages[4293].alt = "Smith Optics Serpico Silver with Polarised Platinum lenses";
// Preloaded image. ID = 4294
productImages[4294] = new Image();
productImages[4294].src="/image/product/medium/serpico_silver_plr-plt_thumbnail-1.jpg";
productImages[4294].alt = "Smith Optics Serpico Silver with Platinum lenses";
// Preloaded image. ID = 4295
productImages[4295] = new Image();
productImages[4295].src="/image/product/medium/serpico_gold_brn_thumbnail.jpg";
productImages[4295].alt = "Smith Optics Serpico Gold with Polarised Brown lenses";
// Preloaded image. ID = 4296
productImages[4296] = new Image();
productImages[4296].src="/image/product/medium/serpico_gold_plr-brn_thumbnail.jpg";
productImages[4296].alt = "Smith Optics Serpico Gold with Brown lenses";
// Preloaded image. ID = 4297
productImages[4297] = new Image();
productImages[4297].src="/image/product/medium/serpico_pastrana-signature_gy_thumbnail.jpg";
productImages[4297].alt = "Smith Optics Serpico Pastrana Signature with Grey lenses";
var productData = [];
var fromPrice = new Array();
var fromMemberPrice = new Array();
productData[120] = [{1: 70}, {"price":159.95, "memberPrice":159.95, "exception":'FALSE', "isSpecial":'FALSE', "specialPrice":159.95, "stock":0, "imageId":4295} ];
fromPrice[120] = 159.95;
fromMemberPrice[120] = 159.95;
productData[121] = [{1: 73}, {"price":159.95, "memberPrice":159.95, "exception":'FALSE', "isSpecial":'FALSE', "specialPrice":159.95, "stock":0, "imageId":4293} ];
fromPrice[121] = 159.95;
fromMemberPrice[121] = 159.95;
productData[122] = [{1: 74}, {"price":159.95, "memberPrice":159.95, "exception":'FALSE', "isSpecial":'FALSE', "specialPrice":159.95, "stock":0, "imageId":4289} ];
fromPrice[122] = 159.95;
fromMemberPrice[122] = 159.95;
productData[123] = [{1: 75}, {"price":199.95, "memberPrice":199.95, "exception":'FALSE', "isSpecial":'FALSE', "specialPrice":199.95, "stock":0, "imageId":4294} ];
fromPrice[123] = 199.95;
fromMemberPrice[123] = 199.95;
productData[3963] = [{1: 2471}, {"price":199.95, "memberPrice":199.95, "exception":'FALSE', "isSpecial":'FALSE', "specialPrice":199.95, "stock":0, "imageId":4292} ];
fromPrice[3963] = 199.95;
fromMemberPrice[3963] = 199.95;
productData[3964] = [{1: 2472}, {"price":159.95, "memberPrice":159.95, "exception":'FALSE', "isSpecial":'FALSE', "specialPrice":159.95, "stock":0, "imageId":4291} ];
fromPrice[3964] = 159.95;
fromMemberPrice[3964] = 159.95;
productData[4011] = [{1: 2498}, {"price":199.95, "memberPrice":199.95, "exception":'FALSE', "isSpecial":'FALSE', "specialPrice":199.95, "stock":0, "imageId":4290} ];
fromPrice[4011] = 199.95;
fromMemberPrice[4011] = 199.95;
productData[4012] = [{1: 2503}, {"price":199.95, "memberPrice":199.95, "exception":'FALSE', "isSpecial":'FALSE', "specialPrice":199.95, "stock":0, "imageId":4296} ];
fromPrice[4012] = 199.95;
fromMemberPrice[4012] = 199.95;
productData[4013] = [{1: 2504}, {"price":199.95, "memberPrice":199.95, "exception":'FALSE', "isSpecial":'FALSE', "specialPrice":199.95, "stock":0, "imageId":4297} ];
fromPrice[4013] = 199.95;
fromMemberPrice[4013] = 199.95;
var attribSets = [1];
// Find the variant selected.
function findVariant()
{
found = false; // Found flag.
variantIndex = 0; // The index of the found variant element.
// This just scans for a match and if found it sets the flags and breaks.
// If one mismatch is detected it just breaks the loop.
for (variant in productData) // Loop through the variant array, called 'productData'.
{
for (set in attribSets) // Now loop through the sets.
{
// Get a refference to a attribute set select box.
attrib = document.getElementById("attributes"+attribSets[set]);
// Check to see if the value of that attribute select box is in the productData attribute array.
if (productData[variant][0][attribSets[set]]==attrib.value) { found = true; } else { found = false; break; }
}
if (found==true) { variantIndex = variant; break; }
}
if (variantIndex!=0)
{
var data = productData[variantIndex][1];
data["var_id"] = variantIndex;
return data;
}
else { return false; }
}
// This enables and disables the submit button.
function submitButtonEnable(enabled)
{
if (enabled==false) { document.getElementById("submitButton").disabled = true; }
else { document.getElementById("submitButton").disabled = false; }
}
function specialRowEnabled(enable) {
if (enable==false) {
document.getElementById("specialRow").style.display="none";
document.getElementById("memberPriceRow").style.display="block";
}
else {
document.getElementById("specialRow").style.display="block";
document.getElementById("memberPriceRow").style.display="none";
}
}
// Display stock indicator
function displayStock() {
// Don't show stock
return true;
// Get the selected variant.
variant = findVariant();
if (variant["stock"] < 0) {
stockString = "Made upon ordering";
}
else if (variant["stock"] ==0) {
stockString = "Out of stock";
}
else if (variant["stock"] > 0) {
stockString = "In stock & ready to ship";
}
document.getElementById("stock").innerHTML = stockString;
}
// This is the function that gets called when the user changes the selection.
function changeVariant() {
var member = false;
// Get the selected variant.
variant = findVariant();
// Not a variant, show a from price and disable add to cart
if(!variant) {
var toprice = getToPrice();
var fromprice = getFromPrice();
if(toprice == fromprice)
{
document.getElementById("price").innerHTML = "RRP from AUD$ " + fromprice;
}
else
{
document.getElementById("price").innerHTML = "RRP from AUD$ " + fromprice + " to AUD$ " + toprice;
}
if(member) {
document.getElementById("memberPrice").innerHTML = "";
}
submitButtonEnable(false);
specialRowEnabled(false);
}
// Check if it is an exception.
else if (variant["exception"]=="FALSE") { // See if it is on special.
if (variant["isSpecial"]=="TRUE")
{ // Display the special price with the old price with strike through font.
document.getElementById("price").innerHTML = "RRP: AUD$ " + variant["price"].toFixed(2) + "";
document.getElementById("specialPrice").innerHTML = variant["specialPrice"].toFixed(2) + getDiscountPercentage(variant["price"], variant["specialPrice"]);
specialRowEnabled(true);
} // Just show the normal price.
else
{
if(member) {
document.getElementById("price").innerHTML = "RRP: AUD$ " + variant["price"].toFixed(2) + "";
}
else {
document.getElementById("price").innerHTML = "RRP: AUD$ " + variant["price"].toFixed(2);
}
specialRowEnabled(false);
}
if(member) {
document.getElementById("memberPrice").innerHTML = "Member's Price: AUD$ " + variant["memberPrice"].toFixed(2) + getDiscountPercentage(variant["price"], variant["memberPrice"]);
}
// Stock
displayStock();
if (variant["imageId"]!=0)
{
// Swapping image was confusing the users
//swapImage(variant["imageId"]);
}
submitButtonEnable(true); // Enable the submit button.
}
else {
// Variant must be an exception so display some text and disable the submit button.
document.getElementById("price").innerHTML = "Not Available";
document.getElementById("memberPrice").innerHTML = "";
submitButtonEnable(false);
specialRowEnabled(false);
}
}
function swapImage(image) {
document.prodImageMain.src = productImages[image].src;
document.getElementById("prodImageMainAlt").innerHTML = productImages[image].alt;
}
/**
* Sort the prices for the product
* @return lowest price
*/
function getFromPrice() {
fromPrice.sort(function(a,b){return a - b});
return fromPrice[0].toFixed(2);
}
/**
* Sort the prices for the product
* @return highest price
*/
function getToPrice() {
fromPrice.sort(function(a,b){return b - a});
return fromPrice[0].toFixed(2);
}
/**
* Percentage off
* @param price Original product price
* @param specialPrice on special/sale price
* @return Str Text string displaying percentage if percentage is greater than 0%
*/
function getDiscountPercentage(price, specialPrice) {
var discount;
// Make sure there is a difference in price
if(price - specialPrice <= 0) {
return ' (No Discount)';
}
discount = ((price - specialPrice)/price)*100;
discount = Math.round(discount);
if(discount > 0) {
return ' (' + discount + '% off)'
}
return '';
}