$(document).ready(function () {
							
	$(document).pngFix();
	
	$('#tips1').tipsy({gravity: 'sw',fade: true});
	$('#tips2').tipsy({gravity: 'sw',fade: true});
	$('#tips3').tipsy({gravity: 'sw',fade: true});
	$('#tips4').tipsy({gravity: 'sw',fade: true});
	$('#tips5').tipsy({gravity: 'sw',fade: true});
	$('#tips6').tipsy({gravity: 'sw',fade: true});

    $(".list_prj a, .menu a").click(function () {
		QueryLoader.init();
    });	
	
	
    $(".menu").treeview({
        animated: "slow",
        collapsed: true,
        unique: true,
        persist: "location",
        control: "#treecontrol"
    });
    $("#prj .box_pull").click(function () {
        $("#prj .box_text").animate({
            width: 'toggle'
        }, 'slow');
        $(this).toggleClass("box_pull_active");
        return false
    });
    $.fn.cycle.updateActivePagerLink = function (pager, currSlideIndex) {
        $(pager).find('li').removeClass('activeLI').filter('li:eq(' + currSlideIndex + ')').addClass('activeLI')
    };
    $('#MainPic').cycle({
        fx: 'scrollHorz',
        speed: 'slow',
        timeout: 0,
        prev: '#prev',
        next: '#next',
        after: function () {
            $('.didascalia').html(this.alt);
            $('#actual_number').html(this.title)
        }
    });
    $("#successivo").tooltip({
        track: true,
        delay: 0,
        fixPNG: true,
        positionRight: true,
        positionLeft: false,
        extraClass: "successivo",
        top: -20,
        left: 10
    });
    $("#precedente").tooltip({
        track: true,
        delay: 0,
        fixPNG: true,
        extraClass: "precedente",
        positionLeft: true,
        positionRight: false,
        top: -20,
        left: -10
    })
});

function resize_gallery() {
    var altezza = window.innerHeight;
    var larghezza = window.innerWidth;
    var ScreenRatio = Math.round(larghezza / altezza);
    if (ScreenRatio >= 1.6) {
        var altezza_foto = Math.round(larghezza / 1.6);
        var margin_top = Math.round((altezza - altezza_foto) / 2);
        document.getElementById("MainPic").style.width = larghezza + "px";
        document.getElementById("MainPic").style.height = altezza_foto + "px";
        document.getElementById("MainPic").style.marginTop = margin_top + "px";
        document.getElementById("MainPic").style.marginLeft = "0px"
    } else {
        var larghezza_foto = Math.round(altezza * 1.6);
        var margin_left = Math.round((larghezza - larghezza_foto) / 2);
        document.getElementById("MainPic").style.height = altezza + "px";
        document.getElementById("MainPic").style.width = larghezza_foto + "px";
        document.getElementById("MainPic").style.marginLeft = margin_left + "px";
        document.getElementById("MainPic").style.marginTop = "0px"
    }
}
$(window).keydown(function (e) {
    if (e.which == 37) {
        $('#prev').click()
    }
    if (e.which == 39) {
        $('#next').click()
    }
    if (e.which == 33) {
        $('#prev').click()
    }
    if (e.which == 34) {
        $('#next').click()
    }
});
