/* Content copyright David B. Zwiefelhofer. All rights reserved. */
	var scrolling = 0;
	var spic_no = 0;
	var del_secs = 0.1;
	
	function findPos(obj) {
		var curleft = curtop = 0;
		if (obj.offsetParent) {
			do {
				curleft += obj.offsetLeft;
				curtop += obj.offsetTop;
			} while (obj = obj.offsetParent);
		}
		return [curleft,curtop];
	}

	document.onmousemove = mouseXandY;
	// Global variables
	xMousePos = 0; // Horizontal position of the mouse on the screen
	yMousePos = 0; // Vertical position of the mouse on the screen
	
	function mouseXandY(e) { // by Kravvitz of DynamicSiteSolutions.com
	  var x=0,y=0;
	  e=e||window.event;
	  if(e.pageX || e.pageY) {
		x=e.pageX;
		y=e.pageY;
	  } else if(typeof(e.clientX)=='number') {
		var dE=document.documentElement;
		x=e.clientX+document.body.scrollLeft+(dE?dE.scrollLeft:0);
		y=e.clientY+document.body.scrollTop+(dE?dE.scrollTop:0);
	  }
	//  return [x,y];
		xMousePos = x; // Horizontal position of the mouse on the screen
		yMousePos = y; // Vertical position of the mouse on the screen
	}
	
	function set_small_pic(id, index){
		if (pic_no !== index) {
			var el = document.getElementById(id);
			eval("img_arr = img_"+id+";");
			pic_no = index;
			el.style.background = "url("+img_arr[index].src+")";
			el.style.backgroundColor = "#FFFFFF";
			el.style.backgroundPosition = "center";
			el.style.backgroundRepeat = "no-repeat";/**/
			el.title = img_arr[index].alt;
	
			document.getElementById("pic_num_"+id).innerHTML = (index+1);
		}
	}
	
	function scroll_pic(el_id){
		var el = document.getElementById(el_id);
		el_pos = findPos(el);
		var cur_x = xMousePos - el_pos[0];
	//	var cur_y = yMousePos - el_pos[1];
		
		if (id !== el_id) {
			eval("img_arr = img_"+el_id+";");
			pic_no = -1;
			id = el_id;
		}
		var ratio = 100/img_arr.length;
		var index = parseInt(cur_x / ratio);
		index = (index >= img_arr.length) ? (img_arr.length-1) : index;
		index = (index < 0) ? 0 : index;
		set_small_pic(id, index);
/*		if (pic_no !== index) {
			pic_no = index;
			el.style.background = "url("+img_arr[index].src+")";
			el.style.backgroundColor = "#FFFFFF";
			el.style.backgroundPosition = "center";
			el.style.backgroundRepeat = "no-repeat";
			el.title = img_arr[index].alt;
	
			document.getElementById("pic_num_"+el_id).innerHTML = (index+1);
		}*/
	}

	function show(object,val) {
		var mObj = document.getElementById(object);
		mObj.style.visibility = val;
		mObj.style.left = xMousePos-parseInt(mObj.style.width.substr(0, mObj.style.width.length-2));
		mObj.style.top = yMousePos-parseInt(mObj.style.height.substr(0, mObj.style.height.length-2));
	}

	var onImageDL = 0;
	var gImg;
	var el_pos = new Array(0, 0);
	
	function pic_click(el_id){
		if (scrolling == 0) { // FF clicks bleed through!
			spic_no = pic_no;
			el_pos = findPos(document.getElementById(el_id));
			var cur_x = xMousePos - el_pos[0];
			
			id = el_id;
			
			eval("img_arr = img_"+el_id+";");
			
			var ratio = 100/img_arr.length;
			var index = parseInt(cur_x / ratio);
	//		index = (index >= img_arr.length) ? (img_arr.length-1) : index;
	//		index = (index < 0) ? 0 : index;
			if (index >= img_arr.length){
				index = img_arr.length-1;
			} else if (index < 0) {
				index = 0;
			}
			
			gImg = new Image();
			gImg = img_arr[index];
			display_picture();
		}
	}
	
	function display_picture_original(){
	//	load small image
		var small_img = new Image();
	//	small_img.src = gImg.src.replace(/tiny/, "small");
		small_img.src = gImg.src.replace(/small/, "featured");
		small_img.alt = gImg.alt;
		var width = small_img.width;
		var height = small_img.height;
	//	alert("width: "+width+", height: "+height);
	//	if small image loaded, display it
	//	document.getElementById('debugging').innerHTML = small_img.src+", "+width+", "+height;
		if (width + height) {
		//	cancel timer call
			if (onImageDL){
				clearTimeout(onImageDL);
				onImageDL = 0;
			}
		//	display the picture
			var mObj = document.getElementById('pic_display');
			mObj.style.width = width+"px";
			mObj.style.height = height+"px";
			mObj.style.left = el_pos[0]+"px";
			mObj.style.top = el_pos[1]+"px";
		//	mObj.style.top = (el_pos[1]-20)+"px";
			mObj.style.background = "url(/images/loading.gif)";
			mObj.style.backgroundColor = "#FFFFFF";
			mObj.style.backgroundPosition = "center center";
			mObj.style.backgroundRepeat = "no-repeat";
			mObj.innerHTML = "<img src="+small_img.src+" width=\""+width+"\" height=\""+height+"\" alt=\""+small_img.alt+"\" title=\""+small_img.alt+"\" /><div id=\"left_scroll\" onclick=\"do_left_scroll()\"></div><div id=\"right_scroll\" onclick=\"do_right_scroll()\"></div>";
		//	mObj.innerHTML = "<img src="+small_img.src+" width=\""+width+"\" height=\""+height+"\" alt=\""+small_img.alt+"\" title=\""+small_img.alt+"\" /><div id=\"left_scroll\" onclick=\"do_left_scroll()\"><img src=\"images/pix.gif\" width=\"15\" height=\"15\" /></div><div id=\"right_scroll\" onclick=\"do_right_scroll()\"><img src=\"images/pix.gif\" width=\"15\" height=\"15\" /></div>";
			mObj.style.visibility = 'visible';
		} else {
		//	small image not yet downloaded, display loading image and call display_picture del_secs later
		//	var del_secs = 1;
			if (onImageDL > 0){
			//	we've already displayed loading and called display_picture with delay, so this is 
			//	that call, we need to clearTimeout (probably not, but better safe) and call it again
				clearTimeout(onImageDL);
				onImageDL = setTimeout("display_picture()", del_secs*1000); // del_secs delay
			} else {
			//	display loading pic, 136 x 102
				var mObj = document.getElementById('pic_display');
				mObj.style.width = "320px";
				mObj.style.height = "240px";
				mObj.style.left = el_pos[0]+"px";
				mObj.style.top = el_pos[1]+"px";
			//	mObj.style.top = (el_pos[1]-20)+"px";
				mObj.style.background = "url(/images/loading.gif)";
				mObj.style.backgroundColor = "#FFFFFF";
				mObj.style.backgroundPosition = "center center";
				mObj.style.backgroundRepeat = "no-repeat";
				mObj.innerHTML = "<img src=\"/images/pix.gif\" width=\"320\" height=\"240\" alt=\"loading...\" title=\"loading...\" />";
				mObj.style.visibility = 'visible';
			//	call the timer
				onImageDL = setTimeout("display_picture()", del_secs*1000); // del_secs delay
			}
		}
	}
	
	function display_picture(){
	//	load small image
		var small_img = new Image();
	//	small_img.src = gImg.src.replace(/tiny/, "small");
		small_img.src = gImg.src.replace(/small/, "featured");
		small_img.alt = gImg.alt;
		var width = small_img.width;
		var height = small_img.height;
	//	alert("width: "+width+", height: "+height);
	//	if small image loaded, display it
	//	document.getElementById('debugging').innerHTML = small_img.src+", "+width+", "+height;
		if (width + height) {
		//	cancel timer call
			if (onImageDL){
				clearTimeout(onImageDL);
				onImageDL = 0;
			}
		//	display the picture
			var mObj = document.getElementById('pic_box_display');
			mObj.style.left = el_pos[0]-15+"px";
			mObj.style.top = el_pos[1]-15+"px";
			var mObj2 = document.getElementById('pic_container');
			mObj2.style.background = "url(/images/loading.gif)";
			mObj2.style.backgroundColor = "#FFFFFF";
			mObj2.style.backgroundPosition = "center center";
			mObj2.style.backgroundRepeat = "no-repeat";
			document.images.display_image.src = small_img.src;
			document.images.display_image.alt = small_img.alt;
			document.images.display_image.title = small_img.alt;
		//	mObj.innerHTML = "<img src="+small_img.src+" width=\""+width+"\" height=\""+height+"\" alt=\""+small_img.alt+"\" title=\""+small_img.alt+"\" /><div id=\"left_scroll\" onclick=\"do_left_scroll()\"></div><div id=\"right_scroll\" onclick=\"do_right_scroll()\"></div>";
			mObj.style.display = 'block';
			mObj.style.visibility = 'visible';
		} else {
		//	small image not yet downloaded, display loading image and call display_picture del_secs later
		//	var del_secs = 1;
			if (onImageDL > 0){
			//	we've already displayed loading and called display_picture with delay, so this is 
			//	that call, we need to clearTimeout (probably not, but better safe) and call it again
				clearTimeout(onImageDL);
				onImageDL = setTimeout("display_picture()", del_secs*1000); // del_secs delay
			} else {
			//	display loading pic, 136 x 102
				var mObj = document.getElementById('pic_box_display');
				mObj.style.left = el_pos[0]-15+"px";
				mObj.style.top = el_pos[1]-15+"px";
				var mObj2 = document.getElementById('pic_container');
				mObj2.style.background = "url(/images/loading.gif)";
				mObj2.style.backgroundColor = "#FFFFFF";
				mObj2.style.backgroundPosition = "center center";
				mObj2.style.backgroundRepeat = "no-repeat";
				document.images.display_image.src = small_img.src;
				document.images.display_image.alt = small_img.alt;
				document.images.display_image.title = small_img.alt;
			//	mObj.innerHTML = "<img src=\"/images/pix.gif\" width=\"320\" height=\"240\" alt=\"loading...\" title=\"loading...\" />";
				mObj.style.display = 'block';
				mObj.style.visibility = 'visible';
			//	call the timer
				onImageDL = setTimeout("display_picture()", del_secs*1000); // del_secs delay
			}
		}
		document.getElementById("pic_number").innerHTML = (spic_no+1)+" of "+img_arr.length+" pictures";
	}
	
	function hide_picture_original(){
/*		var d = new Date();
		document.getElementById('debugging').innerHTML = "hide_picture() "+d.getTime();*/
		if (scrolling == 0){
			var mObj = document.getElementById('pic_display');
			mObj.style.visibility = 'hidden';
			mObj.style.background = "url(/images/loading.gif)";
			mObj.style.backgroundPosition = "center center";
			mObj.style.width = "0px";
			mObj.style.height = "0px";
			mObj.style.left = "0px";
			mObj.style.top = "0px";
			set_small_pic(id, spic_no);
		}
		scrolling = 0;
	}
	
	function hide_picture(){
		if (scrolling == 0){
			document.images.display_image.src = "images/pix.gif";
			var mObj2 = document.getElementById('pic_container');
			mObj2.style.background = "url(/images/loading.gif)";
			mObj2.style.backgroundPosition = "center center";
			var mObj = document.getElementById('pic_box_display');
			mObj.style.display = 'none';
			mObj.style.visibility = 'hidden';
			mObj.style.left = "0px";
			mObj.style.top = "0px";
			set_small_pic(id, spic_no);
		}
		scrolling = 0;
	}
	
	function display_string(el_id, str){
		el_pos = findPos(document.getElementById(el_id));
		var mObj = document.getElementById('str_display');
		var width = 240;
		mObj.style.width = width+"px";
	//	mObj.style.height = "40px";
		mObj.style.left = (el_pos[0] - width + 60)+"px";
		mObj.style.top = (el_pos[1]-11)+"px";
		mObj.style.backgroundColor = "#FFFFFF";
		mObj.innerHTML = str;
		mObj.style.visibility = 'visible';
	}
	
	function hide_str(){
		var mObj = document.getElementById('str_display');
//		mObj.style.width = "0px";
//		mObj.style.height = "0px";
//		mObj.style.left = "0px";
//		mObj.style.top = "0px";
		mObj.style.visibility = 'hidden';		
	}
	
	function display_remarks_original(el_id){
		var id = el_id.substr("rmrks_".length);
		var xmlhttp = create_xmlhttp();
		document.getElementById("working").innerHTML = "<img src=\""+host+"images/waiting-16.gif\" width=\"16\" height=\"16\" />";
	//	serverPage = ""+host+"processors/fetch-remarks.asp?ms="+new Date().getTime()+setup_querystring();
		serverPage = ""+host+"processors/fetch-remarks.asp?id="+id;
		if (debugging) {
			document.getElementById("debugging").innerHTML = serverPage+"<br />"+document.getElementById("debugging").innerHTML;
		}
		xmlhttp.open("GET", serverPage, true); // asynch param set to false for synch requests, true for asynch

		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				el_pos = findPos(document.getElementById(el_id));
				var mObj = document.getElementById('remarks_display');
				mObj.style.left = (el_pos[0] - mObj.style.width.substr(0, mObj.style.width.length - 2) + 147)+"px";
				mObj.style.top = (el_pos[1]-11)+"px";
			//	mObj.style.backgroundColor = "#FFFFFF";
				mObj.innerHTML = xmlhttp.responseText;
				mObj.style.visibility = 'visible';
				document.getElementById("working").innerHTML = "<img src=\""+host+"images/pix.gif\" width=\"16\" height=\"16\" />";
			} else if (xmlhttp.readyState == 4 && xmlhttp.status != 200) {
				document.getElementById("working").innerHTML = "<img src=\""+host+"images/error-16x16.gif\" width=\"16\" height=\"16\" />";
			}
		}
		
		xmlhttp.send(null);
	}
	
	function hide_remarks_original(){
		var mObj = document.getElementById('remarks_display');
		mObj.style.visibility = 'hidden';
	}
	
	function display_remarks(el_id){
		var id = el_id.substr("rmrks_".length);
		var xmlhttp = create_xmlhttp();
		document.getElementById("working").innerHTML = "<img src=\""+host+"images/waiting-16.gif\" width=\"16\" height=\"16\" />";
		serverPage = ""+host+"processors/fetch-remarks.asp?id="+id;
		if (debugging) {
			document.getElementById("debugging").innerHTML = serverPage+"<br />"+document.getElementById("debugging").innerHTML;
		}
		xmlhttp.open("GET", serverPage, true); // asynch param set to false for synch requests, true for asynch

		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				el_pos = findPos(document.getElementById(el_id));
				var mObj = document.getElementById('remarks_box_display');
				mObj.style.left = (el_pos[0] - mObj.style.width.substr(0, mObj.style.width.length - 2) + 147)+"px";
				mObj.style.top = (el_pos[1]-15)+"px";
			//	mObj.style.backgroundColor = "#FFFFFF";
				document.getElementById('remarks_area').innerHTML = xmlhttp.responseText;
				mObj.style.visibility = 'visible';
				mObj.style.display = 'block';
				document.getElementById("working").innerHTML = "<img src=\""+host+"images/pix.gif\" width=\"16\" height=\"16\" />";
			} else if (xmlhttp.readyState == 4 && xmlhttp.status != 200) {
				document.getElementById("working").innerHTML = "<img src=\""+host+"images/error-16x16.gif\" width=\"16\" height=\"16\" />";
			}
		}
		
		xmlhttp.send(null);
	}
	
	function hide_remarks(){
		var mObj = document.getElementById('remarks_box_display');
		mObj.style.visibility = 'hidden';
		mObj.style.display = 'none';
	}
	
	function reset_scrolling(){
		scrolling = 0;
	}
	
	function do_scroll(dir){
//		var d = new Date();
//		document.getElementById('debugging').innerHTML = "do_scroll() "+d.getTime();
		scrolling = 1;
		eval("img_arr = img_"+id+";");
		spic_no = spic_no + dir;
		spic_no = (spic_no >= img_arr.length) ? 0 : spic_no;
		spic_no = (spic_no < 0) ? img_arr.length-1 : spic_no;

		gImg = img_arr[spic_no];
		display_picture();
	//	reset scrolling to false w/delay because in FF this func doesn't eat click event
		setTimeout("reset_scrolling()", 100); 
	}

	function do_left_scroll(){
		do_scroll(-1);
	}
	
	function do_right_scroll(){
		do_scroll(1);
	}
	