<!--
var wm;
var iNumImgWall = 0;
var sPathImgWall = 'images/wall/';
var sExtImage = 'gif';

function checkWindowsize() {
	var w = 0;
	var h = 0;
	var res = false;

	//IE
	if(!window.innerWidth) {
		//strict mode
		if(!(document.documentElement.clientWidth == 0)) {
			w = document.documentElement.clientWidth;
			h = document.documentElement.clientHeight;
		}
		//quirks mode
		else {
			w = document.body.clientWidth;
			h = document.body.clientHeight;
		}
	}
	//w3c
	else {
		w = window.innerWidth;
		h = window.innerHeight;
	}
	
	if(w>0 && h>0)
		if(w>780 && h>540)
			res=true;
	
	return res;
}

window.addEvent('domready', function() {
	$$('a').addEvent('click', function(){this.blur()});
	
	/*** Inizializzazione degli array di immagini da passare all'oggetto WALL ***/
	var i;
	
	iNumImgWall = 70;
	var arAllImg = new Array();
	var sLabelImg = 'wall';
	for (i=1; i<=iNumImgWall; i++) {
		arAllImg[i-1] = i<10 ? sLabelImg +'_0'+ i +'.'+ sExtImage :  sLabelImg +'_'+ i +'.'+ sExtImage;
	}
		
	/***
	Implementiamo un'ulteriore metodo per l'oggetto WALL: "loadingWallComplete".
	Questo metodo viene invocato dal metodo "finish" della class loadWall, alla fine di tutto il processo.
	Questo metodo si occupa di richiamare in sequenza i metodi:
	showTextRule: sposta l'elemento "wrapper_textrule", che contiene l'immagine testo "THE ONLY RULE IS NO RULE", 
					tra le prime due righe del WALL e starting il processo dell'oggetto bubbleFx
					che si occupa dell'effetto dell'immagine testo in questione
	rowWallOpacity: opacizza, nascondendole, tutte le righe di immagini del muro tranne la prima che viene solo opacizzata ma non
					nascosta
	showButtonsAndLogo: visualizza i bottoni che portano alle pagine interne e il logo Montangero.
	***/
	loadWall.implement({
		loadingWallComplete: function() {
			var x = new Chain();
			
			var showTextRule = function(xChain){ 
				$('text_rule_element').show();
				
				new Fx.Tween($('text_rule_element'), {
					property: 'opacity', 
					duration: 800,
					onComplete: function(xChain) {xChain.callChain()}.bind(this, xChain)
				}).start(1);
			
			}.bind(this, x);

			var showFooter = function(xChain){
				$('footer').show();
				
				new Fx.Tween($('footer'), {
					property: 'opacity', 
					duration: 800,
					onComplete: function(xChain) {xChain.callChain()}.bind(this, xChain)
				}).start(1);
			}.bind(this, x);

			var rowWallOpacity = function(xChain) { 
				new Fx.Tween($('wall_row_1'), {
					property: 'opacity', 
					duration: 1500,
					onComplete: function() {
						xChain.callChain();
					}
				}).start(0);
				new Fx.Tween($('wall_row_2'), {
					property: 'opacity', 
					duration: 1500
				}).start(0);
				new Fx.Tween($('wall_row_3'), {
					property: 'opacity', 
					duration: 1500,
					onComplete: function() {
						xChain.callChain();
					}
				}).start(0);
				new Fx.Tween($('wall_row_4'), {
					property: 'opacity', 
					duration: 1500,
					onComplete: function() {
						xChain.callChain();
					}
				}).start(1);
				new Fx.Tween($('wall_row_5'), {
					property: 'opacity', 
					duration: 1500,
					onComplete: function() {
						xChain.callChain();
					}
				}).start(1);
				
				new Fx.Tween($('text_rule_element').getElement('img'), {
					property: 'opacity', 
					duration: 1500
				}).start(0.4);
				
			}.bind(this, x);

			var showButtons = function(){
				$('box_button_pages').show();
				
				var listButtons = $('box_button_pages').getElement('ul');
				
				new Fx.Tween(listButtons, {
					property: 'opacity', 
					duration: 3000
				}).start(1);
			};

			x.chain(showTextRule);
			x.chain(showFooter);
			x.chain(rowWallOpacity);
			x.chain(showButtons);
			x.callChain();
		}
	});

	/*** Dichiarazione e start della Classe loadWall. ***/
	wm = new loadWall({
		container: 'wall-home',
		rows: 5,
		columns: 7,
		labelImage: sLabelImg,
		extImage: sExtImage,
		emptyImage: 'wall_empty.gif',
		maxSteps: 155,
		stepDuration: 24,
		sPathImgWall: sPathImgWall,
		arAllImages: arAllImg
	});
});

