/* ================================================ 
andyryan.js for AndyRyan.com

Copyright (c) 2008 Jesse Nahan. All rights reserved.
jesse@myactivemind.com
==================================================== */


function alerton() {

	document.getElementById('alertLevel').style.visibility = 'visible';
	document.getElementById('alertBox').innerHTML = 'TEST TEXT';
}

function alertoff() {

	document.getElementById('alertLevel').style.visibility = 'hidden';
	document.getElementById('alertBox').innerHTML = '';
}

function emailTest() {
	
	document.getElementById('alertLevel').style.visibility = 'visible';

	getData('email_linkDIV.php?gallery_id='+current_galleryID+'&ie6=N','alertLevel');

}

var XMLHttpRequestObject = false; 

if (window.XMLHttpRequest) {
XMLHttpRequestObject = new XMLHttpRequest();
} else if (window.ActiveXObject) {
XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
}

function getData(dataSource, divID) 
{ 
if(XMLHttpRequestObject) {
  var obj = document.getElementById(divID); 
  XMLHttpRequestObject.open("GET", dataSource); 

  XMLHttpRequestObject.onreadystatechange = function() 
  { 
	if (XMLHttpRequestObject.readyState == 4 && 
	  XMLHttpRequestObject.status == 200) { 
		obj.innerHTML = XMLHttpRequestObject.responseText; 
	} 
  } 

  XMLHttpRequestObject.send(null); 
}
}

// Search value tracking variables
var	searchSterm = '';
var	searchRestrict = 'any';
var	searchOffset = 0;
var	searchThumbDisplay = 'true';
var	searchStart = 'sets';
var searchClientID = -1;


// IE6 uses jpgs matching the background instead of transparent pngs. 
var imageSuffix;

if (explorer6) {

	switch (backgroundColor) {
	
		case "ffffff":
			imageSuffix = "_white.jpg";
			break;		
		
		case "333333":
			imageSuffix = "_gray.jpg";
			break;		
		
		default:
			imageSuffix = "_black.jpg";
		
	}
} else {

	imageSuffix = ".png";

}


function fetchPhotoSetName(galleryID) {

	getData('fetchPhotoSetName.php?gallery_id='+galleryID+'&background='+backgroundColor,'photoSetName');

}

function showHelp() {

	document.getElementById('photoSetName').innerHTML = ''; 

	// Clear bottom rule on monoslideshow
	document.getElementById('monoSlideshow').style['borderBottom'] = '1px solid #999999';
	
	if (explorer6 == true) {

		getData('showhelp.php?showH='+showH+'&showW='+showW+'&gallery_id='+current_galleryID+'&current_album='+current_album+'&ie6=Y', 'monoSlideshow');

	} else {
	
		getData('showhelp.php?showH='+showH+'&showW='+showW+'&gallery_id='+current_galleryID+'&current_album='+current_album+'&ie6=N', 'monoSlideshow');
	
	}
}

function showRestricted(gid,pid,accessID) {

	document.getElementById('photoSetName').innerHTML = ''; 

	if (explorer6 == true) {

		getData('showrestricted.php?showH='+showH+'&showW='+showW+'&gallery_id='+gid+'&photo_id='+pid+'&access_confirm='+accessID+'&ie6=Y', 'monoSlideshow');
		
	} else {
	
		getData('showrestricted.php?showH='+showH+'&showW='+showW+'&gallery_id='+gid+'&photo_id='+pid+'&access_confirm='+accessID+'&ie6=N', 'monoSlideshow');

	}
}

function returnToSet() {

	switchAlbum(current_album,current_galleryID);
	
}

function showContact() {

	document.getElementById('photoSetName').innerHTML = ''; 

	// Clear bottom rule on monoslideshow
	document.getElementById('monoSlideshow').style['borderBottom'] = '0px';

	if (explorer6 == true) {

		getData('showcontact.php?showH='+showH+'&showW='+showW+'&ie6=Y', 'monoSlideshow');
		
	} else {
	
		getData('showcontact.php?showH='+showH+'&showW='+showW+'&ie6=N', 'monoSlideshow');

	}
}

function showAccount() {

	document.getElementById('photoSetName').innerHTML = ''; 

	// Clear bottom rule on monoslideshow
	document.getElementById('monoSlideshow').style['borderBottom'] = '0px';

	if (explorer6 == true) {
	
		getData('showaccount.php?showH='+showH+'&showW='+showW+'&user_id='+user_id+'&ie6=Y', 'monoSlideshow');

	} else {
	
		getData('showaccount.php?showH='+showH+'&showW='+showW+'&user_id='+user_id+'&ie6=N', 'monoSlideshow');

	}

}

function showRemove(userIDToRemove) {

	document.getElementById('photoSetName').innerHTML = ''; 

	// Clear bottom rule on monoslideshow
	document.getElementById('monoSlideshow').style['borderBottom'] = '0px';

	if (explorer6 == true) {
	
		getData('showremove.php?showH='+showH+'&showW='+showW+'&user_id='+userIDToRemove+'&ie6=Y', 'monoSlideshow');

	} else {
	
		getData('showremove.php?showH='+showH+'&showW='+showW+'&user_id='+userIDToRemove+'&ie6=N', 'monoSlideshow');

	}

}

