//LINK MOUSEOVER FUNCTIONS BEGIN
function linkMouseover(){
	$$('#headermenu a').addEvents({
				mouseenter: function(){
				// We set the cursor to pointer so users know they can click this region
				this.setStyle('cursor','pointer');
	 
				// Change text color on mouseover
				this.set('morph', {duration: 200});
				this.morph({
					'color': '#FFFFFF'
					
				});
			},
			mouseleave: function(){
				// Morphes back to the original style
				this.set('morph', {duration: 500});
				this.morph({
					'color': '#000000'
					
				});
			}
	});
}//LINK MOUSEOVER FUNCTIONS END


//IMAGE GALLERY 
function imageGallery(imageRoot) {
		
		
		// CHANGE THIS !!
		var slides = 2;		// NUMBER OF SLIDES IN SLIDESHOW, CHANGE ACCORDINGLY
		
		var pos = 0;
		var offset = 600;	// HOW MUCH TO SLIDE WITH EACH CLICK
		var currentslide = 1;	// CURRENT SLIDE IS THE FIRST SLIDE
		var inspector = $('fullimg');	// WHERE THE LARGE IMAGES WILL BE PLACE	
		var fx = new Fx.Morph(inspector, {duration: 300, transition: Fx.Transitions.Sine.easeOut});
 		var fx2 = new Fx.Morph(inspector, {duration: 200, transition: Fx.Transitions.Sine.easeOut});

		
		/* THUMBNAIL IMAGE SCROLL */
		var imgscroll = new Fx.Scroll('wrapper', {
   			offset: {'x': 0, 'y': 0},
			duration: 1000,
   			transition: Fx.Transitions.Cubic.easeOut	// HOW THE SCROLLER SCROLLS
		}).toLeft();

	
		/* EVENTS - WHEN AN ARROW IS CLICKED THE THUMBNAILS SCROLL */
		$('moveleft').addEvent('click', function(event) { event = new Event(event).stop();
			if(currentslide == 1) return;
			currentslide--;					// CURRENT SLIDE IS ONE LESS
			pos += -(offset);				// CHANGE SCROLL POSITION
			imgscroll.start(pos);			// SCROLL TO NEW POSITION
		});
		$('moveright').addEvent('click', function(event) { event = new Event(event).stop();
			if(currentslide >= slides) return;
			currentslide++;
			pos += offset;
			imgscroll.start(pos);
		});
		
		/* WHEN AN ITEM IS CLICKED, IT INSERTS THE IMAGE INTO THE FULL VIEW DIV */
		$$('.item').each(function(item){ 
			item.addEvent('click', function(e) { 
				e = new Event(e).stop();
				fx2.start({ 
					'opacity' : 0													
				}).chain(function(){
					
					inspector.empty();		// Empty Stage
					var loadimg = 'http://www.alithiaspurizampetti.com/images/ajax-loader.gif';	   // Reference to load gif
					var load = new Element('img', { 'src': loadimg, 'class': 'loading' }).inject(inspector); 
					fx2.start({ 'opacity' : 1 });
					var largeImage = new Element('img', { 'src': item.href }); // create large image
					
					/* When the large image is loaded, fade out, fade in with new image */
					//largeImage.onload = function(){  // While this line of code causes the images to load/transition in smoothly, it cause IE to stop working
						fx.start({ 
							'opacity' : 0													
						}).chain(function(){
							inspector.empty();	           				// empty stage
							var description = item.getElement('span');	// see if there is a description
							
							if(description)					   
								var des = new Element('p').set('text', description.get('text')).inject(inspector);
									
							largeImage.inject(inspector); // insert new image
							fx.start({'opacity': 1});	 // then bring opacity of elements back to visible				
						});
					//};
					
				});
			});
		});

		// INSERT THE INITAL IMAGE - LIKE ABOVE
		inspector.empty();
		var description = $('first').getElement('span');
		if(description) var desc = new Element('p').setHTML(description.get('html')).inject(inspector);
		var largeImage = new Element('img', {'src': $('first').href}).inject(inspector);
	
}


//SIDE IMAGE FADE BEGINS
function sideImage(src,altText) {
	
	var sideImage = new Asset.image(src, {alt: altText,id:'leftimage', style:'width:315px;height:500px;position:absolute;left:-100px;visibility:hidden;', onload: slideFunction});
		
	function slideFunction(){
		
		sideImage.inject('header');
		
		var sideImageFx = new Fx.Morph('leftimage', {
		duration: 3000
		});
		sideImageFx.start({
			'opacity':[0,1],
			'left':[-100,0]	
		});
	}
	
		
}
//SIDE IMAGE FADE ENDS	




