/*
 FILE JS PRINCIPALE PER IL SITO E-XTRATEGY
*/

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($.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());
};

var download = function(url) {
	top.location.href = url;
};

var InitPage = function(){
	var CreditsWidth = $('#Donazione').width();
	var CreditsHeight = $('#Donazione').height();
	
	
	$('.PaypalDownload').click(
			function(event) {
				event.preventDefault();
				var width = (getViewportWidth() - CreditsWidth)/2;//210
				var height = (getViewportHeight() - CreditsHeight)/2;
				$('body').append("<div id='Overlay' style='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);
					$('#Donazione').css('position','absolute');
				}	
				$('#Donazione').css('z-index','1000').css('left',width+'px').css('top',height+'px').show("blind",{direction:"vertical"},500);
				
				setTimeout("download('"+$(this).attr('href')+"')", 20000);
			});
	$('#Chiudi').click(
			function(event) { 
				event.preventDefault();
				$('#Donazione').hide("blind",{direction:"vertical"},500); 
				$('#Overlay').fadeTo(500,0,function(){$('#Overlay').remove()});	
			});

			
	};

	