function showRelated(pickGalleryID,pickPhotoID) {

	document.getElementById('photoSetName').innerHTML = ''; 

	// Show bottom rule on monoslideshow
	document.getElementById('monoSlideshow').style['borderBottom'] = '1px solid #999999';

	if (explorer6 == true) {
	
		getData('showrelated.php?showH='+showH+'&showW='+showW+'&gallery_id='+pickGalleryID+'&photo_id='+pickPhotoID+'&ie6=Y', 'monoSlideshow');

	} else {
	
		getData('showrelated.php?showH='+showH+'&showW='+showW+'&gallery_id='+pickGalleryID+'&photo_id='+pickPhotoID+'&ie6=N', 'monoSlideshow');
	}

}

function showClassic() {

	window.open("classic/andyryan.html","displayWindow",'width=800' + ',height=600' + ',resizable=1,scrollbars=1,toolbar=no,location=no,status=no' )

}

function showLogin() {
	
	document.getElementById('photoSetName').innerHTML = ''; 

	// Clear bottom rule on monoslideshow
	document.getElementById('monoSlideshow').style['borderBottom'] = '0px';

	if (explorer6 == true) {
	
		getData('showlogin.php?showH='+showH+'&showW='+showW+'&error_msg='+error_msg+'&ie6=Y', 'monoSlideshow');

	} else {
	
		getData('showlogin.php?showH='+showH+'&showW='+showW+'&error_msg='+error_msg+'&ie6=N', 'monoSlideshow');

	}
	
	// reset error_msg -- if there is an error message, it should only appear once.
	error_msg = 0;

}

function showLogin1(gid,pid) {
	
	// Variation of login to include gallery and photo_ids passed from e-mail ink
	document.getElementById('photoSetName').innerHTML = ''; 

	// Clear bottom rule on monoslideshow
	document.getElementById('monoSlideshow').style['borderBottom'] = '0px';

	if (explorer6 == true) {
	
		getData('showlogin.php?showH='+showH+'&showW='+showW+'&error_msg='+error_msg+'&ie6=Y&gallery_id='+gid+'&photo_id='+pid, 'monoSlideshow');

	} else {
	
		getData('showlogin.php?showH='+showH+'&showW='+showW+'&error_msg='+error_msg+'&ie6=N&gallery_id='+gid+'&photo_id='+pid, 'monoSlideshow');

	}
	
	// reset error_msg -- if there is an error message, it should only appear once.
	error_msg = 0;

}


function showMysets(show_parent_id) {

	// update navigation highlight
	document.getElementById('nav_books').innerHTML = '';
	document.getElementById('nav_advert').innerHTML = '';
	document.getElementById('nav_arch').innerHTML = '';
	document.getElementById('nav_food').innerHTML = '';
	document.getElementById('nav_people').innerHTML = '';
	document.getElementById('nav_projects').innerHTML = '';
	document.getElementById('nav_history').innerHTML = '';
	document.getElementById('nav_mysets').innerHTML = '<img src="images/nav8_mysets_blue'+imageSuffix+'" width="76" height="25" border="0" name="nav_mysets"/>';

	document.getElementById('photoSetName').innerHTML = ''; 

	// Clear bottom rule on monoslideshow
	document.getElementById('monoSlideshow').style['borderBottom'] = '0px';

	getData('showmysets.php?showH='+showH+'&showW='+showW+'&thumbnailtoggle='+thumbnailsOnSearch+'&user_id='+user_id+'&show_parent_id='+show_parent_id, 'monoSlideshow');


}

function showHistory(show_parent_id) {

	// update navigation highlight
	document.getElementById('nav_books').innerHTML = '';
	document.getElementById('nav_advert').innerHTML = '';
	document.getElementById('nav_arch').innerHTML = '';
	document.getElementById('nav_food').innerHTML = '';
	document.getElementById('nav_people').innerHTML = '';
	document.getElementById('nav_projects').innerHTML = '';
	document.getElementById('nav_history').innerHTML = '<img src="images/nav8_setsviewed_blue'+imageSuffix+'" width="106" height="25" border="0" name="nav_history"/>';

	if (user_id >=0) {
	
		document.getElementById('nav_mysets').innerHTML = '';
	
	}

	document.getElementById('photoSetName').innerHTML = ''; 
	
	// Clear bottom rule on monoslideshow
	document.getElementById('monoSlideshow').style['borderBottom'] = '0px';


	getData('showhistory.php?showH='+showH+'&showW='+showW+'&thumbnailtoggle='+thumbnailsOnSearch+'&show_parent_id='+show_parent_id, 'monoSlideshow');


}

function showProjects(show_parent_id) {

 	show_parent_id = typeof(show_parent_id) != 'undefined' ? show_parent_id : 0;
	
	// update navigation highlight
	document.getElementById('nav_books').innerHTML = '';
	document.getElementById('nav_advert').innerHTML = '';
	document.getElementById('nav_arch').innerHTML = '';
	document.getElementById('nav_food').innerHTML = '';
	document.getElementById('nav_people').innerHTML = '';
	document.getElementById('nav_projects').innerHTML = '<img src="images/nav8_projects_blue'+imageSuffix+'" width="79" height="25" border="0" name="nav_projects"/>';
	document.getElementById('nav_history').innerHTML = '';

	document.getElementById('photoSetName').innerHTML = ''; 

	if (user_id >=0) {
	
		document.getElementById('nav_mysets').innerHTML = '';
	
	}
	
	document.getElementById('photoSetName').innerHTML = ''; 

	// Clear bottom rule on monoslideshow
	document.getElementById('monoSlideshow').style['borderBottom'] = '0px';

	getData('showprojects.php?showH='+showH+'&showW='+showW+'&thumbnailtoggle='+thumbnailsOnSearch+'&show_parent_id='+show_parent_id, 'monoSlideshow');

}


