
if($('cpGallery')){
	
	
	var delay = cpGalleryDelay;
	
	var c=1000;
	var i=0;
	var showStart = false;
	var l=0;
	var firstImg ='';
	
		
	var first = 0;
	$$('.slide img').each(function(e) {
	
		if( first++ == 0)	
			firstImg = $(e).src;
			
		$(e).setOpacity(0.0);
	});
	
	
	var order = [];
	var tnum = 0;
	$$('.slide').each(function(e) { 
		order[tnum] = tnum;
		tnum++;
	});
	order.sort(randOrd);
	
	
	$$('.slide').each(function(e) {
	
		e.id = "cpGallery_" + order[i];
		e.setStyle({ zIndex: 0, position: 'absolute', top: '0px', left: '0px', display: 'none', overflow: 'hidden'});
					
		i++;
				
	});
	

	loadCheck = new Image();
	loadCheck.src = firstImg;
	//loadCheck.onload = cpSlideShowFailSafe;

//window.observe('load', cpSlideShowFailSafe);
window.onload= cpSlideShowFailSafe;

}	

	function cpSlideShowFailSafe(){
	
		if(showStart == false){
			showStart = true;
			
			$$('.slide img').each(function(e) {
					$(e).setOpacity(1.0);
			});

			cpSlideShow();
		}
	}

	function cpSlideShow(){
		if(l >= (i)) l=0;
		$("cpGallery_" + l).setStyle({ zIndex: c++, display: 'none', overflow: 'hidden'});
		new Effect.Appear("cpGallery_" + l, { duration: 1.0 });
		
		
		
		var z = 1;
		$("cpGallery_" + l + "").childElements().each(function(e) {
			
			
			if(e.hasClassName('slide-in-left')){
				
				e.setStyle({ zIndex: z, position: 'absolute', top: '0px', left: '-500px', display: 'block', overflow: 'hidden'});
				new Effect.Move(e, { x: 500, y: 0, mode: 'relative', duration: 2.0, delay: 0.5});

			}
			if(e.hasClassName('slide-out-left')){
				
				var d = (delay/1000) - 2;
				e.setStyle({ zIndex: z, position: 'absolute', top: '0px', left: '0px', display: 'block'});
				new Effect.Move(e, { x: -500, y: 0, mode: 'relative', duration: 2.0, delay: d });

			}
			
			if(e.hasClassName('slide-in-right')){
				
				e.setStyle({ zIndex: z, position: 'absolute', top: '0px', left: '500px', display: 'block', overflow: 'hidden'});
				new Effect.Move(e, { x: -500, y: 0, mode: 'relative', duration: 2.0, delay: 0.5});

			}
			if(e.hasClassName('slide-out-right')){
				
				var d = (delay/1000) - 2;
				e.setStyle({ zIndex: z, position: 'absolute', top: '0px', left: '0px', display: 'block'});
				new Effect.Move(e, { x: 500, y: 0, mode: 'relative', duration: 2.0, delay: d });

			}
			
			if(e.hasClassName('slide-overlay')){
				
				e.setStyle({ zIndex: z, position: 'absolute', top: '0px', left: '0px', display: 'block'});

			}
			
			z++;
		});
		l++;
		
		setTimeout("cpSlideShow()", delay);	
	}
	
	
	function randOrd(){
		return (Math.round(Math.random())-0.5);
	} 

