﻿function img_camere(max_img) {

    var current = 1;

    var hide_testo = true;

    //nascondo mostro il testo
//    $("#immagine").hover(
//    //Mouseover, fadeIn the hidden hover class
//        function () {
//            if (hide_testo)
//                $("#cont_pagine").hide("slide", { orientation: "vertical" }, 1000, function () { });
//        },
//    //Mouseout, fadeOut the hover class
//        function () {
////            if (hide_testo)
////                $("#cont_pagine").show("slide", { orientation: "horizontal" }, 1000, function () { });
//            //hide_testo = true;
    //        });

    $("#img_sfondo").mouseenter(function () {
        $("#cont_pagine").hide("slide", { orientation: "horizontal" }, 1000, function () { });
       // hide_testo = true;
    });

    $("#img_sfondo").mouseleave(function () {
        $("#cont_pagine").show("slide", { orientation: "horizontal" }, 1000, function () { });
       // hide_testo = true;
    });

    $('#img_sfondo').live('mousemove', function (e) {
        var $this = $(this);
        var imageWidth = parseFloat($this.css('width'), 10);

        var x = e.pageX - $this.offset().left + 60;
        if (x < (imageWidth / 2))
            $this.addClass('prev_img_cursor').removeClass('next_img_cursor');
        else
            $this.addClass('next_img_cursor').removeClass('prev_img_cursor');

    });

    $('#img_sfondo').click(function () {
        var $this = $(this);
        hide_testo = false;
        if ($this.is('.next_img_cursor')) {
            caricaImg_click('next_img_cursor');
        }
        else if ($this.is('.prev_img_cursor')) {
            caricaImg_click('prev_img_cursor');
        }
    });

//    $('#immagine').live('click', function () {
//        var $this = $(this);
//        hide_testo = false;
//        if ($this.is('.next_img_cursor')) {
//            caricaImg_click('next_img_cursor');
//        }
//        else if ($this.is('.prev_img_cursor')) {
//            caricaImg_click('prev_img_cursor');
//        }
//    });

    function caricaImg_click(cursorClass) {
        $("#cont_pagine").hide();
        if (cursorClass == 'next_img_cursor' && current < max_img) {
            $("#img_" + current).fadeOut(200, function () {
                current = current + 1;
                $("#img_" + current).fadeIn(200); 
            });
            //$('#immagine').empty();
            //$('#img_sfondo').html('');
            //$('#immagine').remove();
//            current = current + 1;
//            $('<img id="immagine" style="display:none;"/>').load(function () {
//                var $this = $(this);
//                if (!$('#img_sfondo').find('img').length) {
//                    $('#img_sfondo').append($this.fadeIn(1000));
//                }
//            }).attr('src', 'Immagini/camere/' + current + '.jpg');
        }
        else if (cursorClass == 'prev_img_cursor' && current > 1) {
            $("#img_" + current).fadeOut(200, function () {
                current = current - 1;
                $("#img_" + current).fadeIn(200); 
            });
//            //$('#immagine').empty();
//            //$('#img_sfondo').html('');
//            $('#immagine').remove();
//            current = current - 1;
//            $('<img id="immagine" style="display:none;"/>').load(function () {
//                var $this = $(this);
//                if (!$('#img_sfondo').find('img').length) {
//                    $('#img_sfondo').append($this.fadeIn(1000));
//                }
//            }).attr('src', 'Immagini/camere/' + current + '.jpg');
        }
    }
}