function showSearch() {

	// update navigation highlight
	document.getElementById('nav_books').innerHTML = '';
	document.getElementById('nav_advert').innerHTML = '';
	document.getElementById('nav_arch').innerHTML = '';
	document.getElementById('nav_food').innerHTML = '';
	document.getElementById('nav_people').innerHTML = '';
	document.getElementById('nav_projects').innerHTML = '';
	document.getElementById('nav_history').innerHTML = '';
	if (user_id >=0) {
	
		document.getElementById('nav_mysets').innerHTML = '';
	
	}
	
	// Clear bottom rule on monoslideshow
	document.getElementById('monoSlideshow').style['borderBottom'] = '0px';

	getData('showsearch.php?showH='+showH+'&showW='+showW, 'monoSlideshow');

}

function showImage(photoIDFromSearch) {

	//alert('show ID: ' + photoIDFromSearch);
	// For now, this displays a single photo from the search page	
	
	photoIDToStart =  photoIDFromSearch;
	current_galleryID = -1;
	switchAlbum(current_album,current_galleryID);


}

function showAccountRequest() {

	// Clear bottom rule on monoslideshow
	document.getElementById('monoSlideshow').style['borderBottom'] = '0px';

	document.getElementById('photoSetName').innerHTML = ''; 
	
	if (explorer6 == true) {
	
		getData('login_request.php?showH='+showH+'&showW='+showW+'&ie6=Y', 'monoSlideshow');

	} else {
	
		getData('login_request.php?showH='+showH+'&showW='+showW+'&ie6=N', 'monoSlideshow');

	}


}

function clearSearchResults() {

	// Clear search term and return to search results link
	searchSterm = '';
	document.getElementById('returnToSearch').innerHTML = '';

}

function showReturnToSearch() {

	// Displays return to search results link
	var returnToClass = (backgroundColor == 'ffffff')? 'returnToSearchGray' : 'returnToSearchWhite';
	
	// TO DO 3/21/08
	// How to handle searching clientID searching? searchClientID > -1???
	
	document.getElementById('returnToSearch').innerHTML = "<a href=\"javascript:switchPageSearchResults('" +searchSterm + "', '" +searchRestrict + "', " +searchOffset + ", '"
		+ searchThumbDisplay + "','" +searchStart + "'," + searchClientID + ");\" class=\""+returnToClass+"\">< Return to search results</a>" +
	" <a href=\"javascript:clearSearchResults();\" class=\""+returnToClass+"\">(clear)</a>";


}


function sendForgottenPassword() {
		
	if (explorer6 == true) {
	
		getData('showSendPassword.php?showH='+showH+'&showW='+showW+'&error_msg='+error_msg+'&ie6=Y', 'monoSlideshow');

	} else {
	
		getData('showSendPassword.php?showH='+showH+'&showW='+showW+'&error_msg='+error_msg+'&ie6=N', 'monoSlideshow');

	}


}

function toggleThumbnails(module,thumbnailValue,show_parent_id) {

 	show_parent_id = typeof(show_parent_id) != 'undefined' ? show_parent_id : 0;
  
	if (thumbnailValue == "true") {
	
		thumbnailsOnSearch = "true";
		
	} else {
	
		thumbnailsOnSearch = "false";
	
	}

	switch(module) {
	
		case 'showprojects':
			showProjects(show_parent_id);
			break;
			
		case 'showmysets':
			showMysets(show_parent_id);
			break;
			
		case 'showhistory':
			showHistory(show_parent_id);
			break;
	}
}

function switchPageProjects(offset,show_parent_id) {

	getData('showprojects.php?showH='+showH+'&showW='+showW+'&thumbnailtoggle='+thumbnailsOnSearch+'&rowOffset='+offset+'&show_parent_id='+show_parent_id, 'monoSlideshow');

}

function switchPageMySets(offset,show_parent_id) {

	getData('showmysets.php?showH='+showH+'&showW='+showW+'&thumbnailtoggle='+thumbnailsOnSearch+'&rowOffset='+offset+'&user_id='+user_id, 'monoSlideshow');

}

function switchViewHistory(offset,show_parent_id) {

	getData('showhistory.php?showH='+showH+'&showW='+showW+'&thumbnailtoggle='+thumbnailsOnSearch+'&rowOffset='+offset+'&show_parent_id='+show_parent_id, 'monoSlideshow');

}

function switchPageSearchResults(sterm,srestrict,offset,thumbnailDisplay,startSearchWith,clientID) {

	//var returnToClass = (backgroundColor == 'ffffff')? 'returnToSearchGray' : 'returnToSearchWhite';
	
	// Update values:
	searchSterm = sterm;
	searchRestrict = srestrict;
	searchOffset = offset;
	searchThumbDisplay = thumbnailDisplay;
	searchStart = startSearchWith;
	searchClientID = clientID
	
	document.getElementById('photoSetName').innerHTML = ''; 
	
	// Clear bottom rule on monoslideshow
	document.getElementById('monoSlideshow').style['borderBottom'] = '0px';

	showReturnToSearch();
	//document.getElementById('returnToSearch').innerHTML = "<a href=\"javascript:switchPageSearchResults('" +sterm + "', '" +srestrict + "', " +offset + ", '" + thumbnailDisplay + "','" +startSearchWith +"');\" class=\""+returnToClass+"\">< Return to search results</a>";

	if (searchClientID == -1) {
	
		getData('showSearchResults.php?showH='+showH+'&showW='+showW+'&searchterm='+sterm+'&restrict='+srestrict+'&rowOffset='+offset+'&thumbnailtoggle='+thumbnailDisplay+'&startWith='+startSearchWith, 'monoSlideshow');
	
	} else {
	
		getData('showSearchResults.php?showH='+showH+'&showW='+showW+'&client_id='+clientID+'&restrict='+srestrict+'&rowOffset='+offset+'&thumbnailtoggle='+thumbnailDisplay+'&startWith='+startSearchWith, 'monoSlideshow');
	
	}
}


