﻿
var full2 = new Array();
var xmlDoc;
var test;
var thumbs = new Array();
var full = new Array();
var picArray = new Array ();
var picNum;
var respNum;
var timeout;
var timing = 0;
var which =0;
var speed = 5000;
var tempString="";
var subA="";
var subB="";
var pNum;
function importXML(file)
{
	
	if (document.implementation && document.implementation.createDocument)
	{
		xmlDoc = document.implementation.createDocument("", "", null);
		xmlDoc.onload = slideshowXML;
	}
	else if (window.ActiveXObject)
	{
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async="false";
		xmlDoc.onreadystatechange = function () {
			if (xmlDoc.readyState == 4) slideshowXML()
		};
 	}
	else
	{
		alert('Your browser can\'t handle this script');
		return;
	}
	xmlDoc.load(file);
}

function kickOff(){
	//alert(pNum);
	document.images.randomized.src=picArray[pNum].src;
	forward();
}
function forward(){
	
	if(which==picNum){
		which=0;
	}

	document.images.slider.src=picArray[which++].src;
	
	timeout = setTimeout('forward()', speed);
}
function viewIt(){
	//alert(full[which]);
	
	//put the popup in here
	
	if(which==0){
		if (window.showModalDialog) {
			window.showModalDialog(full2[which].src,"name","dialogWidth:500px;dialogHeight:500px");
		} 
		else {
			window.open(full2[which].src,'mywin','left=20,top=20,width=500,height=500,toolbar=0,resizable=0,modal=yes');
			
			
		}
		//document.images.viewer.src=full2[which].src;
		//window.open(full2[which].src,'mywin','left=20,top=20,width=500,height=500,toolbar=0,resizable=0,modal=yes');
	}
	else{
		if (window.showModalDialog) {
			window.showModalDialog(full2[which-1].src,"name","dialogWidth:500px;dialogHeight:500px");
		} 
		else {
			window.open(full2[which-1].src,'mywin','left=20,top=20,width=500,height=500,toolbar=0,resizable=0,modal=yes');
			/*html = "<HTML><HEAD><TITLE>Photo</TITLE></HEAD><BODY LEFTMARGIN=0 MARGINWIDTH=0 TOPMARGIN=0 MARGINHEIGHT=0><CENTER><IMG SRC='" + full2[which-1].src + "' BORDER=0 NAME=image onload='window.resizeTo(document.image.width,document.image.height)'></CENTER></BODY></HTML>";
 			popup=window.open('','image','toolbar=0,location=0,directories=0,menuBar=0,scrollbars=0,resizable=1');
 			popup.document.open();
 			popup.document.write(html);
 			popup.document.focus();
 			popup.document.close();*/
		}
		//document.images.viewer.src=full2[which-1].src;
		//window.open(full2[which-1].src,'mywin','left=20,top=20,width=500,height=500,toolbar=0,resizable=0,modal=yes');
	}
}
function sliderXML(){

//document.write('<a href = "#" onClick="window.createPopup();"><img src="'+thumbs[0]+'" name="slider"></a>');
	document.write('<a title="Click for larger image!" border="0" href = "#" onClick="viewIt();"><img width="146" height="150" src="'+thumbs[0]+'" name="slider"></a>');
}

function randomizer(){
	
//document.write('<a href = "#" onClick="window.createPopup();"><img src="'+thumbs[0]+'" name="randomized"></a>');
	document.write('<img width="146" height="150" src="'+thumbs[0]+'" name="randomized">');
	
}

function slideshowXML(){
		picNum = xmlDoc.getElementsByTagName('picture').length;
		//insert randomizer here for testing
		pNum=Math.floor(Math.random()*picNum);
		
		//alert(pNum);
		
		for(var j=0;j<picNum;j++){
			tempString=xmlDoc.getElementsByTagName('filename')[j].firstChild.data;
			subA  = tempString.substring(tempString.length-4,tempString.length);
			subB = tempString.substring(0,tempString.lastIndexOf('_')); 
			full[j]='./sliderimages/'+subB+subA;
			thumbs[j] = './sliderimages/'+xmlDoc.getElementsByTagName('filename')[j].firstChild.data;
			picArray[j] = new Image();
			picArray[j].src = thumbs[j];
			full2[j]=new Image();
			full2[j].src = full[j];
		}
}
