/*
 FILE JS PRINCIPALE PER VIAGGIARE TERRA E MARE
*/

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 jQuery*/
var isIE6 = false;
jQuery.each(jQuery.browser, function(i, val) {
	if(jQuery.browser.msie && jQuery.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 = jQuery('#Credits').width();
	var CreditsHeight = jQuery('#Credits').height();
	jQuery('#btnCredits').click(
		function(event) {
			event.preventDefault();
			jQuery('#Flash object').css('visibility','hidden');
			var width = (getViewportWidth() - CreditsWidth)/2;//210
			var height = (getViewportHeight() - CreditsHeight)/2;
			jQuery('#Fondo').prepend("<div id='Overlay' style='opacity:0;display:block;position:absolute;top:0;left:0;width:"+getDocumentWidth()+"px;height:"+getDocumentHeight()+"px;background-color:#000;'></div>");
			jQuery('#Overlay').fadeTo(500,0.8);
			if (isIE6) {
				jQuery('html,body').animate({scrollTop: 0}, 1000);
				jQuery('#Credits').css('position','absolute');
			}
			jQuery('#Credits').css('left',width+'px').css('top',height+'px').show("blind",{direction:"vertical"},500);
		});
	jQuery('#Chiudi').click(
		function(event) {
			event.preventDefault();
			jQuery('#Credits').hide("blind",{direction:"vertical"},500);
			jQuery('#Overlay').fadeTo(500,0,function(){jQuery('#Overlay').remove()});
		});
}
jQuery(document).ready(InitCredits);