function submitAccountRequest() {

	if (verifyLoginRequest()) {
	
		var myForm = document.loginRequestForm;
		var firstname = encodeURIComponent(myForm.firstname.value);
		var lastname = encodeURIComponent(myForm.lastname.value);
		var email = encodeURIComponent(myForm.email.value);
		var company = encodeURIComponent(myForm.company.value);
		var city = encodeURIComponent(myForm.city.value);
		var state = encodeURIComponent(myForm.state.value);
		var country = encodeURIComponent(myForm.country.value);
		
		getData('login_request_process.php?showH='+showH+'&showW='+showW+'&firstname='+firstname+'&lastname='+lastname+'&email='+email+'&company='+company+'&city='+city+'&state='+state+'&country='+country, 'monoSlideshow');
		
	} else {
	
		alert('Verify false');
	}
	

}

function submitUpdatePassword() {

	var myForm = document.updatePassword;

	if (myForm.curpassword.value == '') {
	
		alert('You must enter your original password.');
		
	} else if (myForm.newpassword.value.length < 6) {
	
			alert('Your new password must be at least 6 characters long.');
			
	} else if (myForm.newpassword.value != myForm.newpassword1.value) {
	
			alert('Your new passwords don\'t match.');
	
	} else {
	
		var newpassword = encodeURIComponent(myForm.newpassword.value);
		var curpassword = encodeURIComponent(myForm.curpassword.value);
		getData('updatePassword.php?showH='+showH+'&showW='+showW+'&curpassword='+curpassword+'&newpassword='+newpassword+'&user_id='+user_id, 'monoSlideshow');

	}

}

function sendPassword() {

	if (document.sendPasswordForm.email.value == '') {
	
		alert('You must enter an e-mail address.');
		
	} else {
	
		var email = encodeURIComponent(document.sendPasswordForm.email.value);
	
		if (explorer6 == true) {
		
			getData('showSendPassword.php?showH='+showH+'&showW='+showW+'&ie6=Y&email='+email, 'monoSlideshow');
		
		} else {
		
			getData('showSendPassword.php?showH='+showH+'&showW='+showW+'&ie6=N&email='+email, 'monoSlideshow');

		}
	}

}

function submitSearch() {

	// fields: searchterm, restrict
	var searchtermVal,restrictVal;
	
	searchtermVal = document.searchForm.searchterm.value;
	restrictVal =document.searchForm.restrict.value;
	
	searchSterm = searchtermVal;
	searchRestrict = restrictVal;
	searchOffset = 0;
	searchThumbDisplay = 'true';
	searchStart = 'sets';
	searchClientID = -1;
		
	showReturnToSearch();

	document.getElementById('photoSetName').innerHTML = ''; 

	getData('showSearchResults.php?showH='+showH+'&showW='+showW+'&searchterm='+searchtermVal+'&restrict='+restrictVal, 'monoSlideshow');

}



function submitSearchTag(tagTerm) {

	//var returnToClass = (backgroundColor == 'ffffff')? 'returnToSearchGray' : 'returnToSearchWhite';
	document.getElementById('photoSetName').innerHTML = ''; 
	//document.getElementById('returnToSearch').innerHTML = "<a href=\"javascript:switchPageSearchResults('" +tagTerm + "', 'any', 0, 'true','sets');\" class=\""+returnToClass+"\">< Return to search results</a>";

	searchSterm = tagTerm;
	searchRestrict = 'any';
	searchOffset = 0;
	searchThumbDisplay = 'true';
	searchStart = 'sets';
	searchClientID = -1;
		
	showReturnToSearch();

	getData('showSearchResults.php?showH='+showH+'&showW='+showW+'&searchterm='+tagTerm, 'monoSlideshow');

}

function submitSearchClient(clientID) {

	document.getElementById('photoSetName').innerHTML = ''; 

	searchSterm = '';
	searchRestrict = 'any';
	searchOffset = 0;
	searchThumbDisplay = 'true';
	searchStart = 'sets';
	searchClientID = clientID;
		
	showReturnToSearch();

	getData('showSearchResults.php?showH='+showH+'&showW='+showW+'&client_id='+clientID, 'monoSlideshow');

}


function addToMySets() {

	var confirmMessage = (current_galleryID > 0)? 'Add this set to "My Sets"?' : 'Add this photo to "My Sets"?'; 
	
	if (confirm(confirmMessage)) {
	
		// Display 'saving' alert box when needed
		document.getElementById('savingAlert').innerHTML = '<span class="savingAlert">Saving...</span>';
		
		getData('addtomysets.php?user_id='+user_id+'&gallery_id='+current_galleryID+'&photo_id='+photoIDToStart, 'savingAlert');
		
	}

}

function returnToAlbum(photoIDForReturn) {

	photoIDToStart = photoIDForReturn;
	switchAlbum(current_album,current_galleryID);

}

function returnToPhoto(photoIDForReturn) {

	photoIDToStart = photoIDForReturn;
	current_galleryID = -1;
	switchAlbum(current_album,current_galleryID);

}

