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

   gianni box

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



jQuery.fn.gianniBox = function(modclass) {
	
	if (modclass == "multimedia") {
		var url = "/pages/getMedia/" + $(this).attr("rel");
		
		var type = $(this).attr("alt");
		
	} else if (modclass == "mymailto") {
		var url = "/pages/mymailto/" + $(this).attr("rel");
		
	} else {
		var url =  $(this).attr("rel");
	}
	
	
	if (typeof(url) != "undefined") {
		
		if (!$('.modal').is(":visible")) {
			//alert(url);
			$("BODY").append("<div class='overlay'></div><div id="+type+" class='modal "+modclass+"'><div class='modalcontent'></div></div>");
		} 
		
		/*$(".modal").draggable({
			handle : ".modalhandle"
		});*/
		
		
		
	}	
	
		$(".overlay").fadeTo(0.5, 0.8);
		$(".modalcontent").html("").css({
			background: "#FFF url('/img/ajax-loader.gif') center 135px no-repeat"
		})
		.load(url)
		.ajaxComplete(function(){
			$(this).css("background-image","none");
			$(".flashcontent").css({'display':'none'});
			var heightM = $(document).height();
			$(".overlay").height(heightM);
		});
		
		$(".modalclose, .overlay").click(function(){
			$(".flashcontent").css({'display':'block'});
			$(".modal, .overlay, .modalcontent").remove();
		});

}


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

   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(){
	
	$(".gbox").click(function(){
		
	$(this).gianniBox("multimedia");

	});

	
	$(".accessori").css({'float':'left'});
	
 	$(document).pngFix(); 
	
	$('.thickbox').click(function(){ 
	$(window).scrollTop(0);
	});

	 $(".biblioteca").tablesorter();
	
	
/*...........................................    

   Structure

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


$(".main, .menuleft,.accessories").equalHeights();


	
	
	
});




