(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 = 1280;  
		var startheight = 751;
		//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);
		//$(this).children().css('top', (browserheight - $(this).height())/2);
	};
})(jQuery);


$(document).ready(function() {
	// apply supersize to background div
	$("div#supersize").supersize();
	// delay news div slide-in
	//setTimeout("toggleMenu('#news')", 3000);
	// delay & manage opacity of Moltitudine button
	//setTimeout("toggleMenu('#d_upload')", 4000);
	$('#b_upload').mouseover(function() {
		$('#d_upload').animate({ opacity: 0.75 }, 300);
		return false; 
		});
	$('#b_upload').mouseout(function() {
		$('#d_upload').animate({ opacity: 1 }, 300);
		return false; 
		});
	// toggle (+) on selected menu items
	$('.menuitem').click(function() {
		var $this = $(this);
		if ($this.find('span').length != 0) {
			$this.children().remove();
		} else {
			$this.parent().find("span.plus_add").remove();
			if ($this.attr("id") != 'bio' && $this.attr("id") != 'biblio' && $this.attr("id") != 'press' && $this.attr("id") != 'credits' && $this.attr("id") != 'app') {
				$this.append('<span class="plus_add"></span>');
			}
		}
	});
	//main menu init
	$('#mMenu').click(function() { toggleMenu('#menu1_content'); });
});