function switchAlbum(album,galleryID) {

	// Add bottom rule on monoslideshow
	document.getElementById('monoSlideshow').style['borderBottom'] = '1px solid #999999';

	// Update nextPrev array
	if (nextPrevIndex < 0) {
	
		nextPrevIndex = nextPrev.push(galleryID) - 1;
		nextPrevCurIndex++;
		

	} else if (galleryID != nextPrev[nextPrevCurIndex]) {
	
		// if this is a different gallery than the current selected OR the one selected through next and previous
		// then add it to the end of the array, removing everything else in the array. 
		// if this just a set to add to the array, i.e. nextPrevCurIndex == nextPrevIndex, then do so.
		if (nextPrevCurIndex == nextPrevIndex) {
		
			nextPrevIndex = nextPrev.push(galleryID) - 1;
			nextPrevCurIndex++;

		} else {
		
			nextPrev.splice(nextPrevCurIndex+1,nextPrevIndex-nextPrevCurIndex,galleryID);
			nextPrevIndex = nextPrev.length - 1;
			nextPrevCurIndex = nextPrevIndex;		
		}
	}
		
	// Update previous button
	if (nextPrevCurIndex > 0) {
	
		// display previous button
		document.getElementById('navpanel0a').innerHTML = '<a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'prevPage\',\'\',\'images/prev_page_on'+imageSuffix+'\',1)" onclick="gotoPrev();" id="prevPageButton" title="Previous Set"><img src="images/prev_page_off'+imageSuffix+'" width="29" height="25" border="0" name="prevPage"></a>';

	} else {
	
		document.getElementById('navpanel0a').innerHTML = '<img src="images/prev_gray'+imageSuffix+'" width="29" height="25" border="0">';	
	
	}
	
	var nextPageID=(user_id > 0)? "a" : "b" ;
	nextPageID = "navpanel8"+nextPageID ;

	if (nextPrevCurIndex > 0 && (nextPrevCurIndex < nextPrevIndex)) {

		// Display active button. Position depends on whether user is logged in
		document.getElementById(nextPageID).innerHTML = '<a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'nextPage\',\'\',\'images/next_page_on'+imageSuffix+'\',1)" onclick="gotoNext();" id="nextPageButton" title="Next Set"><img src="images/next_page_off'+imageSuffix+'" width="29" height="25" border="0" name="nextPage"></a>';

	} else {
		
		document.getElementById(nextPageID).innerHTML = '<img src="images/next_gray'+imageSuffix+'" width="29" height="25" border="0">';

	}
	
	current_album = album;
	
	// TEST THIS. If the galleryID is different than the current, reset the photoID to start. So far, that is ONLY passed through a link when index.php is first loaded. 
	// THIS WILL CHANGE.
		// Reset photoIDToStart
		
	if (galleryID != current_galleryID) {
	
		photoIDToStart =  -1 ;
		current_galleryID = galleryID;
		
	}
	
	// Fetch PhotoSetName for display if not one of the main categories
	if (galleryID > 4) {
	
		fetchPhotoSetName(galleryID);
	
	} else {
	
		document.getElementById('photoSetName').innerHTML = ''; 

	} 
	
	backgroundColorMain = "#" + backgroundColor;
	
	var motionSetting, thumbnailSetting;
	
	// Update email this set link
	if (galleryID > -1) {
	
		updateEmailSet(galleryID);
		
	} else {
	
		updateEmailImage();
	
	}
	
	motionSetting = (motion)?"true":"false";
	thumbnailSetting = (thumbnailsOn)?"true":"false";
		
	// 'X' is delimiter due to Safari issues with semicolon
	xmlfile="./display.php/NOXgallery_id=" + galleryID + "XshowW=" + showW + "XshowH=" + showH + "Xmotion=" +  motionSetting + "XbackgroundColor=" + backgroundColor + "Xsound=" + soundSetting + "Xstart=" + startWith + "XthumbSize=" + thumbnailSize + "XphotoID=" +photoIDToStart + "XgroupToStart=" + gpToStart;
	
	// For debugging
	//document.getElementById('photoSetName').innerHTML = xmlfile;
	
	// 3/11/08 so.addParam("wmode","transparent"); adding this line to display dialog box on top of the display
	var so = new SWFObject("monoslideshow.swf", "SOmonoSlideshow", showW, showH,  "7", backgroundColorMain);
	so.addVariable("dataFile", xmlfile); 
	so.addVariable("showLogo", "false");
	so.addVariable("showVersionInfo", "false");
	so.addParam("wmode","transparent");
	so.write("monoSlideshow");
	
}

