// JavaScript Document
vistaCodice = function() {
	$(".vedi_ris p").click(function(){
		campo =  $(this).parent().find(":input");
		testo = campo.attr('value');
		nomeCampo = campo.attr('name');
		classeCampo = campo.attr('class');

		if($(this).html()=="[Vista Sito]")
		{
			testoDiv = testo.replace(/\n/g,"<br />");
			$(this).html("[Vista Codice]")
			//$(this).parent().find("div").html("<input type='text' name='"+nomeCampo+"' value='"+testo+"' class=\""+classeCampo+"\"><div class=\""+classeCampo+"\" style=\"background-color:#efefef; padding-bottom:3px; overflow:auto;\">"+testoDiv+"</div>");
			$(this).parent().find("textarea").css("display","none");
			//alert($(this).parent().find("textarea").attr("name"));
			$(this).after("<div class=\""+classeCampo+"\" style=\"background-color:#efefef; padding-bottom:3px; overflow:auto;\">"+testoDiv+"</div>");
		}
		else
		{
			$(this).html("[Vista Sito]")
			$(this).parent().find("textarea").css("display","block");
			$(this).parent().find("div").remove();
		}
	})
}
 
aumenta_counter_tema = function(chiave) {
	$.ajax({
		type: "POST",
		url: "ajax_counter_temi.php",
		data: "codice="+chiave
	});
}

overoutImg = function(){
	cerca = $("img[srcOver]");
	$("img[srcOver]").hover( 
		function() {
		/* funzione per il mouse-over*/
			srcSmall = 	$(this).attr('src');
			$(this).attr('src',$(this).attr('srcOver'));
		},
		function() {
		/* funzione per il mouse-over*/
			$(this).attr('src',srcSmall);
		}
	)
}


creaPopUp = function(){
	//cerco tutte le immagini con attributo srcBig
	$("img[srcBig]").each(function(){
		$(this).css('cursor','pointer');
		$(this).attr('title','Apri Immagine Grande');
		
		$(this).click(function(){
			WFinestra = window.document.body.offsetWidth;
			HFinestra = window.document.body.offsetHeight;
			HImgBig = parseInt($(this).attr('heightBig'));
			WImgBig = parseInt($(this).attr('widthBig'));
			
			posTop = $(this).offset().top - HImgBig;
			if(isNaN(posTop) || posTop<0)
				posTop = 2;
			else if(posTop+HImgBig > HFinestra)
				posTop = HFinestra - HImgBig - 30;
			
			posLeft = $(this).offset().left + parseInt($(this).css('width').replace("px",""));
			if(isNaN(posLeft) || posLeft<0)
				posLeft = 2;
			else if(posLeft+WImgBig > WFinestra)
				posLeft = WFinestra - 2*WImgBig;
		
			$(this).after("<div class='div_pop_up' style='display:none; top:"+posTop+"px; left:"+posLeft+"px'><p title='Chiudi Finestra'>X</p><img src='"+$(this).attr('srcBig')+"'></div>");
			
			$(".div_pop_up").draggable({ 
				cursor: 'pointer'
			});

			$(this).next(".div_pop_up").css('display','block');
		
			$(".div_pop_up p").click(function(){
				$(this).parent().remove();
				//$(this).parent().css('display','none');
			});
			
		});
	})
}

$(document).ready(function() {
	//creaPopUp();
	//overoutImg();
});
