/*...........................................    

   General funciotns

...........................................*/	

jQuery.fn.toggleText = function(a, b) {
	return this.each(function() {
		jQuery(this).text(jQuery(this).text() == a ? b : a);
	});
};

jQuery.fn.equalHeights=function() {
	var maxHeight=0;
	this.each(function(){
		if (this.offsetHeight>maxHeight) {maxHeight=this.offsetHeight;}
	});
	this.each(function(){
		$(this).height(maxHeight + "px");
		if (this.offsetHeight>maxHeight) {
			$(this).height((maxHeight-(this.offsetHeight-maxHeight))+"px");
		}
	});
};



$(document).ready(function(){

/*...........................................    

   	AIAP box

...........................................*/


	$(".abox").click(function () {
		var heightM = $(document).height();
		var url = $(this).attr("rel");
		if (typeof(url) != "undefined") {
			
			$("#loader object").hide();
			$("<div></div>").appendTo("body").addClass("overlay");
			$(".overlay").height(heightM);
			$("<div></div>").prependTo("body").addClass("aiapbox").load(url);
			$(".aiapbox").css("background","transparent url(/img/loadingAnimation.gif) center no-repeat").click(function () {
			});
			
			 $(".aiapbox").ajaxComplete(function(){
			   $(".aiapbox").css("background","none");
			 });
			 
			
		}
	});

/*...........................................    

   	Accessories

...........................................*/
	
/*
	estende colonna centrale se c'è un embed
*/
	
	$("embed").parents(".col2").width("480px");

/*
	equal heights
*/

	$(".equalh").equalHeights();

/*...........................................    

   Triggers

...........................................*/

			
$(".trigger").click(function () {
	
	$(this).next().toggle("slow");
	
});

/*...........................................    

   Biblioteca

...........................................*/

$(".librion").parents().show();

$(".randomlibro").css("cursor","pointer").click(function () {
	var url = $(this).attr("rel");
	if (typeof(url) != "undefined") {
		$(this).next(".ajax_libroDetail").empty().css("background", "transparent url(/img/loadingAnimation.gif) 30px no-repeat").load(url);
		 $(".ajax_libroDetail").ajaxComplete(function(){
		   $(".ajax_libroDetail").css("background","none");
		 });
	}
 });


$(".biblioList TBODY TR").mouseover(function(){
	var url = $(this).attr("rel");
	$(this).addClass("on").click(function(){
	window.open(url, '_self');
	})
}).mouseout(function(){
	$(this).removeClass("on");
});


$(".bibliobox").css("cursor","pointer").mouseover(function(){

	$(this).addClass("on");

}).mouseout(function(){

	$(this).removeClass("on");

}).click(function(){
	
	var url = $(this).find("A").attr("href");
	//alert(url);
	window.open(url, '_self');

});
	
$(".view LI A").css("cursor","pointer").click(function(){	
	$(".libri").hide();
	$(".view LI A").removeClass("on");
	
	var trigged = $(this).attr("rel");
	$(".t").hide();
	$("#"+trigged).show();
	$(this).addClass("on");
	
})
		
		
 $(".biblioList").tablesorter(); 


$(".advancedsearch:has(input:text[value])").show(); 



$("#showGrid").click(function(){
	$("BODY").toggleClass("grid");
});


		 
		 

});
