function pageLoaded() {
	//inizializza Move
	Move.init();
	Move.fps = 25; //imposta Frame al secondo (opzionale)
	Move.pps = -40; //imposta pixel al secondo (opzionale)
}

function lento() {
	Move.pps *= .80;
}

function veloce() {
	Move.pps *= 1.20;
}

function display(str) {
	$('display').update(str);	
	}
	
function displayImgBig(str) {
	$('displayImgBig').update(str);	
	}


var Move = {
	fps: 25,
	pps: 20,
	stripeWidth: 0,
	x: 0,
	status: 'stop',

	init: function(event) {
//		alert(this.stripeWidth);		
//		this.stripeWidth = 5;
		var baseDiv = 'stripBox';
		
		this.stageWidth = 800; //Element.getDimensions($('Box')).width;
		this.stripeWidth = (800*8);	//Element.getDimensions($('baseStrip')).width;
		this.stripeHeight = Element.getDimensions($('baseStrip')).height;

		
		Event.observe($('Box'), 'click', Move.open.bindAsEventListener(Move));
		$('Box').show();

		if (this.stageWidth <= this.stripeWidth)
		{

			var repliche = Math.floor(this.stageWidth / this.stripeWidth);
			repliche = 6;

			//this.start();
			Event.observe($('Box'), 'mouseover', Move.freeze.bindAsEventListener(Move));
			//Event.observe($('Box'), 'mouseleave', Move.start.bindAsEventListener(Move));
			Event.observe($('Box'), 'mouseout', Move.start.bindAsEventListener(Move));
			this.stripBoxWidth = (repliche) * this.stripeWidth;
			//duplicate stripe
			var newWidth = this.stripBoxWidth + 'px';
			Element.setStyle($('stripBox'),{
				width: newWidth,
				left:  '0px'
			});
			/*
			var newHeight = this.stripeHeight + 'px';
			alert(newHeight);
			Element.setStyle($('Box'),{
				height: newHeight,
				width: newWidth
			});
			*/
			var newStripe = $(baseDiv).innerHTML; //stripe in HTML
			for (var i=0; i <= repliche; i++) {
				new Insertion.Bottom($(baseDiv), newStripe);
			}
			this.moveAgent = new PeriodicalExecuter(this.mover,1/this.fps);
		}
	},


	start: function(event) {
		//alert('Start');
		var myDiv;// = Event.findElement(event, 'div');
		myDiv = $('Box');
		if (Element.classNames(myDiv) != 'Box') return;
		this.moveAgent = new PeriodicalExecuter(this.mover,1/this.fps);
		this.status = 'play';
		Event.stop(event);
	},
	freeze: function(event) {
		//alert('Freez');
		var myDiv;// = Event.findElement(event, 'div');
		myDiv = $('Box');
		//if((Element.childOf($(myDiv),$('Box'))) || (Element.classNames(myDiv)=='Box')) {
		if (Element.classNames(myDiv)=='Box'){
			this.moveAgent.stop();
			this.status = 'stop';
			Event.stop(event);
			
		}else{
			this.moveAgent = new PeriodicalExecuter(this.mover,1/this.fps);
			this.status = 'play';
			Event.stop(event);
		}
	},
	mover: function() {
	//	!!! var offset = Move.pps / Move.fps; //va modificatoper unbinding corretto dobbiamo riferirci a this o riuscire a passare di parametri!!
		//alert(Move.stripeWidth);
		
		Move.x += Move.pps / Move.fps;
		if ( Move.x >= Move.stripeWidth*2 ) {
			Move.x -= Move.stripeWidth;
			//alert('reset1');
		}
		if ( Move.x <= -Move.stripeWidth ) {
			Move.x += Move.stripeWidth;
			//alert('reset2');
		}

		//var newPos = Math.floor(Move.x - (Move.stripeWidth)) + 'px'
		var newPos = Math.floor(Move.x) + 'px'
		
		Element.setStyle($('stripBox'),{
			left: newPos 
		});
		
		//display(newPos);
	},
	open: function(event) {
		var elt = Event.findElement(event,'img');
		var newX, newY
		newX = 456
		
		var msg = "Node Type; "+$(elt).src;
		//alert("Width:"+Element.getDimensions($(elt)).width + ' ---- Height:'+Element.getDimensions($(elt)).height);
		
		newY = (Element.getDimensions($(elt)).height * newX) / Element.getDimensions($(elt)).width
	
		msg += '\nNew X: '+ newX + ' --- New Y: ' + newY;

		var myArr = $(elt).src.split('/');
		myArr[myArr.length-2] = '456_x';
		
		var imgTag = ""
		for (var i=0;i<myArr.length-1;i++) 
			imgTag += myArr[i] + '/';
		imgTag += myArr[myArr.length-1];
		
		//displayImgBig('<img src="'+imgTag +'">');
		
		newX = newX + 20
		newY = newY + 28
		
		
		window.open(imgTag,'InGardaPopup','width='+newX+',height='+newY+',toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no');

		this.moveAgent.stop();
		this.status = 'stop';
		Event.stop(event)
		/*
		this.moveAgent = new PeriodicalExecuter(this.mover,1/this.fps);
		this.status = 'play';
		Event.stop(event);
		*/

	}
}//Move

Event.observe(window, 'load', pageLoaded);