//IMAGE GALLERY SLIDE IN BEGINS

function gallerySlideIn(){

	var x = new Chain();
	var one = function(){
	
		var contentsFx = new Fx.Morph($('img_gallery'), {
		duration: 1000,
		transition: 'sine:out'
		});
		contentsFx.start({
		'left':[-600,0],
		'opacity':[0,1]
		});
	
	};
	var two = function(){
	
		var sideFx = new Fx.Morph($('textcontent'), {
		duration: 1000,
		transition: 'sine:out'
		});
		sideFx.start({
		'left':[315,0],
		'width':[0,315],
		'opacity':[0,1]
		});
	
	};
	var three = function(){
	
		var imgFx = new Fx.Morph($('fullimg'), {
		duration: 1000,
		transition: 'sine:out'
		});
		imgFx.start({
		'opacity':[0,1],
		'width':[0,600]
		});
	
	};
	var four = function(){
	
		var imgFx = new Fx.Morph($('wrapper'), {
		duration: 1000,
		transition: 'sine:out'
		});
		imgFx.start({
		'opacity':[0,1]
		});
	
	};
	x.chain(one);
	x.chain(two);
	x.chain(three);
	x.chain(four);
	x.callChain(); /*alert '1'*/
	x.callChain.delay(500, x); /*wait, alert '2'*/
	x.callChain.delay(1000, x); /*wait, alert '3'*/
	x.callChain.delay(100, x); /*wait, alert '4'*/

}
//IMAGE GALLERY SLIDE IN END



//PRESS SLIDE IN BEGINS

function pressSlideIn(){

	var x = new Chain();
	var one = function(){
	
		var contentsFx = new Fx.Morph($('pressContainer'), {
		duration: 1000,
		transition: 'sine:out'
		});
		contentsFx.start({
		'left':[-600,0],
		'opacity':[0,1]
		});
	
	};
	var two = function(){
	
		var sideFx = new Fx.Morph($('textcontent'), {
		duration: 1000,
		transition: 'sine:out'
		});
		sideFx.start({
		'left':[315,0],
		'width':[0,315],
		'opacity':[0,1]
		});
	
	};
	var three = function(){
	
		var imgFx = new Fx.Morph($('pressImage'), {
		duration: 1000,
		transition: 'sine:out'
		});
		imgFx.start({
		'opacity':[0,1],
		'height':[0,450]
		});
	
	};
	
	x.chain(one);
	x.chain(two);
	x.chain(three);
	x.callChain(); /*alert '1'*/
	x.callChain.delay(500, x); /*wait, alert '2'*/
	x.callChain.delay(1000, x); /*wait, alert '3'*/

}
//PRESS SLIDE IN END



//PRESS SELECTOR
function pressSelector(pressDir){
	
	pressSelector.aName = '';
		
	$$('#textcontent li').addEvents({
								   
				click: function(){
				// We set the cursor to pointer so users know they can click this region
				this.getChildren('a').setStyle('cursor','pointer');
				this.setStyle('background-color','#888888');	
				
				pressSelector.aName = this.getChildren('a').getProperty('name');
				
					//image	changer					
					var pressImage = new Asset.image(pressDir + pressSelector.aName + '.jpg', {alt: pressSelector.aName, onload: pressChange});							
				
					//setup effects
					var x = new Chain();				
										
						var fadeAway = function() { 
								var fadeAway2 = new Fx.Morph($('pressImageWrapper'), {
								duration: 200,
								transition: 'sine:out'
								});

								fadeAway2.start({
								'opacity':[1,0]
								});	
							};
																
						var switchImages = function(){					
								$('pressImageWrapper').empty();							
								pressImage.inject('pressImageWrapper');
							};
						
						var fadeBack = function(){ 
								var fadeBack2 =new Fx.Morph($('pressImageWrapper'), {
								duration: 200,
								transition: 'sine:out'
								});
								fadeBack2.start({
								'opacity':[0,1]
								});
							};
					
					
					function pressChange(){
					
					x.chain(fadeAway);
					x.chain(switchImages);
					x.chain(fadeBack);
					x.callChain(); /*alert '1'*/
					x.callChain.delay(200, x); /*wait, alert '2'*/
					x.callChain.delay(200, x); /*wait, alert '3'*/
					
					}
					
																	
				},
				
				mouseleave: function(){
				this.setStyle('background-color',null);	
				}
			
	});
}//PRESS SELECTOR END

