var productImages = [];
// Preloaded image. ID = 1899
productImages[1899] = new Image();
productImages[1899].src="/image/product/medium/violet-profile.jpg";
productImages[1899].alt = "Otis Zulu Violet Fibre with Cool Grey Lens";
// Preloaded image. ID = 1900
productImages[1900] = new Image();
productImages[1900].src="/image/product/medium/violet-front.jpg";
productImages[1900].alt = "Otis Zulu Violet Fibre with Cool Grey Lens";
// Preloaded image. ID = 1901
productImages[1901] = new Image();
productImages[1901].src="/image/product/medium/violet-side.jpg";
productImages[1901].alt = "Otis Zulu Violet Fibre with Cool Grey Lens";
// Preloaded image. ID = 1902
productImages[1902] = new Image();
productImages[1902].src="/image/product/medium/amber-profile.jpg";
productImages[1902].alt = "Otis Zulu Amber Fibre with Tropical Brown Lens";
// Preloaded image. ID = 1903
productImages[1903] = new Image();
productImages[1903].src="/image/product/medium/amber-front.jpg";
productImages[1903].alt = "Otis Zulu Amber Fibre with Tropical Brown Lens";
// Preloaded image. ID = 1904
productImages[1904] = new Image();
productImages[1904].src="/image/product/medium/amber-side.jpg";
productImages[1904].alt = "Otis Zulu Amber Fibre with Tropical Brown Lens";
// Preloaded image. ID = 1905
productImages[1905] = new Image();
productImages[1905].src="/image/product/medium/black-profile-4.jpg";
productImages[1905].alt = "Otis Zulu Black with Cool Grey Lens";
// Preloaded image. ID = 1906
productImages[1906] = new Image();
productImages[1906].src="/image/product/medium/black-front-4.jpg";
productImages[1906].alt = "Otis Zulu Black with Cool Grey Lens";
// Preloaded image. ID = 1907
productImages[1907] = new Image();
productImages[1907].src="/image/product/medium/black-side-4.jpg";
productImages[1907].alt = "Otis Zulu Black with Cool Grey Lens";
// Preloaded image. ID = 1908
productImages[1908] = new Image();
productImages[1908].src="/image/product/medium/ebony-profile.jpg";
productImages[1908].alt = "Otis Zulu Ebony with Tropical Brown Lens";
// Preloaded image. ID = 1909
productImages[1909] = new Image();
productImages[1909].src="/image/product/medium/ebony-front.jpg";
productImages[1909].alt = "Otis Zulu Ebony with Tropical Brown Lens";
// Preloaded image. ID = 1910
productImages[1910] = new Image();
productImages[1910].src="/image/product/medium/ebony-side.jpg";
productImages[1910].alt = "Otis Zulu Ebony with Tropical Brown Lens";
// Preloaded image. ID = 1991
productImages[1991] = new Image();
productImages[1991].src="/image/product/medium/black-profile-11.jpg";
productImages[1991].alt = "Otis Zulu Black with Grey Polarised Lens";
// Preloaded image. ID = 1992
productImages[1992] = new Image();
productImages[1992].src="/image/product/medium/black-front-11.jpg";
productImages[1992].alt = "Otis Zulu Black with Grey Polarised Lens";
// Preloaded image. ID = 1993
productImages[1993] = new Image();
productImages[1993].src="/image/product/medium/black-side-11.jpg";
productImages[1993].alt = "Otis Zulu Black with Grey Polarised Lens";
var productData = [];
var fromPrice = new Array();
var fromMemberPrice = new Array();
productData[2791] = [{19: 1397}, {"price":199.95, "memberPrice":199.95, "exception":'FALSE', "isSpecial":'FALSE', "specialPrice":199.95, "stock":0, "imageId":1908} ];
fromPrice[2791] = 199.95;
fromMemberPrice[2791] = 199.95;
productData[2792] = [{19: 1404}, {"price":199.95, "memberPrice":199.95, "exception":'FALSE', "isSpecial":'FALSE', "specialPrice":199.95, "stock":0, "imageId":1905} ];
fromPrice[2792] = 199.95;
fromMemberPrice[2792] = 199.95;
productData[2793] = [{19: 1771}, {"price":319.95, "memberPrice":319.95, "exception":'FALSE', "isSpecial":'FALSE', "specialPrice":319.95, "stock":0, "imageId":1905} ];
fromPrice[2793] = 319.95;
fromMemberPrice[2793] = 319.95;
productData[2794] = [{19: 1774}, {"price":199.95, "memberPrice":199.95, "exception":'FALSE', "isSpecial":'FALSE', "specialPrice":199.95, "stock":0, "imageId":1902} ];
fromPrice[2794] = 199.95;
fromMemberPrice[2794] = 199.95;
productData[3423] = [{19: 2126}, {"price":199.95, "memberPrice":199.95, "exception":'FALSE', "isSpecial":'FALSE', "specialPrice":199.95, "stock":0, "imageId":1899} ];
fromPrice[3423] = 199.95;
fromMemberPrice[3423] = 199.95;
var attribSets = [19];
// 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 '';
}