// Javascript slideshow
//Written by MicroCreations
//Portions modified from Reef Central


		var timer; 
		var current_location = 1;
		var next_location = 1; 
		var pics_loaded = 0;
		var timeout_value;
		var images = new Array;
		var photo_urls = new Array;
		var photo_width = new Array;
		var photo_height = new Array;
		var preloadimgs = new Array;
				
		photo_height[1] =  "362";
		photo_width[1] =  "900";
		photo_urls[1] =  "images/slideshow/slide1.jpg";
		
		photo_height[2] =  "362";
		photo_width[2] =  "900";
		photo_urls[2] =  "images/slideshow/slide2.jpg";
		
		photo_height[3] =  "362";
		photo_width[3] =  "900";
		photo_urls[3] =  "images/slideshow/slide3.jpg";
		
		photo_height[4] =  "362";
		photo_width[4] =  "900";
		photo_urls[4] =  "images/slideshow/slide4.jpg";
		
		photo_height[5] =  "362";
		photo_width[5] =  "900";
		photo_urls[5] =  "images/slideshow/slide5.jpg";
		
		photo_height[6] =  "362";
		photo_width[6] =  "900";
		photo_urls[6] =  "images/slideshow/slide6.jpg";
		
		photo_height[7] =  "362";
		photo_width[7] =  "900";
		photo_urls[7] =  "images/slideshow/slide7.jpg";
		
		photo_height[8] =  "362";
		photo_width[8] =  "900";
		photo_urls[8] =  "images/slideshow/slide8.jpg";
		
		photo_height[9] =  "362";
		photo_width[9] =  "900";
		photo_urls[9] =  "images/slideshow/slide9.jpg";
		
		photo_height[10] =  "362";
		photo_width[10] =  "900";
		photo_urls[10] =  "images/slideshow/slide10.jpg";
		
		photo_height[11] =  "362";
		photo_width[11] =  "900";
		photo_urls[11] =  "images/slideshow/slide11.jpg";
		
		photo_height[12] =  "362";
		photo_width[12] =  "900";
		photo_urls[12] =  "images/slideshow/slide12.jpg";
		
		photo_height[13] =  "362";
		photo_width[13] =  "900";
		photo_urls[13] =  "images/slideshow/slide13.jpg";
		
		photo_height[14] =  "362";
		photo_width[14] =  "900";
		photo_urls[14] =  "images/slideshow/slide14.jpg";
		
		photo_height[15] =  "362";
		photo_width[15] =  "900";
		photo_urls[15] =  "images/slideshow/slide15.jpg";
		
		photo_height[16] =  "362";
		photo_width[16] =  "900";
		photo_urls[16] =  "images/slideshow/slide16.jpg";
		
		photo_height[17] =  "362";
		photo_width[17] =  "900";
		photo_urls[17] =  "images/slideshow/slide17.jpg";
		
		photo_height[18] =  "362";
		photo_width[18] =  "900";
		photo_urls[18] =  "images/slideshow/slide18.jpg";
		
		photo_height[19] =  "362";
		photo_width[19] =  "900";
		photo_urls[19] =  "images/slideshow/slide19.jpg";
		
		photo_height[20] =  "362";
		photo_width[20] =  "900";
		photo_urls[20] =  "images/slideshow/slide20.jpg";
		
		photo_height[21] =  "362";
		photo_width[21] =  "900";
		photo_urls[21] =  "images/slideshow/slide21.jpg";
		
		photo_height[22] =  "362";
		photo_width[22] =  "900";
		photo_urls[22] =  "images/slideshow/slide22.jpg";
		
		photo_height[23] =  "362";
		photo_width[23] =  "900";
		photo_urls[23] =  "images/slideshow/slide23.jpg";
		
		photo_height[24] =  "362";
		photo_width[24] =  "900";
		photo_urls[24] =  "images/slideshow/slide24.jpg";
		
		photo_height[25] =  "362";
		photo_width[25] =  "900";
		photo_urls[25] =  "images/slideshow/slide25.jpg";
		
		photo_height[26] =  "362";
		photo_width[26] =  "900";
		photo_urls[26] =  "images/slideshow/slide26.jpg";
		
		photo_height[27] =  "362";
		photo_width[27] =  "900";
		photo_urls[27] =  "images/slideshow/slide27.jpg";
		
		photo_height[28] =  "362";
		photo_width[28] =  "900";
		photo_urls[28] =  "images/slideshow/slide28.jpg";
		
		photo_height[29] =  "362";
		photo_width[29] =  "900";
		photo_urls[29] =  "images/slideshow/slide29.jpg";
		
		photo_height[30] =  "362";
		photo_width[30] =  "900";
		photo_urls[30] =  "images/slideshow/slide30.jpg";
		
		photo_height[31] =  "362";
		photo_width[31] =  "900";
		photo_urls[31] =  "images/slideshow/slide31.jpg";
		
		photo_height[32] =  "362";
		photo_width[32] =  "900";
		photo_urls[32] =  "images/slideshow/slide32.jpg";
		
		photo_height[33] =  "362";
		photo_width[33] =  "900";
		photo_urls[33] =  "images/slideshow/slide33.jpg";
		
		photo_height[34] =  "362";
		photo_width[34] =  "900";
		photo_urls[34] =  "images/slideshow/slide34.jpg";
		
		photo_height[35] =  "362";
		photo_width[35] =  "900";
		photo_urls[35] =  "images/slideshow/slide35.jpg";
		
		photo_height[36] =  "362";
		photo_width[36] =  "900";
		photo_urls[36] =  "images/slideshow/slide36.jpg";
		
		photo_height[37] =  "362";
		photo_width[37] =  "900";
		photo_urls[37] =  "images/slideshow/slide37.jpg";

		
		photo_count=37;
		
		
		function start(){
			//Pause while pre-load
			onoff = 1;
			pauserun();
			//Preload
			imageObj = new Image();
			for (x in photo_urls)
			{
				imageObj.src = photo_urls[x];
			} 
			
			pauserun();
			play();
		}
		
		function play() {
			current_location = 1;
			onoff = 1;
			go_to_next_photo();

		}
		
		
		
		function preload_complete() {
		}
		
		function reset_timer() {
			clearTimeout(timer);
			  timer = setTimeout('go_to_next_photo()', 3500);
		}
		
		function wait_for_current_photo() {
		
			preload_next_photo();
			reset_timer();
		
		}
		
		function go_to_next_photo() {
			if (onoff == 1){
				/* Go to the next location */
				current_location = next_location;
				/* Show the current photo */
				if (!show_current_photo()) {
				wait_for_current_photo();
				return 0;
				}
			
				preload_next_photo();
			}	
			reset_timer();
			
		}
		
		function preload_next_photo() {
			
			/* Calculate the new next location */
			next_location = (parseInt(current_location) + 1);
			if (next_location > photo_count) {
			next_location = 1;
			}
			if (next_location == 0) {
				next_location = photo_count;
			}
			
		}
		
		function show_current_photo() {
		
			blendimage("backimage", "blendimage", photo_urls[current_location], photo_width[current_location], photo_height[current_location], 400)
		
		  return 1;
		}
		
		function previmg() {
			/* Calculate the new previous location */
			prev_location = (parseInt(current_location) - 1);
			if (prev_location <= 0) {
				prev_location = photo_count;
			}
			
			/* Calculate the new next location */
			next_location = (parseInt(prev_location) + 1);
			if (next_location > photo_count) {
			next_location = 1;
			}
			if (next_location == 0) {
				next_location = photo_count;
			}
			
			current_location = prev_location;
			/* Show the current photo */
			if (!show_current_photo()) {
			wait_for_current_photo();
			return 0;
			}
		
			preload_next_photo();	
			reset_timer();
			
			
		}
		
		function nextimg() {
			/* Go to the next location */
			current_location = next_location;
			/* Show the current photo */
			if (!show_current_photo()) {
			wait_for_current_photo();
			return 0;
			}
		
			preload_next_photo();	
			reset_timer();
		}
		
		function pauserun() {		
			if(onoff==1){
				onoff=0;
				document.getElementById('playpause').src="images/play.gif";
			}
			else
			{
				onoff=1;
				document.getElementById('playpause').src="images/pause.gif";
			}
			
			
			
		}
		
		function blendimage(backid, imageid, imagefile, picwidth, picheight, millisec) { 
			var speed = Math.round(millisec / 100); 
			var timer2 = 0; 
			 
			//set the current image as background 
			//alert(document.getElementById(imageid).style.top);
			changeOpac(50, backid)
			document.getElementById(backid).style.position = "absolute";
			
			
			//document.getElementById(backid).style.top =findPosY(document.getElementById(imageid)) + 'px';
			//document.getElementById(backid).style.left = findPosX(document.getElementById(imageid)) + 'px';
			
			document.getElementById(backid).style.top = document.getElementById(imageid).offsetTop + 'px';
			document.getElementById(backid).style.left = document.getElementById(imageid).offsetLeft  + 'px';
			document.getElementById(backid).style.width = document.getElementById(imageid).offsetWidth + 'px';
			document.getElementById(backid).style.height = document.getElementById(imageid).offsetHeight + 'px';
			document.getElementById(backid).src = document.getElementById(imageid).src; 
			 
			//make image transparent 
			changeOpac(0, imageid); 
			 
			//make new image 
 			document.getElementById(imageid).src = imagefile; 
		   
		   
		   //Change to redraw div instead of replace img src because img.complete doesn't work
			changeimg2(imageid, imagefile, picwidth, picheight);
		
			document.getElementById(imageid).width = picwidth;
			document.getElementById(imageid).height = picheight;
			
			//fade in image 
			for(i = 0; i <= 99; i++) { 
				setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer2 * speed)); 
				setTimeout("changeOpac(" + (50- (i/2)) + ",'" + backid + "')",(timer2 * speed)); 
				timer2++; 	
				
			} 
		} 
		
		
		
		function changeimg2(imageid, imagefile, picwidth, picheight)
		{
			var objCellvar = document.getElementById("blenddiv");
			objCellvar.innerHTML = "<table height='362px' width='900px'>" +
			  "<tr> " + 
				"<td align='center' valign='center'> <img src='" +imagefile + "' height='" + picheight + "' style='border: 0 none; filter: alpha(opacity=0); -moz-opacity: 0; opacity: 0;' id='blendimage' alt='' />" +
				"</td> " +
			  "</tr> " +
			"</table>";
			objCellvar.style.display = "block";
			
		}
		
		
		//change the opacity for different browsers 
		function changeOpac(opacity, id) { 
			  var object = document.getElementById(id).style; 
			  object.opacity = (opacity / 100); 
			  object.MozOpacity = (opacity / 100); 
			  object.KhtmlOpacity = (opacity / 100); 
			  object.filter = "alpha(opacity=" + opacity + ")"; 
		}
		
		function findPosX(obj)
		  {
			var curleft = 0;
			if(obj.offsetParent)
				while(1) 
				{
				  curleft += obj.offsetLeft;
				  if(!obj.offsetParent)
					break;
				  obj = obj.offsetParent;
				}
			else if(obj.x)
				curleft += obj.x;
			return curleft;
		  }
		
		  function findPosY(obj)
		  {
			var curtop = 0;
			if(obj.offsetParent)
				while(1)
				{
				  curtop += obj.offsetTop;
				  if(!obj.offsetParent)
					break;
				  obj = obj.offsetParent;
				}
			else if(obj.y)
				curtop += obj.y;
			return curtop;
		  }
		  
		  
		  document.write('</SCRIPT>' +
		  '<div style="width:900px; height:362px; padding-top:0px; vertical-align:middle; text-align:center; position:relative;">	 ' +
			'<center>  ' +
			'<div style="height: 362px; width:900px; padding-top:0px; overflow:hidden; position:relative; z-index:1" id="blenddiv"> ' +
			'<table height="362px" width="900px">' +
			 ' <tr> ' +
				'<td align="center" valign="center"> ' +
				'<img src="' + photo_urls[1] + '" height="' + photo_height[1] + '" style="border: 0 none; filter: alpha(opacity=0); -moz-opacity: 0; opacity: 0;" id="blendimage" alt="" /> ' +
				'</td>' +
			  '</tr>' +
			'</table>' +
			'</div>' +
			'<img src="images/spacer.gif" height="362" style="border: 0 none; position:absolute" id="backimage" alt="" /> ' +
			'</center>' +
		  '</div>');
		  
		  //Controls for the slideshow
		   document.write('<div style=" left:380px; width:150px; height:25px; padding-top:3px; vertical-align:left; text-align:left; position:relative;">	 ' +
					'<a href="javascript:previmg()"><img src="images/leftarrow.gif" border="0" alt="previous" /></a> <img src="images/selectspacer.gif" />  <a href="javascript:nextimg()"><img src="images/rightarrow.gif" border="0" alt="next" /></a> <img src="images/selectspacer.gif" />  <a href="javascript:pauserun()"><img src="images/pause.gif" border="0" name="palypause" id="playpause" /></a> ' +
		  		'</div>');
		  
			start();
			 
			createcssmenu2(); 
			
		  
