(function($){
	var ua = navigator.userAgent.toLowerCase();
	var isStrict = document.compatMode == 'CSS1Compat',
	    isOpera = ua.indexOf("opera") > -1,
	    isIE = ua.indexOf('msie') > -1,
	    isIE7 = ua.indexOf('msie 7') > -1,
	    isBorderBox = isIE && !isStrict,
	    isSafari = (/webkit|khtml/).test(ua),
	    isSafari3 = isSafari && !!(document.evaluate),
	    isGecko = !isSafari && ua.indexOf('gecko') > -1,
	    isWindows = (ua.indexOf('windows') != -1 || ua.indexOf('win32') != -1),
	    isMac = (ua.indexOf('macintosh') != -1 || ua.indexOf('mac os x') != -1),
	    isLinux = (ua.indexOf('linux') != -1);
	
	/*Trippetto per Riconoscere IE6 con $*/
	var isIE6 = false;
	$.each($.browser, function(i, val) {
		if($.browser.msie && $.browser.version.substr(0,1)<="6") {
			isIE6 = true;
		}
	});
	
	var getViewportHeight = function(){
	  var height = window.innerHeight; // Safari
	  var mode = document.compatMode;
	  if((mode || isIE) && !isOpera){
	      height = isStrict ? document.documentElement.clientHeight : document.body.clientHeight;
	  }
	  return height;
	};
	var getViewportWidth = function(){
	  var width = window.innerWidth; // Safari
	  var mode = document.compatMode;
	  if(mode || isIE){
	      width = isStrict ? document.documentElement.clientWidth : document.body.clientWidth;
	  }
	  return width;
	};
	var getDocumentHeight = function(){
	  var scrollHeight = isStrict ? document.documentElement.scrollHeight : document.body.scrollHeight;
	  return Math.max(scrollHeight, getViewportHeight());
	};
	var getDocumentWidth = function(){
	  var scrollWidth = isStrict ? document.documentElement.scrollWidth : document.body.scrollWidth;
	  return Math.max(scrollWidth, getViewportWidth());
	};
	
	/*Bottone credits*/
	var InitCredits = function(){
		var CreditsWidth = $('#Credits').width();
		var CreditsHeight = $('#Credits').height();
		$('#btnCredits').click(
			function(event) {
				event.preventDefault();
				$('#Flash object').css('visibility','hidden');
				var width = (getViewportWidth() - CreditsWidth)/2;//210
				var height = (getViewportHeight() - CreditsHeight)/2;
				$('#Fondo').prepend("<div id='Overlay' style='z-index:10;opacity:0;display:block;position:absolute;top:0;left:0;width:"+getDocumentWidth()+"px;height:"+getDocumentHeight()+"px;background-color:#000;'></div>");
				$('#Overlay').fadeTo(500,0.8);
				if (isIE6) {
					$('html,body').animate({scrollTop: 0}, 1000);
					$('#Credits').css('position','absolute');
				}
				$('#Credits').css('left',width+'px').css('top',height+'px').css('z-index','100').show("blind",{direction:"vertical"},500);
			});
		$('#Chiudi').click(
			function(event) {
				event.preventDefault();
				$('#Credits').hide("blind",{direction:"vertical"},500);
				$('#Overlay').fadeTo(500,0,function(){$('#Overlay').remove()});
			});
	}
	
	$(document).ready(InitCredits);
	
})(jQuery);	