function pickAlbum(choose_album,gallery_ID) {

	if (((choose_album == 'history') || (choose_album == 'mysets')) && (gallery_ID < 5)) {
	
		switch (gallery_ID) {
		
			case '1':
				current_album = "architecture";
				break;
				
			case '2':
				current_album = "advertising";
				break;

			case '3':
				current_album = "food";
				break;
		
			case '4':
				current_album = "people";
				break;
				
			case '5':
				current_album = "books";
				break;
				
			default:
				current_album = choose_album;
				break;	
		}
		
	} else {

		current_album = choose_album;
		
	}
	
	switch (current_album) {
	
		case 'architecture':
			document.getElementById('nav_arch').innerHTML = '<img src="images/nav8_arch_blue'+imageSuffix+'" width="110" height="25" border="0" name="nav_arch"/>';
			document.getElementById('nav_food').innerHTML = '';
			document.getElementById('nav_books').innerHTML = '';
			document.getElementById('nav_people').innerHTML = '';
			document.getElementById('nav_projects').innerHTML = '';
			document.getElementById('nav_advert').innerHTML = '';
			document.getElementById('nav_history').innerHTML = '';
			if (user_id > -1 && error_msg == 0) {

				document.getElementById('nav_mysets').innerHTML = '';
			
			}
			break;
		
		case 'food':
			document.getElementById('nav_food').innerHTML = '<img src="images/nav8_food_blue'+imageSuffix+'" width="61" height="25" border="0" name="nav_food"/>';
			document.getElementById('nav_arch').innerHTML = '';
			document.getElementById('nav_books').innerHTML = '';
			document.getElementById('nav_people').innerHTML = '';
			document.getElementById('nav_projects').innerHTML = '';
			document.getElementById('nav_advert').innerHTML = '';
			document.getElementById('nav_history').innerHTML = '';
			if (user_id > -1 && error_msg == 0) {

				document.getElementById('nav_mysets').innerHTML = '';
			
			}
			break;
		
		case 'people':
			document.getElementById('nav_people').innerHTML = '<img src="images/nav8_people_blue'+imageSuffix+'" width="73" height="25" border="0" name="nav_people"/>';
			document.getElementById('nav_arch').innerHTML = '';
			document.getElementById('nav_books').innerHTML = '';
			document.getElementById('nav_food').innerHTML = '';
			document.getElementById('nav_projects').innerHTML = '';
			document.getElementById('nav_advert').innerHTML = '';
			document.getElementById('nav_history').innerHTML = '';
			if (user_id > -1 && error_msg == 0) {

				document.getElementById('nav_mysets').innerHTML = '';
			
			}
			break;
		
		case 'advertising':
			document.getElementById('nav_advert').innerHTML = '<img src="images/nav8_advert_blue'+imageSuffix+'" width="103" height="25" border="0" name="nav_advert"/>';
			document.getElementById('nav_arch').innerHTML = '';
			document.getElementById('nav_books').innerHTML = '';
			document.getElementById('nav_food').innerHTML = '';
			document.getElementById('nav_projects').innerHTML = '';
			document.getElementById('nav_people').innerHTML = '';
			document.getElementById('nav_history').innerHTML = '';
			if (user_id > -1 && error_msg == 0) {

				document.getElementById('nav_mysets').innerHTML = '';
			
			}
			break;
		
	
		case 'mysets':
			document.getElementById('nav_advert').innerHTML = '';
			document.getElementById('nav_arch').innerHTML = '';
			document.getElementById('nav_food').innerHTML = '';
			document.getElementById('nav_books').innerHTML = '';
			document.getElementById('nav_people').innerHTML = '';
			document.getElementById('nav_projects').innerHTML = '';
			document.getElementById('nav_mysets').innerHTML = '<img src="images/nav8_mysets_blue'+imageSuffix+'" width="76" height="25" border="0" name="nav_mysets"/>';
			document.getElementById('nav_history').innerHTML = '';
			break;
			
		case 'projects':
			document.getElementById('nav_advert').innerHTML = '';
			document.getElementById('nav_arch').innerHTML = '';
			document.getElementById('nav_books').innerHTML = '';
			document.getElementById('nav_food').innerHTML = '';
			document.getElementById('nav_people').innerHTML = '';
			document.getElementById('nav_projects').innerHTML = '<img src="images/nav8_projects_blue'+imageSuffix+'" width="79" height="25" border="0" name="nav_projects"/>';
			if (user_id > -1 && error_msg == 0) {

				document.getElementById('nav_mysets').innerHTML = '';
			}
			break;
		
		case 'books':
			document.getElementById('nav_advert').innerHTML = '';
			document.getElementById('nav_arch').innerHTML = '';
			document.getElementById('nav_books').innerHTML = '<img src="images/nav8_books_blue'+imageSuffix+'" width="61" height="25" border="0" name="nav_projects"/>';
			document.getElementById('nav_food').innerHTML = '';
			document.getElementById('nav_people').innerHTML = '';
			document.getElementById('nav_projects').innerHTML = '';
			if (user_id > -1 && error_msg == 0) {

				document.getElementById('nav_mysets').innerHTML = '';
			}
			break;

		default:
			document.getElementById('nav_advert').innerHTML = '';
			document.getElementById('nav_arch').innerHTML = '';
			document.getElementById('nav_books').innerHTML = '';
			document.getElementById('nav_food').innerHTML = '';
			document.getElementById('nav_people').innerHTML = '';
			document.getElementById('nav_projects').innerHTML = '';
			if (user_id > -1 && error_msg == 0) {

				document.getElementById('nav_mysets').innerHTML = '';
			}
			break;

	}

	switchAlbum(current_album,gallery_ID);

}

function pickMotion(choose_motion) {

	motion = (choose_motion == "motion" ? true : false);
	switchAlbum(current_album,current_galleryID);

}


function setSound(soundToggle) {

	// soundToggle is "on" or "off"
	soundSetting = soundToggle;
	switchAlbum(current_album,current_galleryID);

}

function setStartWith(startToggle) {

	// startToggle is "photos", "photothumbs" or "thumbs"
	startWith = startToggle;
	switchAlbum(current_album,current_galleryID);
	
}


function pickBackground(choose_background) {

	backgroundColor = choose_background;
	setBodyColor();		
	
	// Update search results if exist
	if (searchSterm != '') {
	
		showReturnToSearch();
		
	}
	switchAlbum(current_album,current_galleryID);
}

function setThumbSize(newThumbSize) {

	thumbnailSize = newThumbSize;
	switchAlbum(current_album,current_galleryID);

}

function setThumbnails(thumbsetting) {

	thumbnailsOn = (thumbsetting == "on")?true:false;
	switchAlbum(current_album,current_galleryID);
	
}

