/*
 * JavaScript functions for Denver Gem Cutting Co.
 * 
 * Rick B - 2011/07/05
 * http://www.datapathways.com
 */

		// SLIDE SHOW SECTION
		// --------------------------------------------------------------------------------

		// name each small image file "image" followed by the number indicating order of display
		// name each small image caption file "captionN.txt" where N corresponds to the slide number
		// name each large image file "imagelg" followed by the number indicating order of display
		// name each large image caption file "captionlgN.txt" where N corresponds to the slide number
		// name each URL file (page loaded in main window) pageN.txt where N corresponds to the slide number
		// ex: image7.png
		//     caption7.txt
		//     imagelg7.png
		//     captionlg7.txt
		//     page7.txt
		// the element displaying the slide show must be a <div>

		var element_id = "imgDiv";       // set this string to the id attribute of the slide show <div>
		var num_slides = 8;              // set this value to number of slides
		var image_path = "/slide.show/"; // set this string to image path
		var image_type = ".png";         // set this string to image file extension
		var secs_delay = 2;              // set this value to display time for each image

		// DO NOT EDIT JavaScript BELOW THIS POINT!
		// --------------------------------------------------------------------------------


		// --------------------------------------------------------------------------------
		// Slide Show Section
		// --------------------------------------------------------------------------------
		var imgAry = new Array(num_slides);
		var strCapAry = new Array(num_slides);
		var lgImgAry = new Array(num_slides);
		var strLgCapAry = new Array(num_slides);
		var strPgAry = new Array(num_slides);

		var img_idx = "0";
		var lgImg = new Image();
		var page_cap = "";
		var page_name = "/index.php";

		function loadImages()
		{
			var idx;

			for(idx = 0; idx < num_slides; idx++)
			{
				imgAry[idx] = new Image();
				imgAry[idx].src = image_path+"image"+(idx+1)+image_type;

				var oRequest = new XMLHttpRequest();
				oRequest.open( "GET", image_path+"caption"+(idx+1)+".txt", false );
				oRequest.send();
				strCapAry[idx] = new String();
				strCapAry[idx] = oRequest.responseText;

				lgImgAry[idx] = new Image();
				lgImgAry[idx].src = image_path+"imagelg"+(idx+1)+image_type;
				
				var oRequest2 = new XMLHttpRequest();
				oRequest2.open( "GET", image_path+"captionlg"+(idx+1)+".txt", false );
				oRequest2.send();
				strLgCapAry[idx] = new String();
				strLgCapAry[idx] = oRequest2.responseText;
				
				var oRequest3 = new XMLHttpRequest();
				oRequest3.open( "GET", image_path+"page"+(idx+1)+".txt", false );
				oRequest3.send();
				strPgAry[idx] = new String();
				strPgAry[idx] = oRequest3.responseText;
			}

			img_idx = randomFromTo(0, num_slides-1);

			document.getElementById("imgDiv").style.backgroundImage = "url(\'"+imgAry[img_idx].src+"\')";
			document.getElementById("imgCaption").innerHTML = strCapAry[img_idx];
			lgImg.src = lgImgAry[img_idx].src;
			page_cap  = strLgCapAry[img_idx];
			page_name = strPgAry[img_idx];
			img_idx++;
			if(img_idx > num_slides-1) 
				img_idx = 0;
			setInterval("slideShow();", 1000*secs_delay);
		}

		function slideShow()
		{
			document.getElementById("imgDiv").style.backgroundImage = "url(\'"+imgAry[img_idx].src+"\')";
			document.getElementById("imgCaption").innerHTML = strCapAry[img_idx];
			lgImg.src = lgImgAry[img_idx].src;
			page_cap  = strLgCapAry[img_idx];
			page_name = strPgAry[img_idx];
			img_idx++;
			if(img_idx > num_slides-1) 
				img_idx = 0;
		}

		function randomFromTo(from, to)
		{
       			return Math.floor(Math.random() * (to - from + 1) + from);
		}

		function openLargeImage()
		{
			var strURL = "/slide.show/large_image.php";
			strURL += "?img="+lgImg.src;
			strURL += "&cap="+page_cap;
			strURL += "&url="+page_name;

			var strSpecs = "directories=no, fullscreen=no, location=no, menubar=no,";
			strSpecs += "resizable=no, scrollbars=no, status=no, titlebar=no, toolbar=no,";
			strSpecs += "left=200, top=150, width=620, height=570";

			window.open(strURL, "_blank", strSpecs);
		}


		// --------------------------------------------------------------------------------
		// MouseOver Section
		// --------------------------------------------------------------------------------
		// Added optional text argument for a caption - no effect on existing calls
		// Rick B 12/17/2011
		function openMouseOverImage(imgsrc, width, height, event, text)
		{
			var x = event.clientX - (width/2);
			var y = event.clientY; //- (height/2);

			var oImg = new Image();
			oImg.src = imgsrc;

			var strURL = "/mouseover_image.php";
			strURL += "?img="+oImg.src;
			strURL += "&width="+width;
			strURL += "&height="+height;

			// When the optional text argument is passed,
			// set variables allowing for caption
			if(!(!text)) 
			{
				strURL += "&text="+text;
				height += 22; // more vertical height in new window
			}

			var strSpecs = "directories=no, fullscreen=no, location=no, menubar=no,";
			strSpecs += "resizable=no, scrollbars=no, status=no, titlebar=no, toolbar=no,";
			strSpecs += "left="+x+", top="+y+", width="+(width+20)+", height="+(height+20);

			window.open(strURL, "_blank", strSpecs);
		}


		// --------------------------------------------------------------------------------
		// Place <span id="foobarN"></span> where N = 1-5 in main PHP file
		// NOTE: <span id="foobar"></span> is found in footer.php
		// --------------------------------------------------------------------------------
		function noBots()
		{
			var stuff = "<img src=\"/images/footer.jpg\"/>";
			var stuff2 = "Email us";
			var foo = "denton";
			var bar = "gemcutting.com";
			var i = 0;

			document.getElementById("foobar").innerHTML = 			
				"<a href=" + "mail" + "to:" + foo + "@" + bar + ">" + stuff + "</a>";

			for(i = 1; i <= 5; i++)
				if(document.getElementById("foobar"+i))
					document.getElementById("foobar"+i).innerHTML = 
						"<a href=" + "mail" + "to:" + foo + "@" + bar + ">" + stuff2 + "</a>";
		}

		//window.onload = loadImages(); // MOVED to <body onload> so getElementById() has code to read


