  //Brokenice Interactive copyright

	//Variables 
  	var car, car1, car3, a1, a2, a3,p3,p2,p1,p4,p5,p6,p7,p8,pd,active,t;
  	//Document load
    Event.observe(window, "load", function() {
  
  			//Initialize carousel
		car = new IcyCarousel('carousel', {altezzaCar : 670, larghezzaCar: 420, autoStart: false, controlSx : 'prevCar2', controlDx : 'nextCar2'});
		car1 = new IcyCarousel('carousel1', {altezzaCar : 670, larghezzaCar: 420, autoStart: false, controlSx : 'prevCar1', controlDx : 'nextCar1'});	
		car3 = new IcyCarousel('carousel2', {altezzaCar : 670, larghezzaCar: 420, autoStart: false, controlSx : 'prevCar3', controlDx : 'nextCar3'});	
		
		dp.SyntaxHighlighter.ClipboardSwf = 'syntax/clipboard.swf';
		dp.SyntaxHighlighter.HighlightAll('code');
		//Initialize effeccts for timeline
		a1 = $('men1').animate({top : -20},500,{play:false, transition: Transition.easeOutBounce});
		a2 = $('men2').animate({top : -10},500,{play:false, transition: Transition.easeOutBounce});
		a3 = $('men3').animate({top : -10},500,{play:false, transition: Transition.easeOutBounce,
			//Register events
			onEnded : function(){
				Event.observe($('get'), "click", function(){
					if(active == null){
						$('testomen3').setOpacity(0);
						$('testomen3').show();
						$('get').hide();
						p3 = $('men3').animate({left : 300, width:670},500,{transition: Transition.easeOutBounce, play:false});
						p8 = $('terzofoglio').animate({width : 638, height: 987},500,{play:false});
						p6 = $('testomen3').animate({opacity:1},500,{play:false, onEnded : function(){
							$('prevCar3').show();
							$('nextCar3').show();
							$('close').show();
						}});
						active = p3;
						t.add(p3, 0);
						t.add(p4, 0);
						t.add(p8, 0, {after : p4});
						t.add(p6, 0, {after : p8});
						t.run();
						a1.rewind();
						a2.rewind();
					}
				});
				Event.observe($('about'), "click", function(){
					if(active == null){
						$('testomen1').setOpacity(0);
						$('testomen1').show();
						p1 = $('men1').animate({left : 300, width:670},500,{transition: Transition.easeOutBounce, play:false});
						$('about').hide();
						p7 = $('primofoglio').animate({width : 638, height: 987},500,{play:false});
						p6 = $('testomen1').animate({opacity:1},500,{play:false, onEnded : function(){
							$('prevCar1').show();
							$('nextCar1').show();
							$('close').show();
						}});
						active = p1;
						t.add(p1, 0);
						t.add(p4, 0);
						t.add(p7, 0, {after : p4});
						t.add(p6, 0, {after : p7});
						t.run();
						a2.rewind();
						a3.rewind();
					}
				});
				Event.observe($('documents'), "click", function(){
					if(active == null){
						$('testomen2').setOpacity(0);
						$('testomen2').show();
						$('documents').hide();
						p2 = $('men2').animate({left : 300, width:670},500,{transition: Transition.easeOutBounce, play:false});
						p5 = $('secondofoglio').animate({width : 638, height: 987},500,{play:false});
						p6 = $('testomen2').animate({opacity:1},500,{play:false, onEnded : function(){
							$('prevCar2').show();
							$('nextCar2').show();
							$('close').show();
						}});
						active = p2;
						t.add(p2, 0);
						t.add(p4, 0);
						t.add(p5, 0, {after : p4});
						t.add(p6, 0, {after : p5});
						t.run();
						a1.rewind();
						a3.rewind();
					}
				});
			}
			
		});
		
		p4 = $('close').animate({opacity : 1},500,{play:false,
			onEnded : function(){
				Event.stopObserving($('primofoglio'), "click");
				Event.stopObserving($('secondofoglio'), "click");
				Event.stopObserving($('terzofoglio'), "click");
			}
		});
		
		Event.observe($('close'), "click", function(){
			//Rewind timeline
			t.rewind();
			//Remove unused effects
			t.remove(p1);
			t.remove(p2);
			t.remove(p3);
			t.remove(p4);
			//Hide components
			$('testomen1').hide();
			$('testomen2').hide();
			$('testomen3').hide();
			$('prevCar1').hide();
			$('nextCar1').hide();
			$('prevCar2').hide();
			$('nextCar2').hide();
			$('prevCar3').hide();
			$('nextCar3').hide();
			$('close').hide();
			active = null;
			$('about').show();
			$('get').show();
			$('documents').show();
			//Run the timeline
			t.run();
		});
		
		//Create timeline and add effects
		t = new TimeLine();
		t.add(a1, 0);
		t.add(a2, 0, {after: a1});
		t.add(a3, 0, {after: a2});
		//Run the timeline
		t.run();
    });

