var max = 0;

$(document).ready(function(){


	$('#ing_disabilitato').tooltip({
		showURL: false,
		track: true,
		fade: 50,
		left: 20,
		top: -10
	});		
/*//////// PHOTOGALLERY //////////////////////////////////////////////////////////////////////////////////////////////////////////*/

	$(".contenitoreNotizie div.scrollable").scrollable({
		size: 3,
		navi:'ul.tabs'
		
	});
		
		
	$(".contenitoreGallery div.scrollable").scrollable({
		size: 10
	});
	
	$(".contenitoreGallery div.scrollable a").lightBox(); 
	
	/*
	$(".dummy").fadeTo(0, ".6");
	
	$(".dummy").hover(function () {
		$(this).fadeTo(300, ".2");
	}, function () {
		$(this).fadeTo(300, ".6");
	});*/
	/*
	$("div.contenitoreGallery div.scrollable div.items a").click(function () {
		$("div.scrollable div.items div").removeClass("current");
		
		var img = $(this).find("img");
		var alt = img.attr("alt");
		var src = img.attr("src").replace('/p-', '/m-');
		
		if (src.indexOf('news') > 0)
			src = src.replace('/m-', '/g-');
		
		$("div.contenitoreFoto").html('<img src="'+src+'" alt="'+alt+'" />');
		$("div.didascaliaFoto").html(alt);
		$("div.didascaliaFoto").show();
		
		$(this).parent().addClass("current");
		
		return false;
	});
	$($("div.contenitoreGallery div.scrollable div.items a")[0]).click();*/

	max = $("div.bloccoContenuto").height() - $("div.descrizione div.scrollable").height();
	
	if (max <= 0) {
		$("a.vert-prev").hide();
		$("a.vert-next").hide();
	}
	
	$("div.bloccoContenuto").css('top', '0');
	$("div.bloccoContenuto").css('position', 'relative');
	
	$(".vert-prev").click(function () {
		scrollUp(30);
	});
	
	$(".vert-next").click(function () {
		scrollDown(30);
	});
	
	if (max > 0) {
		$('div.bloccoContenuto').mousewheel(function(event, delta){
			if (delta > 0) 
				scrollUp(70);
			else 
				scrollDown(70);
			
			return false;
		});
	}
	
	if ($("div.bloccoDownload").length > 0 && $("div.bloccoLink").length > 0) {
		var h_download = $("div.bloccoDownload").height();
		var h_link = $("div.bloccoLink").height();
		
		if (h_download > h_link) {
			$("div.bloccoLink").height(h_download);
		} else {
			$("div.bloccoDownload").height(h_link);
		}
	}
	
	if ($("div.contenitoreGallery img").length <= 10) {
		$("div.contenitoreGallery a.prev").css("visibility", "hidden");
		$("div.contenitoreGallery a.next").css("visibility", "hidden");
	}
});

function scrollUp(q) {
	var current = parseInt($("div.bloccoContenuto").css('top'));
	var target = current + q;
	
	if (target > 0) target = 0;
	
	$("div.bloccoContenuto").stop().animate({
		top: target
	}, 300);
}

function scrollDown(q) {
	var current = parseInt($("div.bloccoContenuto").css('top'));
	var target = current - q;
	
	if (Math.abs(target) > max) target = max * -1;
	
	$("div.bloccoContenuto").stop().animate({
		top: target
	}, 300);
}