window.addEvent('domready', function() {
	$('lnk_home').hide();
	
	$$('.elementMove').each(function(item, index) {
		if(item.getParent().get('id') == 'page_works') {
			new classWorks({
				objectParent: item.getParent(),
				objectMove: item,
				objectClickEvent: item.getElement('.lnk_btn'),
				objectSlider: item.getElement('.slider'),
				objectShowSpot: item.getElement('.works_spot'),
				objectListLink: item.getElement('.listlink')
			});
		}
		else if(item.getParent().get('id') == 'page_whyus' || item.getParent().get('id') == 'page_contact') {
			new sectionClass({
				objectParent: item.getParent(),
				objectMove: item,
				objectClickEvent: item.getElement('.lnk_btn'),
				objectDescription: item.getElement('.slider')
			});
		}
		else if(item.getParent().get('id') == 'page_people') {
			new classPeople({
				objectParent: item.getParent(),
				objectMove: item,
				objectClickEvent: item.getElement('.lnk_btn'),
				objectSlider: item.getElement('.slider'),
				objectDetail: item.getElement('.people_detail')
			});
		}
		else if(item.getParent().get('id') == 'page_heritage') {
			new classHeritage({
				objectParent: item.getParent(),
				objectMove: item,
				objectClickEvent: item.getElement('.lnk_btn'),
				objectSlider: item.getElement('.slider'),
				objectShowSpot: item.getElement('.heritage_spot')
			});
		}
	});
});

//Nascondiamo quegli elementi della pagina visualizzati successivamente durante la sequenza iniziale di effetti visivi
window.addEvent('domready', function() {
	$('box_button_pages').getElement('ul').fade('out');
	$('btn_back').hide();
	$('footer').fade('out');
	$('text_rule_element').fade('out');

	if(checkWindowsize()) {
		$('container_content').position({
			relativeTo: 'container_main',
			offset: {x: 0, y: 0}
		});
	}
});


window.addEvent('domready', function() {
	$('progress-bar').position();
	/* progress bar */
	var progressBar = new dwProgressBar({
		container: $('progress-bar'),
		startPercentage: 0,
		speed:750,
		boxID: 'progress-bar-box',
		percentageID: 'progress-bar-perc',
		displayID: 'progress-bar-perc-text',
		displayText: true
	});
	/* preloading */
	var images = []; 
	for (i=1; i<=iNumImgWall; i++) {
		images[i-1] = i<10 ? sPathImgWall +'wall_0'+ i +'.'+ sExtImage : sPathImgWall +'wall_'+ i +'.'+ sExtImage;
	}
	
	var loader = new Asset.images(images, {
		onProgress: function(counter,index) {
			progressBar.set((counter + 1) * (100 / images.length));
		},
		onComplete: function() {
			$('progress-bar').hide();
			$('wall-home').getElements('a').setStyle('display', 'block');
			
			//var flashvars  = {config:"{playList: [{name:'effetto_start',url: '../flv/effetto_start.flv'}], autoPlay:false, loop: false}"};
			//var params = { allowScriptAccess: "always" };
			//var att = { name: "FlowPlayerObj_IE" };
			//swfobject.embedSWF("swf/FPClassicOnlyPlayVolume.swf", "flv_audio_start", "0", "0", "7", "Scripts/expressInstall", flashvars, params, att);
			
			var flowPlayerStart = document.getElementById("FlowPlayerObj_IE") ? document.getElementById("FlowPlayerObj_IE") : $(document.body).getElement('object[name=FlowPlayerObj_IE]');
			(
				function(){ 
					//flowPlayerStart.DoPlay();
					wm.start();
				}.bind(this)
			).delay(300);
		}
	});
});
//-->