

function openResource(URL) {
	id = "mediaViewer";
	window.open(URL, 'mediaViewer', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=770,height=620,left=455,top=300');
}

function initGallery(photoID, resourceID) {
	swapPhoto(photoID, resourceID)
}

var reqPhoto = createRequestObject();
var reqPrev = createRequestObject();

var updateID;

var bSlideshow;
var SSPhotoID, SSResourceID;
var x;
x=0;
var arrPhotos = new Array();
function goSlideshow(strSlideshow) {
	bSlideshow = true;
	
	arrPhotos = strSlideshow.split("|");
		
	if(x != arrPhotos.length-1) {
		swapPhoto(arrPhotos[x], arrPhotos[arrPhotos.length-1]);
		x++;
		setTimeout(function()
		{
			goSlideshow(strSlideshow);
		}, 3000);
	}else if(x == arrPhotos.length-1){
		x=0;
	}
	
	
	
	
	//nextBtn.href="javascript: swapPhoto(" + photoID + ", " + resourceID + ");";
	//alert(nextBtn.href);
	//for(var x=1; x<numPhotos; x++) {
	/*	var nextBtn = document.getElementById("nextBtn");
		//alert(nextBtn.href);
		var firstPar = nextBtn.href.lastIndexOf("(");
		var lastPar = nextBtn.href.lastIndexOf(")");
		photoID = nextBtn.href.substring(firstPar + 1,firstPar + 2);
		resourceID = nextBtn.href.substring(lastPar - 1, lastPar);
	*/			
		//if(window.readyState==4) {
			//window.setTimeout('swapPhoto(\''+photoID+'\',\''+resourceID+'\');', 1000);
		//}
	//	if (slideshowReady == true) {
				//window.setTimeout('swapPhoto(\''+photoID+'\',\''+resourceID+'\');', 1000);
		
		
			//alert(photoID + " | " + resourceID);
			
		//}else{
				//goSlideshow(photoID, resourceID, x);	
	//	}
		
		//alert(x);
	//}
}

function swapPhoto(photoID, resourceID) {
	var strPhotoSrc;
	var url = "includes/swapPhoto.aspx";
	
	if(bSlideshow) {
		SSPhotoID = photoID;
		SSResourceID = resourceID;
	}
	
	updateID = "dynamicContent";
	reqPhoto.open("POST",url,true);
	reqPhoto.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	reqPhoto.onreadystatechange = handleContent;
	reqPhoto.send("PhotoID=" + photoID + "&ResourceID=" + resourceID + "&Action=getCurrent");	
}


function createRequestObject() {
	var ro;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
		ro = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		ro = new XMLHttpRequest();
	}
	return ro;
}

function handleContent() {
	if (reqPhoto.readyState == 4) {
	 	if (reqPhoto.status == 200) {
			document.getElementById(updateID).innerHTML = reqPhoto.responseText;
			slideshowReady = true;			
		}
	}
}

