﻿function addImage(img, side, caption)
{
	var pos = img.lastIndexOf('/');
	var dir = img.substring(0,pos);
	var name = img.substring(pos+1);
	
	captions.push(caption);
	sources.push(img);

	if(side == 'none')
	{
	    document.write("<div id='none' style='display: none;'>");
	}
		
	addImageLink(dir, name);
	if(side == 'left')
		addLeftImage(dir, name);
	else if(side == 'right')
		addRightImage(dir, name);
	else if(side != 'none')
	{
	    document.write("<img src='"+dir+"/thumb_"+name+"' border='none' style='margin: 0px 2px 0px 2px; '/>");
	}
	document.writeln("</a>");
	
	if(side == 'none')
	{
	    document.writeln("</div>");
	}
}

function addImageLink(dir, name)
{
    document.write("<a href=\"" + sources[sources.length-1] +"\" rel=\"lightbox[slideshow]\" title=\""+captions[captions.length-1]+"\">");

	//document.write("<a href='javascript:showSlideShow("+(sources.length-1)+");'>");
}

function addRightImage( dir, name )
{
	document.write("<img src='"+dir+"/thumb_"+name+"' border='none' align='right' style='margin-left: 5px;'/></a>");
}

function addLeftImage( dir, name )
{
	document.write("<img src='"+dir+"/thumb_"+name+"' border='none' align='left' style='margin-right: 5px;'/></a>");
}

