$(document).ready(function() {
	
	$("#menucontroller").click (function() {
		var stato="chiuso";
		if (stato=="chiuso") {
			$('#ilmenu').slideDown('slow', function() {
				stato="aperto";
			});
		}
		if (stato=="aperto") {
			$('#ilmenu').slideUp('slow', function() {
				stato="chiuso";
			});
		}
	});
	
	/*$("#contenuti_rq_testa").click (function() {
		window.location.href = "index.asp";
	});*/
	// console.log("avvio java"); 
	
	$("a[rel*=external]").live("click", function(){
		window.open($(this).attr("href"));
		return false;
	});

	var nrel=0;
	$("a").each(function (i) {
		if ($(this).hasClass("box")) {
			nrel++;
		}
	});

		if (jQuery.fancybox) {
		for (u=1;u<=nrel;u++) {
			$("a[rel=example_group" + u +"]").fancybox({
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'titlePosition' 	: 'over',
			'overlayOpacity'  : 0.7,
			'overlayColor'    : '#000',
			'titleFormat'	: function(title, currentArray, currentIndex, currentOpts) {
				return '<span id="fancybox-title-over">Immagine ' + (currentIndex + 1) + ' di ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '<'+'/span>';
				}
			});
		}
	}
	
	$('a.email').each(function(i) {
		var text = $(this).attr("href");
		var address = text.replace(" at ", "@");
		$(this).attr('href', 'mailto:' + address);
	});  

	$('.rotondiSmall').each(function(i) {
		$(".rotondiSmall").corner("10px");
		$(".rotondiBig").corner("30px");
	});   
});	


function openCtg( form ) { 
	var newIndex = form.ctg.selectedIndex; 
	if ( newIndex === 0 ) { 
		alert( "Fai una selezione" ); 
	} else { 
		cururl = form.ctg.options[ newIndex ].value; 
		window.location.assign( cururl ); 
	} 
} 

function openarea( form ) { 
	var newIndex = form.area.selectedIndex; 
	if ( newIndex === 0 ) { 
		alert( "Fai una selezione" ); 
	} else { 
		cururl = form.area.options[ newIndex ].value; 
		window.location.assign( cururl ); 
	} 
} 

function openpiccenter(url,name,x,y){
	var sx = screen.width;
	var sy = screen.height;
	var wx = (sx/2) - (x/2);
	var wy = (sy/2) - (y/2) - 50;
	picxywindow = window.open(url,name,"width=" + x + ",height=" + y + ",menubar=0,resizable=0,scrollbars=1,status=0,titlebar=0,toolbar=0,left="+ wx +",top=" + wy);
	picxywindow.focus();
}	

function openPhoto (_n) {
	 i1 = new Image;
	 var chemin = _n;
	 i1.src = chemin;
	 html = '<HTML>\n<HEAD>\n<TITLE>Le immagini</TITLE>\n</HEAD>\n<BODY LEFTMARGIN=0 MARGINWIDTH=0 TOPMARGIN=0 MARGINHEIGHT=0>\n<CENTER><IMG SRC="'+chemin+'" BORDER=0 NAME=imageTest onLoad="window.resizeTo(document.imageTest.width+14,document.imageTest.height+32)"></CENTER>\n</BODY>\n</HTML>';
	 popupImage = window.open('','pop','_blank','toolbar=0,location=0,directories=0,menuBar=0,scrollbars=0,resizable=0');
	 popupImage.document.open();
	 popupImage.document.write(html);
	 popupImage.document.close();
	 popupImage.focus();
}

function checkIt(evt) {
    evt = (evt) ? evt : window.event
    var charCode = (evt.which) ? evt.which : evt.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        status = "Il campo accetto solo cifre- only numeric values are permitted"
        return false
    }
    status = ""
    return true
}

function validacerca(t) {
	if (t.srcid.value == ""){
		alert("Scrivi un codice da cercare- Insert a code to search");
		t.srcid.focus();
		return (false);
	}
	return (true);
}


