(function($){
	//Resize image on ready or resize
	$.fn.supersize = function() {	
		//Invoke the resizenow() function on document ready
		$(document).ready(function() {
			$('#supersize').resizenow(); 
		});
		//Invoke the resizenow() function on browser resize
		$(window).bind("resize", function() {
    		$('#supersize').resizenow(); 
		});
	};
	//Adjust image size
	$.fn.resizenow = function() {
		//Define starting width and height values for the original image
		var startwidth = 1399;  
		var startheight = 899;

		//Define image ratio
		var ratio = startheight/startwidth;
		//Gather browser dimensions
		var browserwidth = $(window).width();
		var browserheight = $(window).height();
		//Resize image to proper ratio
		if ((browserheight/browserwidth) > ratio) {
		    $(this).height(browserheight);
		    $(this).width(browserheight / ratio);
			$('#grid').height(browserheight);
			$('#grid').width(browserheight / ratio);
		    $(this).children().height(browserheight);
		    $(this).children().width(browserheight / ratio);
		} else {
		    $(this).width(browserwidth);
		    $(this).height(browserwidth * ratio);
			$('#grid').width(browserwidth);
		    $('#grid').height(browserwidth * ratio);
		    $(this).children().width(browserwidth);
		    $(this).children().height(browserwidth * ratio);
		}
		//Make sure the image stays center in the window
		$(this).children().css('left', (browserwidth - $(this).width())/2);
	        //ci va l'if per non far sparire il pulsante//	
        $(this).children().css('top', (browserheight - $(this).height())/2);
	};
})(jQuery);

function bigMe() {
	$(this).animate({"width":"200","height":"404", "marginTop":"-=20"}, 350);
}
function smallMe() {
	$(this).animate({"width":"170","height":"343", "marginTop":"+=20"}, 350);
}


$(document).ready(function() {
	// apply supersize to background div
    $("div#supersize").supersize();
	$('#supersize').resizenow(); 

	$('.more').click(function() {
		$(this).parent().next().slideToggle('slow');
	});
	
	$('#schedule a').click(function() {		
		if ($(this).next().css("display") == 'none') { 
			$(this).css("background-image","url(img/minus.png)");
		} else {
			$(this).css("background-image","url(img/plus.png)");
		}
		$(this).next().slideToggle('slow');
	});
	
	$('.cards').hoverIntent(bigMe,smallMe);
	$('.cards').click(function() {
		var tit = $('#'+$(this).attr('rel'));
		if (tit.css("display") == 'none') { 
			tit.prev().css("background-image","url(img/minus.png)");
		} else {
			tit.prev().css("background-image","url(img/plus.png)");
		}
		$('#'+$(this).attr('rel')).slideToggle('slow');
	});
	
	$("#gmaps").colorbox({width:"80%", height:"50%", iframe:true});
	
});

