$(document).ready(function() {
	Shadowbox.init({overlayOpacity:0.8});
	$('#footer a').tipsy({gravity: 's'});
	$('#fotosx ul.panelfoto a').tipsy({gravity: 's'});
	$('#videodx ul.panelfoto a').tipsy({gravity: 's'});
	$('#dati td').click(function () {
		$(this).parent("tr").parent("tbody").parent("table").find("td").removeClass("h");
		$(this).parent("tr").find("td:first-child input").attr("checked", "checked"); 
		$(this).parent("tr").find("td").addClass("h");
	});
	$('#closepop').click(function () {
		$("#pop").hide('slow');
		if ($("#formvideo").css("display")=="none") {
			// aggiorno elenco thumb foto
			$('#fotosx').load('ajax.fotolist.php?start=0',function () { Shadowbox.setup(); $('#fotosx ul.panelfoto a').tipsy({gravity: 's'}); } );

		}
	} );
	$('#uplvideo').click(function () { 
		$("#pop").show('slow');
		$("#formvideo").show();
		$("#formfoto").hide();
	} );
	$('#uplfoto').click(function () { 
		$("#pop").show('slow'); 
		$("#formfoto").show(); 
		$("#formvideo").hide(); 
	} );
	
	if ($('#corpowillnews .paginazione').length > 0) {
		setPaginazione();
	}
	
} );

function fotopage(start) {
	$('#fotosx').load('ajax.fotolist.php?start='+start, function() { Shadowbox.setup(); $('#fotosx ul.panelfoto a').tipsy({gravity: 's'}); });
}
function videopage(page,maxpage) {
	$('#videodx ul.panelfoto li').hide();
	$('#videodx ul.panelfoto li.p'+page).show();
	$('#videoback').unbind("click");
	$('#videofwd').unbind("click");
	if (page==0) {
		$('#videoback').fadeTo('slow', 0.5);
	} else { 
		$('#videoback').fadeTo('slow', 1); $('#videoback').click(function() {
			videopage(page-1,maxpage);
		}); 
	}
	if (page==maxpage) { 
		$('#videofwd').fadeTo('slow', 0.5);
	} else {
		$('#videofwd').fadeTo('slow', 1); $('#videofwd').click(function() {
			videopage(page+1,maxpage);
		}); 
	}
}

function switchform() {
	$('#corpoconco').hide("slow");
	$('#corpoform').show("slow");
	return false;
}

function filtratabella() {

	on = $("#filtropv option:selected").html();
	if (on!='tutte') {
		$('#dati tr[rel!='+on+']').hide();
		$('#dati tr[rel^='+on+']').show();
	} else {
		$('#dati tr').show();
	}

}

function setPaginazione () {
	$('#pprec').click(
		function (e) {
			e.preventDefault();
			var $act = $('#corpowillnews .contenitore .lista ul:visible').attr('id');
			var $num = parseInt($act.replace(/l/i,''));
			
			// alert ($act + " - " + $num);
			
			if ($num > 5) {
				var $new = $num - 5;
				$('#corpowillnews .contenitore .lista ul').hide();
				$('#corpowillnews .contenitore .lista ul#l' + $new).show();
			}
		}
	)
	$('#psucc').click(
		function (e) {
			e.preventDefault();
			var $act = $('#corpowillnews .contenitore .lista ul:visible').attr('id');
			var $num = parseInt($act.replace(/l/i,''));
			var $new = $num + 5;
			
			// alert ($act + " - " + $num + " - " + $new);
			
			if ($('ul#l' + ($num + 5)).length > 0) {
				$('#corpowillnews .contenitore .lista ul').hide();
				$('#corpowillnews .contenitore .lista ul#l' + $new).show();
			}
		}
	)
}

function openFanFestPreview(item) {
	var n = item.data('index');
	if (isNaN(n)==false) {
		n++;
		n = "000"+n;
		n = n.substr(n.length-3);
		var html = '';
		html += '<div class="fanfestdetail">';
		html += '<img src="css/img/fanfest/'+n+'.jpg" alt="" ><br/>';
		html += '<a href="download.php?t=fanfest&n='+n+'" onclick="pageTracker._trackPageview(\'/download/fanfest/'+n+'.jpg\')">DOWNLOAD</a>';
		html += '</div>';
		
		
		Shadowbox.open({
			content:    html,
			player:     "html",
			title:      "",
			height:     560,
			width:      806
		});
	}
}


