//<![CDATA

window.addEvent('domready', function() {

	var arVersion = navigator.appVersion.split("MSIE");
	var version = parseFloat(arVersion[1]);

	//if(version < 7) document.location.href = "update-browser.html";

	for(var i=0; i<document.links.length; i++) {
		if (document.links[i].rel == "external") document.links[i].target = "_blank";
	}

	if(typeof(do_init) == 'function') do_init();

});

function do_init() {

	var arVersion = navigator.appVersion.split("MSIE");
	var version = parseFloat(arVersion[1]);

	if(version < 7) pngfix();

	var heightWindow = document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
	var heightBody = $('wrapper').offsetHeight;

	/*if(heightWindow > heightBody) {
		heightDoc = heightWindow;
	} else {
		heightDoc = heightBody;
	}*/

	if(heightWindow > 500) {

		heightDoc = heightWindow;

	} else {

		heightDoc = 500;

	}

	var widthWindow = document.body.offsetWidth;
	var widthBody = $('wrapper').offsetWidth;

	/*if(widthWindow > widthBody) {
		widthDoc = widthWindow;
	} else {
		widthDoc = widthBody;
	}*/

	if(widthWindow > 840) {

		widthDoc = widthWindow;

	} else {

		widthDoc = 840;

	}

	$(document.body).setStyle('height', heightDoc + 'px');
	$('contBg').setStyle('height', heightDoc + 'px');

	var imgLoading = new Asset.image('templates/main/immagini/loadingWhite.gif', { id: 'imgLoading'});
	document.body.appendChild(imgLoading);

	$('imgLoading').setStyle('margin', '0 auto');
	$('imgLoading').setStyle('margin-top', (heightDoc / 2) - 20);

	$('imgLoading').fade('in');
	$('wrapperFix').setStyle('opacity', '0');
	$('contBg').setStyle('opacity', '0');

	var imgBackground = new Asset.image('templates/main/immagini/bgIndex.jpg', { id: 'imgBackground', onload:function(img){

		document.body.removeChild(imgLoading);
		$('contBg').appendChild(img);
		resizeImage();
		window.onresize = resizeImage;

		var fnFadeWrapper = function() {

			var fadeWrapper = new Fx.Tween($('wrapperFix'), {duration: 1000, onComplete:function() {

				//effettiPagina();

			}});
			fadeWrapper.start('opacity','1');

		}

		var fadeBg = new Fx.Tween($('contBg'), {duration: 300, onComplete:fnFadeWrapper});
		fadeBg.start('opacity','1');

	}.bindWithEvent(this)});

}

function effettiPagina() {

	$$('.effettoOver').each(function(el) {

		//fx
		var fx = new Fx.Tween(el, {duration: 250, link: 'cancel'});

		el.setStyle('color', '#000000').addEvents({

			'mouseenter': function(e) {

				e.stop();
				fx.start('color', '#fd0202');

			},
			'mouseleave': function(e) {

				e.stop();
				fx.start('color', '#000000');

			},
			'click': function(e) {

				var tmpHref = el.href;
				el.href = 'javascript:void(0);';

				var fadeScritte = new Fx.Tween($('wrapperFix'), {duration: 600, onComplete:function() {

					var fadePage = new Fx.Tween($('contBg'), {duration: 600, onComplete:function() {

						window.location = tmpHref;

					}});
					fadePage.start('opacity','0');

				}});
				fadeScritte.start('opacity','0');

			}

		});

	});

}

function resizeImage() {

	var newHeightWindow = document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
	var newHeightBody = $('wrapper').offsetHeight;

	if(newHeightWindow > 500) {

		newHeightDoc = newHeightWindow;

	} else {

		newHeightDoc = 500;

	}

	var newWidthWindow = document.body.offsetWidth;
	var newWidthBody = $('wrapper').offsetWidth;


	if(newWidthWindow > 840) {
		var newWidthDoc = newWidthWindow;
	} else {
		var newWidthDoc = 840;
	}

	$(document.body).setStyle('height', newHeightDoc+'px');
	$('contBg').setStyle('height', newHeightDoc+'px');

	imgHeight = document.getElementById('imgBackground').offsetHeight;
	imgWidth = document.getElementById('imgBackground').offsetWidth;

	if(newHeightWindow < newHeightBody) {

		$(document.body).setStyle('overflow-y', 'auto');

	} else {

		window.scroll(0, 0);
		$(document.body).setStyle('overflow-y', 'hidden');
		var widthScrollBar = getScrollerWidth();
		newWidthDoc = newWidthDoc + widthScrollBar;

	}

	if(newWidthDoc > newHeightDoc) {

		document.getElementById('imgBackground').height = newHeightDoc;
		document.getElementById('imgBackground').width = ((newHeightDoc * imgWidth) / imgHeight);

		if(newWidthDoc > (document.getElementById('imgBackground').offsetWidth)) {

			document.getElementById('imgBackground').width = newWidthDoc;
			document.getElementById('imgBackground').height = ((newWidthDoc * imgHeight) / imgWidth);

		}

	} else {

		document.getElementById('imgBackground').width = newWidthDoc;
		document.getElementById('imgBackground').height = ((newWidthDoc * imgHeight) / imgWidth);

		if(newHeightDoc > (document.getElementById('imgBackground').offsetHeight)) {

			document.getElementById('imgBackground').height = newHeightDoc;
			document.getElementById('imgBackground').width = ((newHeightDoc * imgWidth) / imgHeight);

		}

	}

	if(document.getElementById('imgBackground').width > document.body.offsetWidth) {

		var newMargin = ((Number(document.body.offsetWidth) - Number(document.getElementById('imgBackground').width)) / 2);

		$('imgBackground').setStyle('margin-left', newMargin + 'px');

	} else {

		$('imgBackground').setStyle('margin-left', 0);

	}

}

function getScrollerWidth() {
    var scr = null;
    var inn = null;
    var wNoScroll = 0;
    var wScroll = 0;

    // Outer scrolling div
    scr = document.createElement('div');
    scr.style.position = 'absolute';
    scr.style.top = '-1000px';
    scr.style.left = '-1000px';
    scr.style.width = '100px';
    scr.style.height = '50px';
    // Start with no scrollbar
    scr.style.overflow = 'hidden';

    // Inner content div
    inn = document.createElement('div');
    inn.style.width = '100%';
    inn.style.height = '200px';

    // Put the inner div in the scrolling div
    scr.appendChild(inn);
    // Append the scrolling div to the doc

    document.body.appendChild(scr);

    // Width of the inner div sans scrollbar
    wNoScroll = inn.offsetWidth;
    // Add the scrollbar
    scr.style.overflow = 'auto';
    // Width of the inner div width scrollbar
    wScroll = inn.offsetWidth;

    // Remove the scrolling div from the doc
    document.body.removeChild(
    document.body.lastChild);

    // Pixel width of the scroller
    return (wNoScroll - wScroll);
}

//]]>