function createXMLHttpRequest()
{
	var xmlrequest = null;
	// branch for native XMLHttpRequest object
	if(window.XMLHttpRequest) 
	{
		try {
			xmlrequest = new XMLHttpRequest();
		} 
		catch(e) {
			xmlrequest = null;
		}
		
	}
	else if(window.ActiveXObject) // branch for IE/Windows ActiveX version
	{
		try {
			xmlrequest = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch(e) 
		{
			try {
				xmlrequest = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e) {
				xmlrequest = null;
			}
		}
	}
	return xmlrequest;
}

function xmlCallback()
{

}

function imageLoaded()
{
	slideshow.image.style.display = 'block';
	slideshow.loading.style.display = 'none';
}

function SlideShow(){
	this.image = null;
	this.caption = null;
	this.curr_image = null;
	this.prev_image = null;
	this.next_image = null;
	this.dir = "";
	this.sources = null;
	this.loading = null;
}

SlideShow.prototype.dispose = function()
{
	this.image = null;
	this.caption = null;
	this.curr_image = null;
	this.prev_image = null;
	this.next_image = null;
	this.dir = "";
	this.sources = null;
	this.loading = null;
}

SlideShow.prototype.toString = function()
{
	return "Slideshow object";
}

SlideShow.prototype.setSources = function( dir, _sources, captions )
{
	this.dir = dir;
	this.sources = _sources;
	this.captions = captions;
}

SlideShow.prototype.showImage = function( index, doc )
{
	if(doc)
		slideshow.doc = doc;
	if(index >= slideshow.sources.length)
		index = slideshow.sources.length-1;
	if(index < 0)
		index = 0;

	if(!slideshow.loading)
	{
		slideshow.loading = slideshow.doc.getElementById('loading_image');
		slideshow.loading.src = "/images/ani_loading_01.gif";
	}
	slideshow.loading.style.display = 'block';
			 
	slideshow.current = index;
	slideshow.next = index+1;
	if(slideshow.next >= slideshow.sources.length)
		slideshow.next = 0;
	slideshow.prev = index-1;
	if(slideshow.prev < 0)
		slideshow.prev = slideshow.sources.length-1;
		
	slideshow.image = slideshow.doc.getElementById('slideshow_image');
	slideshow.image.style.display = 'none';
	//slideshow.image.style.left = '0px;';
	//slideshow.image.style.top = '0px;';
	slideshow.image.onload = imageLoaded;
	
	var dir = slideshow.dir;
	if(dir == "")
	{
		slideshow.image.src = slideshow.sources[index];
	}
	else
		slideshow.image.src = dir + slideshow.sources[index];
	
	var xmlr = createXMLHttpRequest();
	if(xmlr)
	{
		try
		{
			xmlr.onreadystatechange = xmlCallback;
			var str = '/cgi-bin/pagelog.pl?PAGE=_JAVA_';
			if(dir != "")
				str+=slideshow.dir;
			str += slideshow.sources[index];
			xmlr.open("GET", str, true);
			xmlr.send("");
		}
		catch(e)
		{
			alert("Exc: "+e);
		}
	}
	else
		alert("no xmlr");
	
	var use_caption = (slideshow.captions != null);
	use_caption = use_caption && index < slideshow.captions.length; 
	//if(!slideshow.caption)
		slideshow.caption = slideshow.doc.getElementById('img_caption');
		
	var ga = slideshow.doc.getElementById('google_ad_div');
	ga.innerHTML="\
	<script type='text/javascript'><!--\
	google_ad_client = 'pub-5741250203238005';\
	google_ad_width = 120;\
	google_ad_height = 600;\
	google_ad_format = '120x600_as';\
	google_color_border = 'CCCCCC';\
	google_color_bg = 'FFFFFF';\
	google_color_link = '000000';\
	google_color_url = '666666';\
	google_color_text = '333333';\
	//--></script>\
	<script type='text/javascript'\
		src='http://pagead2.googlesyndication.com/pagead/show_ads.js'>\
	</script>";


	slideshow.caption.innerHTML = "<b>("+(index+1)+"/"+slideshow.captions.length+")</b> "+(use_caption ? slideshow.captions[index] == '' ? slideshow.sources[index] : slideshow.captions[index] : slideshow.sources[index]);
	
	/*if(!slideshow.curr_image)
		slideshow.curr_image = slideshow.doc.getElementById('curr_img');
	slideshow.curr_image.src = slideshow.dir + "thumb_"+slideshow.sources[slideshow.current];*/
	
	//if(!slideshow.prev_image)
	{
		slideshow.prev_image = slideshow.doc.getElementById('prev_img');
		slideshow.prev_image.onclick = slideshow.showPrev;
		slideshow.prev_image.object = this;
	}
	var prev = slideshow.sources[slideshow.prev];
	var lio = prev.lastIndexOf('/');
	if(lio > 0)
		slideshow.prev_image.src = dir+prev.slice(0, lio+1)+'thumb_'+prev.slice(lio+1, prev.length);
	else
		slideshow.prev_image.src = dir + "thumb_"+slideshow.sources[slideshow.prev];
	
	//if(!slideshow.next_image)
	{
		slideshow.next_image = slideshow.doc.getElementById('next_img');
		slideshow.next_image.onclick = slideshow.showNext;
		slideshow.next_image.object = this;
	}
	
	var next = slideshow.sources[slideshow.next];
	lio = next.lastIndexOf('/');
	if(lio > 0)
		slideshow.next_image.src = dir+next.slice(0, lio+1)+'thumb_'+next.slice(lio+1, next.length);
	else
		slideshow.next_image.src = dir + "thumb_"+slideshow.sources[slideshow.next];
}

SlideShow.prototype.showNext = function()
{
	var _this = this;
	if(_this.object)
		_this = _this.object;
		
 	slideshow.showImage(slideshow.next, slideshow.doc);
 	
 	return true;
}

SlideShow.prototype.showPrev = function()
{
	var _this = this;
	if(_this.object)
		_this = _this.object;
		
	slideshow.showImage(_this.prev, _this.doc);
	
	return true;
}

var slideshow_html = "\
 <head><title>Photo From the Mike Doyle Collection</title>\n\
 <LINK rel = STYLESHEET \n\
 href ='/photo_style.css' \n\
 Type ='text/css'> </LINK>\n\
 <script type='text/javascript'>\n\
 function init(){\n\
 if(document.slideshow) \n\
	document.slideshow.showImage(document.start, document);\n\
 }\n\
 </script>\n\
 </head>\n\
 <body onload='init();' style='background-color: #FFFFFF;'>\n\
 <div id='slideshow_div' style='border: 1px solid black; left: 0px; top: 0px; float: left; margin: 0px 20px 0px 0px;'>\n\
 <table>\n\
 <tr><td>\n\
 <img id='loading_image' src='/images/ani_loading_01.gif'>\
 <img id='slideshow_image' oncontextmenu='return false;'></td></tr>\n\
 <tr><td align='center'>\n\
 <div id='img_caption'></div></td></tr>\n\
 </table>\n\
 </div>\n\
 <div id='link_div' style='top: 0px;'>\n\
 <div class='fontSubHeader'>Sponsor Links:</div><br>\n\
 <a href='/cgi-bin/redirect.pl?http://www.metoliusclimbing.com' target='_blank'>\n\
 <img src='/images/tmp_metolius.jpg' style='border: none; margin: 0px 0px 10px 5px;'></a><br>\n\
 <a href='/cgi-bin/redirect.pl?http://www.sportiva.com' target='_blank'>\n\
 <img src='/images/tmp_sportiva_logo.jpg' style='border: none; margin: 0px 0px 10px 5px;'></a><br>\n\
 <a href='/cgi-bin/redirect.pl?http://www.blurrstuff.com' target='_blank'>\n\
 <img src='/images/tmp_blurr_red.jpg' style='border: none; margin: 0px 0px 10px 5px;'></a><br>\n\
 <a href='/cgi-bin/redirect.pl?http://www.sequenceclimbing.com' target='_blank'>\n\
 <img src='/images/tmp_seq_img.jpg' style='border: none; margin: 0px 0px 10px 5px;'></a><br>\n\
 <a href='/cgi-bin/redirect.pl?http://www.mammutusa.com' target='_blank'>\n\
 <img src='/images/tmp_hdr_logo.jpg' style='border: none; margin: 0px 0px 10px 5px;'></a><br>\n\
 </div>\n\
 <div id='thumbnail.div' style='position: absolute; left: 620px; top: 650px;'>\n\
 <table>\n\
 <tr>\n\
 <td align='center' style='width: 105px;'><img id='prev_img' style='border: none;'></td>\n\
 <td align='center' style='width: 105px;'><img id='next_img' style='border: none;'></td>\n\
 </tr><tr>\n\
 <td align='center'>Previous</td><td align='center'>Next</td></tr></table>\n\
 </div>\n\
 <div id='google_ad_div'>\
 </div>\n\
 </body>\n\
 </html>\n";

var slideshow = new SlideShow();
 
function createSlideShow( dir, sources, captions, id )
{
	if(!slideshow)
		slideshow = new SlideShow();

	slideshow.dispose();
	slideshow.setSources(dir, sources, captions);
	
	var params = "width=1100,height=840,left=10,top=10";
	params += ",resizable=yes,scrollbars=yes,toolbar=no,location=no,menubar=no,status=no";
	
	var new_window = window.open("", "_blank", params);
	
	//new_window.start = parseInt(id);
	//new_window.slideshow = slideshow;
	
	var init = true;
	if(document.all)
		init = false;
	else
	{
		new_window.document.start = parseInt(id);
		new_window.document.slideshow = slideshow;
	}
	
	new_window.document.open();	
	new_window.document.writeln(slideshow_html);
	new_window.document.close();
	
	if(!init)
	{
		new_window.document.start = parseInt(id);
		new_window.document.slideshow = slideshow;
		new_window.document.slideshow.showImage(new_window.document.start, new_window.document);
	}
}

function loadVideo( url, width, height, desc, title )
{
	var xmlr = createXMLHttpRequest();
	if(xmlr)
	{
		try
		{
			xmlr.onreadystatechange = xmlCallback;
			var str = '/cgi-bin/pagelog.pl?PAGE=_VIDEO_URL';
			str += url + "PLUS_TITLE"+title;
			xmlr.open("GET", str, true);
			xmlr.send("");
		}
		catch(e)
		{
			alert("Exc: "+e);
		}
	}
	else
		alert("no xmlr");

    var pwidth = parseInt(width)+50;
    var pheight = parseInt(height)+250;
	var params = "width="+pwidth+",height="+pheight+",left=10,top=10";
	params += ",resizable=no,scrollbars=yes,toolbar=no,location=no,menubar=no,status=no";
	
	var video_html = "<head><title>Video From the Mike Doyle Collection</title>\n\
								<LINK rel = STYLESHEET \n\
							 href ='/photo_style.css' \n\
							 Type ='text/css'> </LINK>\n\
							 <script type='text/javascript'>\n\
							 function init(){\n\
							 }\n\
							 </script>\n\
							 </head>\n\
							 <body onload='init();' style='background-color: #E5E5E5;'>\n\
							 <div class='fontText'>";
	video_html += "<center><b>"+title+"</b></center><br>";
	//video_html +=	<param name="movie" value="http://www.youtube.com/v/xSv7y4DSTdA"></param><embed src="http://www.youtube.com/v/xSv7y4DSTdA" type="application/x-shockwave-flash" width="425" height="350"></embed></object>
	video_html += "<object width="+width+" height="+height+">";
	video_html += "\<param name=\"movie\" value=\""+url;
	video_html += "\"></param><embed src=\""+url;
	video_html += "\" type=\"application/x-shockwave-flash\" width="+width+" height="+height+"></embed></object>";
	video_html += "<br>"+desc;

	video_html += "</div></body></html>";
		
	var new_window = window.open("", "_blank", params);
	
	new_window.document.open();	
	new_window.document.writeln(video_html);
	new_window.document.close();
}
