﻿/// <reference path="jquery-1.6.1.js" />
/// <reference path="jquery-ui-1.8.13.custom.min.js" />
/// <reference path="jquery.slidingGallery-1.2.min.js" />
/// <reference path="jquery.slidingGallery-1.2.js" />


(function ($) {

    $(function () {

        $('#container').show();

        if ($('#logoIntro').lenth > 0) {
            if ($('#logoIntro').height() > ($(window).height() * 0.7)) {
                $('#logoIntro').height($(window).height() * 0.7);
            }

            $('#logoIntro').height($(window).height() * 0.7);
        }

        

        $('.containerLink').unbind('click');
        $('.containerLink').click(function () {

            $(this).fadeOut(1000, function () {
                location.href = $(this).find('a').attr('href');
            });
            return false;
        });


        $(".menu_nav li a").each(function () {
            var link = location.href;
            //        console.log("link: " + link);
            //        console.log("href: " + $(this).attr("href"));
            //        console.log("math: " + link.match($(this).attr("href")));
            if (link.match($(this).attr("href")) != null) {
                $(this).css(
                {
                    backgroundImage: "url(img-icon/buttonMenuHovered.png)"
                });
            }
        });

        $("#makeMeScrollable div.scrollableArea img").unbind('click');
        $("#makeMeScrollable div.scrollableArea img").click(function () {
            id = this.id;
            id_immagine = id.substring(4, id.length);


            callback = function () {
                $('.gallery img').removeClass();
                $('#' + id_immagine).addClass("start");
                $("#galleria").show();
                $('#makeMeScrollable').css('visibility', 'hidden');

                //image sliders
                var zoomFunc = function (dimension) {
                    return dimension * 1.8;
                }
                var shrinkFunc = function (dimension) {
                    return dimension * 0.5;
                }
                $('div.gallery img').slidingGallery({
                    'slideSpeed': 'slow',
                    'Lzoom': zoomFunc,
                    'Pzoom': zoomFunc,
                    'Lshrink': shrinkFunc,
                    'Pshrink': shrinkFunc
                });

                $("#closeButton").unbind('click');
                $("#closeButton").click(function () {
                    $("#galleria").hide();
                    $('#makeMeScrollable').css('visibility', 'visible');
                    return false;
                });
            }

            //se esiste il div galleria
            if ($('#galleria').length > 0) {
                callback();
            }
            else {
                $.ajax({
                    url: "gallery.html",
                    dataType: "text",
                    success: function (data, textStatus, jqXHR) {

                        html = data;
                        $("#container").append(html);
                        callback();
                    }
                });
            }

            return false;

        });

    });

    $(window).load(function () {
        if ($('div#makeMeScrollable').length > 0) {
            $("div#makeMeScrollable").smoothDivScroll({
                autoScroll: "OnStart",
                autoScrollDirection: "backandforth",
                autoScrollStep: 1,
                autoScrollInterval: 15,
                startAtElementId: "min-img1",
                visibleHotSpots: "always"
            });
        }
    });

})(jQuery);



