var _image = 1;
var _multiplier = 599 / 109;
function zoom(e) {
    var x, y;
    if (document.all) {
        x = event.clientX + document.body.scrollLeft;
        y = event.clientY + document.body.scrollTop;
    } else {
        x = e.pageX;
        y = e.pageY;
    }
    if (_image == 1 || _image == 3) {
        x = x - 10;
    } else {
        x = x - 130;
    }
    if (_image == 1 || _image == 2) {
        y = y - 80;
    } else {
        y = y - 230;
    }
    if (x < 0) {
        x = 0;
    } else if (x > 109) {
        x = 109;
    }
    if (y < 0) {
        y = 0;
    } else if (y > 109) {
        y = 109;
    }
    var img = new Image();
    img.src = document.getElementById("Big").src;
    imgwidth = img.width;
    imgheight = img.height;
    var bigX = parseInt(x * _multiplier * (imgwidth - 400) / 600);
    var bigY = parseInt(y * _multiplier * (imgheight - 400) / 600);
    document.getElementById("BigDiv").style.left = 250 - bigX;
    document.getElementById("BigDiv").style.top = 10 - bigY;
    document.getElementById("BigDiv").style.clip = "rect(" + bigY + ", " + (400 + bigX) + ", " + (400 + bigY) + ", " + bigX + ")";
}
function show(i) {
    _image = i;
    document.getElementById("Big").src = document.getElementById("Big" + i).src;
}
var $j = jQuery.noConflict();
$j(document).ready(function() {
    function isNumeric(value) {
        if (value == null || !value.toString().match(/^[-]?\d*\.?\d*$/)) return false;
        return true;
    }
    function roundNumber(number, digits) {
        var multiple = Math.pow(10, digits);
        var rndedNum = Math.round(number * multiple) / multiple;
        return rndedNum;
    }
    var qty;
    var tmp;
    var price;
    var unitprice;
    var totalPrice = 0;
    function calTotalPrice() {
        totalPrice = 0;
        $j.each($j("input.q-input"),
        function(i, val) {
            if ($j(this).val() == "") {
                qty = 0.00;
            }
            if ($j(this).val() == 0) {
                qty = 0.00;
            }
            qty = $j(this).val();
            qty = parseInt(qty);
            price = $j(this).next().html();
            price = price.replace(/[^\d.]/g, '');
            price = parseFloat(price);
            unitprice = price * qty;
            totalPrice += unitprice;
        });
        totalPrice = roundNumber(totalPrice, 2);
        $j("li.final-total h3 strong").html("&pound;" + totalPrice);
    }
    $j.each($j("input.q-input"),
    function(i, val) {
        $j(val).keyup(function(e) {
            qty = $j(this).val();
            if(e.which == 8 || e.which == 46){
                return;
            }
            if (isNumeric(qty)) {
                calTotalPrice();
            } else {
                alert('Please enter a number');
                qty = qty.substring(0, qty.length - 1);
                $j(val).val(qty);
                return;
            }
        });
    });
});