function setNav() {

	// This function is deprecated. Remove in next revision.
	var navToggle;
	
	switch (backgroundColor) {
	
		case "ffffff":
			navToggle = "b";
			break;
			
		case "333333":
			navToggle = "c";
			break;
			
		default:
			navToggle = "a";
			break;
	
	}

	navToggle = "a";

    var navHTML = '<li id="navpanel9a"><a href="#" id="nav_books" onclick="pickAlbum(\'books\',5);"></a></li>\n';
    navHTML += '<li id="navpanel1a"><a href="#" id="nav_arch" onclick="pickAlbum(\'architecture\',1);"></a></li>\n';
	navHTML += '<li id="navpanel2a"><a href="#" id="nav_food" onclick="pickAlbum(\'food\',3);"></a></li>\n';
	navHTML += '<li id="navpanel3a"><a href="#" id="nav_people" onclick="pickAlbum(\'people\',4);"></a></li>\n';
	navHTML += '<li id="navpanel4a"><a href="#" id="nav_advert"></a></li>\n';
	navHTML += '<li id="navpanel5a"><a href="#" id="nav_projects" onmousedown="showProjects();"></a></li>\n';
	navHTML += '<li id="navpanel6a"><a href="#" id="nav_history" onmousedown="showHistory();"></a></li>';

	// if user is logged in, display the mysets link
	if (user_email != "" && error_msg == 0) {
		
		navHTML += '<li id="navpanel7a"><a href="#" id="nav_mysets"  onmousedown="showMysets();"></a></li>\n';
	
	}
			 	
	document.getElementById('naviconmenu').innerHTML = navHTML;

}

function swaplayers() {

	document.getElementById('controlbuttons1').style.visibility = "visible";

}

function swapback() {

	document.getElementById('controlbuttons1').style.visibility = "hidden";

}

// IE6
function swapmenu() {

	if (user_id > -1 ) {
	
		document.getElementById('toolsMenu').style.visibility = "visible";
		
	} else {	
	
		document.getElementById('toolsMenuLogin').style.visibility = "visible";

	}
}

// IE6
function swapmenuback() {

	if (user_id > -1 ) {
	
		document.getElementById('toolsMenu').style.visibility = "hidden";
		
	} else {	
	
		document.getElementById('toolsMenuLogin').style.visibility = "hidden";

	}

}

function updateVar(newBackground) {

	// IE6 requires a reload to change background and load the matching jpgs. 
	// All other browsers can change background without a reload
	document.getElementById('backgroundToPass').value = (newBackground == null)?backgroundColor:newBackground;
	document.getElementById('galleryIDToPass').value = current_galleryID;
	document.getElementById('motionToPass').value = (motion ? "true" : "false");
	document.getElementById('thumbnailSettingToPass').value = thumbnailsOn;
	document.getElementById('thumbnailSizeToPass').value = thumbnailSize;
	document.getElementById('soundSettingToPass').value = soundSetting;
	document.getElementById('startWithToPass').value = startWith;

	// Update history variable to pass with fit to window
	document.getElementById('historyList').value = nextPrev.toString();
	document.getElementById('nextPrevToPass').value = nextPrevCurIndex;

}

function updateEmailSet(gallery_ID) {

	// IE6 uses gif, others use png
	var suffix,ie6toggle;
	
	if (explorer6 == true) {
	
		suffix = "gif";
		ie6toggle = "Y";
		
	} else {
	
		suffix = "png";
		ie6toggle = "N";
		
	} 
	
	// Update email tag and, if applicable, download tag
	var tag1,tag2;

	// Version 1: open in new window
	tag1 = '<a href="email_link.php?ie6='+ie6toggle+'&gallery_id=';
	tag2 = '" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'nav_tools_email\',\'\',\'images//nav6_email_on.'+suffix+'\',1)" onclick="displayWindow(\'\',720,640)" target="displayWindow"><img src="images/nav6_email_off.'+suffix+'" width="80" height="14" border="0" name="nav_tools_email"></a>';

	// Version 2: thickbox
	//tag1 = '<a href="email_link_thickbox.php?height=720&width=640&ie6='+ie6toggle+'&gallery_id=';

	//tag1 = '<a href="http://jquery.com/demo/thickbox/images/plant1.jpg?height=600&width=800&gallery_id=';
	//tag1 = '<a href="email_link_thickbox.php?keepThis=true&modal=true&height=620&width=640&ie6='+ie6toggle+'&gallery_id=';
	//tag2 = '&TB_iframe=true" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'nav_tools_email\',\'\',\'images//nav6_email_on.'+suffix+'\',1)" class="thickbox" ><img src="images/nav6_email_off.'+suffix+'" width="80" height="14" border="0" name="nav_tools_email"></a>';

	document.getElementById('emailSet').innerHTML = tag1 + gallery_ID + tag2;
	
	if (allow_downloads == "Y") {
	
		tag1 = '<a href="download.php?ie6='+ie6toggle+'&gallery_id=';
		tag2 = '" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'nav_tools_download\',\'\',\'images/nav6_download_on.'+suffix+'\',1)" onclick="displayWindow(\'\',720,640)" target="displayWindow"><img src="images/nav6_download_off.'+suffix+'" width="80" height="14" border="0" name="nav_tools_download"></a>';

		document.getElementById('downloadSet').innerHTML = tag1 + gallery_ID + tag2;

	}
	
	// Update add to sets, too:
	
	if (user_email != "") {
	
		// photoID is important if only a single image is displayed.
		tag1 = '<a href="addToMySets.php?ie6='+ie6toggle+'&gallery_id=';
		tag2 = '" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'nav_tools_addToSets\',\'\',\'images/nav6_addtosets_on.'+suffix+'\',1)" onclick="displayWindow(\'\',720,640)" target="displayWindow"><img src="images/nav6_addtosets_off.'+suffix+'" width="80" height="14" border="0" name="nav_tools_addToSets"></a>';
	
		document.getElementById('addToSet').innerHTML = tag1 + gallery_ID +'&photo_id='+photoIDToStart + tag2;
	
	}
}

