$.fn.image = function(src, f){ 
    return this.each(function(){ 
     var i = new Image(); 
     i.src = src; 
     i.onload = f; 
     $(i).hide();
     this.appendChild(i);
     
   }); 
} 
function onloadResult(static_code){
	$(".absControl").each(function(){
			$(this).parents("div.risultato").find("div.absClose").hide();
			$(this).toggle(function(){$(this).parents("div.risultato").find("div.absClose").slideDown('slow');$(this).text('chiudi -')},
					function(){$(this).parents("div.risultato").find("div.absClose").slideUp();$(this).text('leggi tutto +')}
					)
		});
		$(".absControlPDF").each(function(){
			$(this).parents("div.risultato").find("div.absClosePDF").hide();
			$(this).toggle(function(){$(this).parents("div.risultato").find("div.absClosePDF").slideDown('slow');$(this).text('chiudi -')},
					function(){$(this).parents("div.risultato").find("div.absClosePDF").slideUp();$(this).text('allegati +')}
				)
		});	
		
		$(".slide > a").each(function(){
			var title = $(this).attr("href");
			title = title.substring(0,title.indexOf("/low"))+"/thumb"+title.substring(title.indexOf("/low")+4);
			var titleAttr = $(this).attr("title");
			
			if(!jQuery.browser.safari || jQuery.browser.version > 400){
				$(this).image(title,function(){
					$(this).prev("img").remove();
					$(this).attr("alt",titleAttr);
					$(this).fadeIn();
				});
			}else{
				$(this).find("img").attr("src",title);
				$(this).find("img").attr("alt",titleAttr);
			}
			 
			// $(this).find("img").attr("src", "http://media.regesta.com/dm_0/IBC/IBCAS00132/thumb/"+title + ".jpg")
	});
};
function onloadResultFoto(static_code){
	$('div.boxStoria').hide();
	$('a.storiaFamiglia').toggle(function(){$('div.boxStoria').slideDown()},function(){$('div.boxStoria').slideUp()})
 	$('div.foto[id]').find('img').hover(function(){
 			$(this).attr('src',$(this).parent('div').attr('id'))
 		},function(){
 			$(this).attr('src',$(this).attr('id'))
 		}) 		
}
function onloadHome(){
	
	  $('#sForm').bind('submit', function() {
          $(this).ajaxSubmit({
              target: '#soutput',
              method:'post'
          });
          return false; // <-- important!
      });
	  
	$(".percorsi, .province").hover(function(){
		percorso = $(this).find("img").attr("src");
		$(this).find("img").attr("src",percorso.substring(0,percorso.lastIndexOf("_"))+"_on.jpg")
	},function(){
		percorso = $(this).find("img").attr("src");
		$(this).find("img").attr("src",percorso.substring(0,percorso.lastIndexOf("_"))+"_off.jpg")
	})
}
function onloadNewPage(){
	$("a[rel='newpage']").each(function(){
		$(this).attr("target","_new");
		$(this).attr("rel","");
	})
}
