﻿// riporta la pagina in alto
$(document).ready(function () {

    $('#go_to_top').click(function () {
        $('html, body').animate({ scrollTop: 0 }, 'slow');
        return false;
    });


});

// opacizza l'immagine al passaggio del mouse della pagina cataolo prodotti
$(document).ready(function () {
    $(".prodotto a img").hover(function () {
        $(this).stop()
.animate({ opacity: 0.7 }, "medium")
    }, function () {
        $(this).stop()
.animate({ opacity: 1 }, "medium")
    });
});

// opacizza l'immagine al passaggio del mouse della pagina dettaglio prodotto
$(document).ready(function () {
    $("#openimage img").hover(function () {
        $(this).stop()
.animate({ opacity: 0.7 }, "medium")
    }, function () {
        $(this).stop()
.animate({ opacity: 1 }, "medium")
    });
});

// apre un popoup con l'immagine del prodotto
jQuery(document).ready(function () {

    var offsetX = 20;
    var offsetY = 10;


    $('#openimage img').hover(function (e) {

        var href = $(this).attr('src'); // get link url
        var dotPosition = href.lastIndexOf(".");  // get the last dot position
        var extension = href.substring(dotPosition, href.length); // get the file extension

        href = href.substring(0, href.length - 7 - extension.length); // delete file extension, dot and size information from this string
        href = href + "350x350" + extension; // create new string which will be the address to the large image

        $('<img id="largeImage" src="' + href + '" alt="Immagine Grande" />')

		.css('top', e.pageY + offsetY)
		.css('left', e.pageX + offsetX)

		.appendTo('body');
    }, function () {
        $('#largeImage').remove();
    });

    $('#openimage img').mousemove(function (e) {

        if ($(window).height() - e.pageY < 0) { //check if it will fit on the screen



            $("#largeImage").css('top', e.pageY + offsetY - 350);
        }
        else {
            $("#largeImage").css('top', e.pageY + offsetY);
        }
        if ($(window).width() - e.pageX < 0) {

            $("#largeImage").css('left', e.pageX + offsetX - 350);
        }
        else {
            $("#largeImage").css('left', e.pageX + offsetX);
        }
    });



}); 





