// JavaScript Document
jQuery(document).ready(function(){
	
	jQuery ('a').each(function(){
		var href=jQuery(this).attr('href');
		if (href){
			if (href.search('file=')>0){
				var first=href.search('file=')+5;
				var last=href.search('#immagine');
				var str=href.substr(first,last-first)
				jQuery(this).attr('href','contenuti/upload/sized/'+str);
				jQuery(this).imageZoom();
			}
		}
	});

	jQuery ('a').each(function(){
		var href=jQuery(this).attr('href');
		if (href){
			if (href.search('info=')>0){
				var preview = jQuery(this).closest('p.more').next('.anteprima').text();
				var lastword = preview.substring(0,160).lastIndexOf(' ');
				if (lastword <= 0)
					lastword = 160;
				jQuery(this).closest('p.more').before('<div class="intro"><p>'+preview.substring(0,lastword)+'...</p></div>');
				jQuery(this).html('<strong>Leggi tutto</strong>');
			}
		}
	});

	jQuery ('a').click(function(){
		var href=jQuery(this).attr('href');
		if (href){
			if (href.search('info=')>0){
				if (jQuery(this).text()=='Leggi tutto'){
					jQuery(this).closest('p.more').prev('.intro').css({'display':'none'});
					jQuery(this).closest('p.more').next('.anteprima').css({'display':'block'});
					jQuery(this).html('<strong>Nascondi articolo</strong>');
				} else {
					jQuery(this).closest('p.more').prev('.intro').css({'display':'block'});
					jQuery(this).closest('p.more').next('.anteprima').css({'display':'none'});
					jQuery(this).html('<strong>Leggi tutto</strong>');
				}
				return false;
			}
		}
	});

});
