var productImages = [];
// Preloaded image. ID = 1864
productImages[1864] = new Image();
productImages[1864].src="/image/product/medium/blackblueprofile.jpg";
productImages[1864].alt = "Otis Seventy7 Black Blue with Cool Grey Lens";
// Preloaded image. ID = 1865
productImages[1865] = new Image();
productImages[1865].src="/image/product/medium/blackbluefront.jpg";
productImages[1865].alt = "Otis Seventy7 Black Blue with Cool Grey Lens";
// Preloaded image. ID = 1866
productImages[1866] = new Image();
productImages[1866].src="/image/product/medium/blackblueside.jpg";
productImages[1866].alt = "Otis Seventy7 Black Blue with Cool Grey Lens";
// Preloaded image. ID = 1867
productImages[1867] = new Image();
productImages[1867].src="/image/product/medium/blacklightsprofile.jpg";
productImages[1867].alt = "Otis Seventy7 Black Lights with Cool Grey Lens";
// Preloaded image. ID = 1868
productImages[1868] = new Image();
productImages[1868].src="/image/product/medium/blacklightsfront.jpg";
productImages[1868].alt = "Otis Seventy7 Black Lights with Cool Grey Lens";
// Preloaded image. ID = 1869
productImages[1869] = new Image();
productImages[1869].src="/image/product/medium/blacklightsside.jpg";
productImages[1869].alt = "Otis Seventy7 Black Lights with Cool Grey Lens";
// Preloaded image. ID = 1870
productImages[1870] = new Image();
productImages[1870].src="/image/product/medium/blackpolarprofile.jpg";
productImages[1870].alt = "Otis Seventy7 Black with Grey Polarised Lens";
// Preloaded image. ID = 1871
productImages[1871] = new Image();
productImages[1871].src="/image/product/medium/blackpolarfront.jpg";
productImages[1871].alt = "Otis Seventy7 Black with Grey Polarised Lens";
// Preloaded image. ID = 1872
productImages[1872] = new Image();
productImages[1872].src="/image/product/medium/blackpolarside.jpg";
productImages[1872].alt = "Otis Seventy7 Black with Grey Polarised Lens";
// Preloaded image. ID = 1873
productImages[1873] = new Image();
productImages[1873].src="/image/product/medium/blackwhiteprofile.jpg";
productImages[1873].alt = "Otis Seventy7 Black White with Cool Grey Lens";
// Preloaded image. ID = 1874
productImages[1874] = new Image();
productImages[1874].src="/image/product/medium/blackwhitefront.jpg";
productImages[1874].alt = "Otis Seventy7 Black White with Cool Grey Lens";
// Preloaded image. ID = 1875
productImages[1875] = new Image();
productImages[1875].src="/image/product/medium/blackwhiteside.jpg";
productImages[1875].alt = "Otis Seventy7 Black White with Cool Grey Lens";
// Preloaded image. ID = 1876
productImages[1876] = new Image();
productImages[1876].src="/image/product/medium/blackprofile-1.jpg";
productImages[1876].alt = "Otis Seventy7 Black with Cool Grey Lens";
// Preloaded image. ID = 1877
productImages[1877] = new Image();
productImages[1877].src="/image/product/medium/blackfront-1.jpg";
productImages[1877].alt = "Otis Seventy7 Black with Cool Grey Lens";
// Preloaded image. ID = 1878
productImages[1878] = new Image();
productImages[1878].src="/image/product/medium/blackside-1.jpg";
productImages[1878].alt = "Otis Seventy7 Black with Cool Grey Lens";
// Preloaded image. ID = 1879
productImages[1879] = new Image();
productImages[1879].src="/image/product/medium/amberfiberprofile.jpg";
productImages[1879].alt = "Otis Seventy7 Amber Fibre with Tropical Brown Lens";
// Preloaded image. ID = 1880
productImages[1880] = new Image();
productImages[1880].src="/image/product/medium/amberfibrefront.jpg";
productImages[1880].alt = "Otis Seventy7 Amber Fibre with Tropical Brown Lens";
// Preloaded image. ID = 1881
productImages[1881] = new Image();
productImages[1881].src="/image/product/medium/amberfibreside.jpg";
productImages[1881].alt = "Otis Seventy7 Amber Fibre with Tropical Brown Lens";
// Preloaded image. ID = 1882
productImages[1882] = new Image();
productImages[1882].src="/image/product/medium/saharaprofile.jpg";
productImages[1882].alt = "Otis Seventy7 Sahara with Tropical Brown Lens";
// Preloaded image. ID = 1883
productImages[1883] = new Image();
productImages[1883].src="/image/product/medium/saharafront.jpg";
productImages[1883].alt = "Otis Seventy7 Sahara with Tropical Brown Lens";
var productData = [];
var fromPrice = new Array();
var fromMemberPrice = new Array();
productData[2779] = [{19: 1401}, {"price":199.95, "memberPrice":199.95, "exception":'FALSE', "isSpecial":'FALSE', "specialPrice":199.95, "stock":0, "imageId":1873} ];
fromPrice[2779] = 199.95;
fromMemberPrice[2779] = 199.95;
productData[2780] = [{19: 1404}, {"price":199.95, "memberPrice":199.95, "exception":'FALSE', "isSpecial":'FALSE', "specialPrice":199.95, "stock":0, "imageId":1876} ];
fromPrice[2780] = 199.95;
fromMemberPrice[2780] = 199.95;
productData[2781] = [{19: 1771}, {"price":319.95, "memberPrice":319.95, "exception":'FALSE', "isSpecial":'FALSE', "specialPrice":319.95, "stock":0, "imageId":1870} ];
fromPrice[2781] = 319.95;
fromMemberPrice[2781] = 319.95;
productData[2782] = [{19: 1774}, {"price":199.95, "memberPrice":199.95, "exception":'FALSE', "isSpecial":'FALSE', "specialPrice":199.95, "stock":0, "imageId":1879} ];
fromPrice[2782] = 199.95;
fromMemberPrice[2782] = 199.95;
productData[2783] = [{19: 1778}, {"price":199.95, "memberPrice":199.95, "exception":'FALSE', "isSpecial":'FALSE', "specialPrice":199.95, "stock":0, "imageId":1867} ];
fromPrice[2783] = 199.95;
fromMemberPrice[2783] = 199.95;
productData[2784] = [{19: 1779}, {"price":199.95, "memberPrice":199.95, "exception":'FALSE', "isSpecial":'FALSE', "specialPrice":199.95, "stock":0, "imageId":1882} ];
fromPrice[2784] = 199.95;
fromMemberPrice[2784] = 199.95;
productData[2785] = [{19: 1780}, {"price":199.95, "memberPrice":199.95, "exception":'FALSE', "isSpecial":'FALSE', "specialPrice":199.95, "stock":0, "imageId":1864} ];
fromPrice[2785] = 199.95;
fromMemberPrice[2785] = 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 '';
}