function updateEmailImage() {

	// IE6 uses gif, others use png
	var suffix,ie6toggle;
	
	if (explorer6 == true) {
	
		suffix = "gif";
		ie6toggle = "Y";
		
	} else {
	
		suffix = "png";
		ie6toggle = "N";
		
	} 
	
	// Update email tag and, if applicable, download tag
	var tag1,tag2;

	tag1 = '<a href="email_image.php?ie6='+ie6toggle+'&photo_id=';
	tag2 = '" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'nav_tools_email\',\'\',\'images//nav6_email_on.'+suffix+'\',1)" onclick="displayWindow(\'\',720,640)" target="displayWindow"><img src="images/nav6_email_off.'+suffix+'" width="80" height="14" border="0" name="nav_tools_email"></a>';

	document.getElementById('emailSet').innerHTML = tag1 + photoIDToStart + tag2;
	
	/*
		NOTE: This does not yet work for downloading a single image. 5/13/08
	*/
	
	if (allow_downloads == "Y") {
	
		tag1 = '<a href="download.php?ie6='+ie6toggle+'&gallery_id=';
		tag2 = '" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'nav_tools_download\',\'\',\'images/nav6_download_on.'+suffix+'\',1)" onclick="displayWindow(\'\',720,640)" target="displayWindow"><img src="images/nav6_download_off.'+suffix+'" width="80" height="14" border="0" name="nav_tools_download"></a>';

		//document.getElementById('downloadSet').innerHTML = tag1 + gallery_ID + tag2;
		document.getElementById('downloadSet').innerHTML = tag1 + '-1' + tag2;

	}

	if (user_email != "") {

		// Update add to sets, too:
		// photoID is important if only a single image is displayed.
		tag1 = '<a href="addToMySets.php?ie6='+ie6toggle+'&gallery_id=';
		tag2 = '" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'nav_tools_addToSets\',\'\',\'images/nav6_addtosets_on.'+suffix+'\',1)" onclick="displayWindow(\'\',720,640)" target="displayWindow"><img src="images/nav6_addtosets_off.'+suffix+'" width="80" height="14" border="0" name="nav_tools_addToSets"></a>';
	
		document.getElementById('addToSet').innerHTML = tag1 + '-1&photo_id='+photoIDToStart + tag2;

	}
}

function setBodyColor() {
	
   document.bgColor= '#'+backgroundColor;  
   
   // Set copyright display image

	// determine copyright to display

	if (explorer6 == false) {
	
		if (backgroundColor == "ffffff") {
		
			copyrightImage = "copyright_andyryan_black.png";
			
		} else {
		
			copyrightImage = "copyright_andyryan_white.png";
		
		}
	
	} else {
	
		copyrightImage = "copyright_andyryan" + imageSuffix;

	}

	document.getElementById('copyrightImage').innerHTML = '<img src="images/' + copyrightImage + '" width="231" height="12">';
	
}

function addcomma(msg) {

	if (msg != "") {

		return msg + ", ";

	} else {

		return msg;
	}
	
}


function verifyLogin(passForm) {

	if (passForm.email.value == "") {
	
		alert("You must enter an email address");
		passForm.email.focus();
		return false;
		
	}

}

function verifyLoginRequest() {

	// This is a variation of an open source field verification function
	myForm = document.loginRequestForm;
	
	var themessage = "";
	var count = 0;
	if (myForm.firstname.value=="") {
		themessage = themessage + "First Name";
		count = count + 1;
	}
	if (myForm.lastname.value=="") {
		themessage = addcomma(themessage);
		themessage = themessage + "Last Name";
		count = count + 1;
	}
	if (myForm.email.value=="") {
		themessage = addcomma(themessage);
		themessage = themessage + "E-mail";
		count = count + 1;
	}
	
	//alert if fields are empty, then cancel form submit
	if (themessage == "") {
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.email.value)){				
			return (true)
		} else {
			alert("There is an error in the e-mail address. Please re-enter.");
			return (false)
		}
	}
	else {
		if (count > 1) {
			var field_text = "these fields: ";
		} else {
			var field_text = "this field: ";
		}
		alert("You are required to enter " + field_text + themessage);
		return false;
	}
}


function gotoNext() {

	if (nextPrevCurIndex < nextPrevIndex) {
	
		nextPrevCurIndex++;
		switchAlbum(current_album,nextPrev[nextPrevCurIndex]);
		
	} else {
	
		alert("There is no next set.");
		
	}

}


function gotoPrev() {

	if (nextPrevCurIndex > 0) {
	
		nextPrevCurIndex--;
		switchAlbum(current_album,nextPrev[nextPrevCurIndex]);
		
	} else {
	
		alert("There is no previous set.");
		
	}

}

var gpToStart = gpd;

// Following four functions are open source
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function displayWindow(url, width, height) {

	if (!window.Win || Win.closed) {
	
		var Win = window.open(url,"displayWindow",'width=' + width + ',height=' + height + ',resizable=1,scrollbars=1' );
	
	} else {
	
		Win.location = url;
	}
	
	Win.focus();
		
}


