function centerImage() {


    var imageWidth = $(".BevCanEurope .HomeTop img.main").width();
    var imageHeight = $(".BevCanEurope .HomeTop img.main").height();

    var newWidth = 376 - (imageWidth / 2);
    var newHeight = 0;
    if ((imageHeight > 0) && (imageHeight < 250)) {
        newHeight = 125 - (imageHeight / 2);
    }



    $(".BevCanEurope").css('backgroundPosition', newWidth + 'px ' + newHeight + 'px');
    $(".BevCanEurope").css('backgroundImage', 'url(\'' + $(".BevCanEurope .HomeTop img.main").attr("src") + '\')');
    $(".BevCanEurope .HomeTop img.main").remove();



}

function applyZoom() {
   
    $(".zoomActivator").bezoom();
}

$(document).ready(function() {


    if ($(".allImages").length > 0) {


        if ($(".BevCanEurope .HomeTop img.main").complete) {

            centerImage();

        }


        $(".BevCanEurope .HomeTop img.main").load(centerImage());
    }
    else {


        $(".BevCanEurope").css('backgroundImage', 'url(\'' + $(".BevCanEurope .HomeTop img.main").attr("src") + '\')');
        $(".BevCanEurope .HomeTop img.main").remove();




    }



    applyZoom();

    var currentImage = 0;
    var numberOfImages = $(".allImages img").length;


    $("#nextImageProduct").click(function() {


        if (currentImage < (numberOfImages - 1)) {

            currentImage = currentImage + 1;
        }
        else {
            currentImage = 0;


        }
        $("#mainImage").attr("src", $(".allImages img:eq(" + currentImage + ")").attr("src"));
        $(".zoomActivator").attr("href", $(".allImages img:eq(" + currentImage + ")").attr("src").replace("/prev/", "/"));
        applyZoom();


    });


    $("#nextImage").click(function() {


        var imageWidth = 0;
        var imageHeight = 0;

        if (currentImage < (numberOfImages - 1)) {

            if ($.browser.msie) {

                var dimensions = document.getElementById('image' + (currentImage + 1)).getAttribute("alt").split("x");

                imageWidth = dimensions[0];
                imageHeight = dimensions[1];

            }
            else {
                imageWidth = $(".allImages img:eq(" + (currentImage + 1) + ")").attr("width");
                imageHeight = $(".allImages img:eq(" + (currentImage + 1) + ")").attr("height");
            }

            var newWidth = 376 - (imageWidth / 2);
            var newHeight = 0;
            if ((imageHeight > 0) && (imageHeight < 250)) {
                newHeight = 125 - (imageHeight / 2);
            }
            $(".BevCanEurope").css('backgroundPosition', newWidth + 'px ' + newHeight + 'px');




            $(".BevCanEurope").css('backgroundImage', 'url(\'' +
$(".allImages img:eq(" + (currentImage + 1) + ")").attr("src") +

'\')');

            currentImage = currentImage + 1;

        }
        else {
            currentImage = 0;
            if ($.browser.msie) {
                var dimensions = document.getElementById('image' + currentImage).getAttribute("alt").split("x");

                imageWidth = dimensions[0];
                imageHeight = dimensions[1];
            }
            else {
                imageWidth = $(".allImages img:eq(" + (currentImage) + ")").attr("width");
                imageHeight = $(".allImages img:eq(" + (currentImage) + ")").attr("height");
            }
            var newWidth = 376 - (imageWidth / 2);

            if ((imageHeight > 0) && (imageHeight < 250)) {
                newHeight = 125 - (imageHeight / 2);
            }


            $(".BevCanEurope").css('backgroundPosition', newWidth + 'px ' + newHeight + 'px');





            $(".BevCanEurope").css('backgroundImage', 'url(\'' +
$(".allImages img:eq(" + (currentImage) + ")").attr("src") +

'\')');
        }


    });


});