function getAlbums()
{
	engAlbum.getAlbumsForDropDown(loadEditAlbums);
}

function GetNavigationImage(PhotoID,navigation)
{
	//engAlbumPhotos.NavigatePhotos(PhotoID,navigation,callback_GetnextImage);
	engAlbumPhotos.NavigatePhotosWithDetails(PhotoID,navigation,callback_GetnextImage);
}

function callback_GetnextImage(res)
{
	//window.location='/myPhotos/photo.aspx';
	var pDiv = $('photodetailcontent');
	if (pDiv)
		pDiv.innerHTML = res.value;
}

loadEditAlbums = function(res)
{
	checkResponse(res.value);
	var control = document.getElementById("ddEditAlbum");
	control.innerHTML = "";
	var dt = res.value;
	
	
	for (var i=0; i<dt.Rows.length; i++)
	{
		var opt = document.createElement("option");
		opt.innerHTML = dt.Rows[i].Album_Title;
		opt.value = dt.Rows[i].Album_ID;
		
		control.appendChild(opt)
	}
}

function appendTimeStamp(url)
{
	// Ben 20071214 - causes resizeImage() side effect in FF
	var now = new Date();
	return url + '?' + now.getTime();
	//return url;
}

function showEditPhoto(itemID)
{
	setSpanValue('editPhotoID', itemID);
	engAlbumPhotos.populatePhotoDetails(itemID, callback_showEditPhoto);
}

function showRotatePhoto(itemID)
{
	setSpanValue('rotatePhotoID', itemID);
	openModalWindow('rotatePhoto');
}

function LoadAlbumImages()
{
	createModel();
	var photodiv=document.getElementById("photoslide");	
	photodiv.style.display="block";	
	var Navigation=document.getElementById("AlbumNavigation");	
	Navigation.style.display="block";
	engAlbumPhotos.GetPhotosByAlbumID(callback_loadAlbumPhotos);	
}
function Loadrss()
{
	createModel();
	closeBackground();	
	var photodiv=document.getElementById("photoslide");	
	photodiv.style.display="none";
	var navigation=document.getElementById("AlbumNavigation");	
	navigation.style.display="none";
	openModalWindow('album_rss1');
}

function LoadAlbumPhotoImagesByPhotoID(PhotoID)
{
	createModel();		
	engAlbumPhotos.GetAlbumPhotosByPhotoID(callback_loadAlbumPhotosByPhotoID);	
}
function callback_loadAlbumPhotosByPhotoID(res)
{
	if (res.error!=null){alert(res.error)};
	checkResponse(res.value);
	var dt = res.value;
	var photodiv=document.getElementById("photoslide");	
	var PhotoId=getSpanValue('commentPhotoID');
	var imageArray=new Array(dt.Rows.length);
	var slidetext=new Array(dt.Rows.length);	
	for (var i=0; i<dt.Rows.length; i++)
	{
		imageArray[i]=dt.Rows[i].ImageFileName;
		slidetext[i]=dt.Rows[i].Caption;
	}
	InitilizeSlideshow();
	addimagestolist(imageArray,slidetext);
	first_image();
	
	photodiv.style.display="block";
	photodiv.style.padding="10px";
}

function CloseSliding()
{
	document.getElementById('photoAlbum').style.display="none";	
	document.getElementById('AlbumNavigation').style.display="none";
	document.getElementById('pageTitle').style.display="block";
	closeModalwindow('photoAlbum');
	closeBackground();	
}

function Loadfornewphoto()
{
	//closeBackgroundall();
	var photodiv=document.getElementById("photoslide");	
	photodiv.style.display="none";	
	//openModalWindow('album_rss1');
	openModalWindow('fileNew');
}

function callback_loadAlbumPhotos(res)
{
	if (res.error!=null){alert(res.error)};
	checkResponse(res.value);
	var dt = res.value;
	var photodiv=document.getElementById("photoslide");	
	var imageArray=new Array(dt.Rows.length);
	var slidetext=new Array(dt.Rows.length);
	for (var i=0; i<dt.Rows.length; i++)
	{
		imageArray[i]=dt.Rows[i].ImageFileName;
		slidetext[i]=dt.Rows[i].Caption;
	}
	InitilizeSlideshow();
	addimagestolist(imageArray,slidetext);
	first_image();
	
	photodiv.style.display="block";
	photodiv.style.padding="10px";
}

function ViewIamge(ImageFileName,Caption)
{
	//var ulphoto = document.createElement("ul");
	//ulphoto.id="auto-size2-ul";
	
	//var liphoto=document.createElement("li");
	
	var imgphoto=document.createElement("img");
	imgphoto.src=ImageFileName;		
	imgphoto.alt=Caption;
	
	//liphoto.appendChild(imgphoto);
	
	//ulphoto.appendChild(liphoto);

	return imgphoto;
}

function NextImage(res)
{
	var dt = res.value;
	
}


function callback_showEditPhoto(res)
{
	checkResponse(res.value);

	var dt = res.value;
	if (dt.Rows[0].Caption!=null)
	{
		setControlValue('txtCaption', dt.Rows[0].Caption);	
	}
	else
	{
		setControlValue('txtCaption', "");
	}
		
	if (dt.Rows[0].Photo_Location!=null)
	{
		setControlValue('txtLocation', dt.Rows[0].Photo_Location);
	}
	else
	{
		setControlValue('txtLocation', "");
	}
		
	if (dt.Rows[0].Photo_Photog!=null)
	{
		setControlValue('txtPhotographer', dt.Rows[0].Photo_Photog);	
	}
	else
	{
		setControlValue('txtPhotographer', "");
	}

	//alert(dt.Rows[0].Photo_Date);
	//alert(dt.Rows[0].Photo_Time);
	
	if (dt.Rows[0].Photo_Date!=null)
	{
		
		var tDateParts = dt.Rows[0].Photo_Date.split('/');

		var tDay = $('ddPhotoDay');
		if (tDay && tDateParts.length > 0)
			for(var ii=0; ii < tDay.length; ii++)
				if (tDay[ii].value == tDateParts[0])
					tDay.selectedIndex = ii;
					
		var tMonth = $('ddPhotoMonth');
		if (tMonth && tDateParts.length > 1)
			for(var ii=0; ii < tMonth.length; ii++)
				if (tMonth[ii].value == tDateParts[1])
					tMonth.selectedIndex = ii;
					
		var tYear = $('txtPhotoYear');
		if (tYear && tDateParts.length > 2)
			tYear.value = tDateParts[2]
	}
	/*		
	if (dt.Rows[0].Photo_Date!=null)
	{
		setControlValue('txtDate', dt.Rows[0].Photo_Date);
	}
	else
	{
		setControlValue('txtDate', "");
	}
	*/
	if (dt.Rows[0].Photo_Time!=null)
	{
		var tTimeParts = dt.Rows[0].Photo_Time.split(':');
		
		var tHour = $('ddTimeHour');
		if (tHour && tTimeParts.length > 0)
			for(var ii=0; ii < tHour.length; ii++)
				if (tHour[ii].value == tTimeParts[0])
					tHour.selectedIndex = ii;
					
		var tMinute = $('ddTimeMinute');
		if (tMinute && tTimeParts.length > 1)
			for(var ii=0; ii < tMinute.length; ii++)
				if (tMinute[ii].value == tTimeParts[1])
					tMinute.selectedIndex = ii;					
	}
	/*	
	if (dt.Rows[0].Photo_Time!=null)
	{
		setControlValue('txtTime', dt.Rows[0].Photo_Time);
	}
	else
	{
		setControlValue('txtTime', "");
	}*/
		
	// Ben 20071214
	if (dt.Rows[0].tagEditList!=null || dt.Rows[0].tagEditList!='')
	{
		setControlValue('txtTags', dt.Rows[0].tagEditList);
	}
	else
	{
		setControlValue('txtTags', "");
	}
	
	setDropDownSelected('ddEditAlbum', dt.Rows[0].Album_ID);
	
	setSelectedRadioValue('radRotate', 0);
	
	var img = document.getElementById("editPhotoThumbnail");
	img.src = appendTimeStamp(dt.Rows[0].srcThumb);
	if((img.offsetWidth>100)||(img.offsetHeight>80))
	{
		if (img.offsetWidth >= img.offsetHeight)
		{
			img.style.width='100px';
		}
		else
		{
			img.style.height='80px';
		}
	}
	
	openModalWindow('editPhoto');
}

function updaterotatePhoto()
{
	var photoID = getSpanValue('rotatePhotoID');
	var rotate = getSelectedRadioValue('radRotate');
	
	showFeedback('rotatePhotoActionContainer');
	engAlbumPhotos.saveRotatePhoto(photoID,rotate,callback_rotatephoto);
}

function callback_rotatephoto(res)
{
	checkResponse(res.value);
	if (res.error!=null){alert(res.error)};
	if (res.value)
	{
		feedbackValid('Saving','Saved');
		//resizeImage();
		//sniffForBodyLoad();
		//cleanupFeedback('rotatePhotoActionContainer');
		//window.setTimeout("hideRotate()",1000);
		window.setTimeout("document.location = '/myPhotos/photo.aspx';", 1000);
	}
	else
	{
		feedbackInvalid('rotatePhotoActionContainer');
	}	
}



function hideRotate()
{
	closeModalWindow('rotatePhoto');
}

function updatePhoto()
{
	var photoID = getSpanValue('commentPhotoID');
			
	updatePhotoDetails(photoID);
}

function updatePhotoDetails(itemID){

	var caption = getControlValue("txtCaption");
	var location = getControlValue("txtLocation");
	var photographer = getControlValue("txtPhotographer");
	
	var tDay = getControlValue("ddPhotoDay");
	var tMonth = getControlValue("ddPhotoMonth");
	var tYear =  getControlValue("txtPhotoYear");
	
	if (tDay.length > 0 && tMonth.length > 0 && tYear.length > 0)
		var photo_date = tDay + '/' + tMonth + '/' + tYear;
	else
		var photo_date = '';
	
	var tHour = getControlValue("ddTimeHour");
	var tMinute = getControlValue("ddTimeMinute");
	var tDate =  new Date();
	var tSecs = tDate.getSeconds();
	var tMilli = tDate.getMilliseconds();
	if (tHour.length > 0 && tMinute.length > 0)
		var photo_time = tHour + ':' + tMinute + ':' + tSecs + ":"+tMilli;
	else
		var photo_time = '';
	
	//var photo_date = getControlValue("txtDate");
	//var photo_time = getControlValue("txtTime");
	//var photo_theme = getControlValue("txtTheme");
	var tagList = getControlValue("txtTags");
	var itemID = getSpanValue('editPhotoID');
	var albumID = getDropDownSelected('ddEditAlbum');
	//var rotate = getSelectedRadioValue('radRotate');	
	var rotate =0;
	showFeedback('editPhotoActionContainer');
	engAlbumPhotos.editPhoto(itemID, caption, location, photographer, photo_date, photo_time, tagList,'',albumID, rotate, callback_updatePhoto);
}

function callback_updatePhoto(res)
{
	checkResponse(res.value);
	if (res.error!=null){alert(res.error)};
	if (res.value)
	{
		feedbackValid('Saving','Saved');
		window.setTimeout("hideUpdatePhoto();", 4000);
	}
	else
	{
		feedbackInvalid('editPhotoActionContainer');
	}	
}
 function hideUpdatePhoto()
 {
	clearInputField('txtCaption');
	clearInputField('txtLocation');		
	clearInputField('txtPhotographer');
	
	clearInputField('ddPhotoDay');
	clearInputField('ddPhotoMonth');
	clearInputField('txtPhotoYear');
	
	clearInputField('ddTimeHour');
	clearInputField('ddTimeMinute');
	
	clearInputField('txtTags');
	
	//var pageNum = getSpanValue('currPageNum');
	//loadPage(pageNum);
		
	closeModalWindow('editPhoto');	
	//document.location = '/myPhotos/photo.aspx';
	//cleanupFeedback('editPhotoActionContainer');
	//testing 20071112
	window.setTimeout("document.location = '/myPhotos/photo.aspx';", 1000);
 }

function showDeleteBatch(){
	createModel();
	closeBackground();
	var photodiv=document.getElementById("photoslide");	
	photodiv.style.display="none";

	var controls = new Array();
	var cont = document.getElementsByTagName("input");
	var counter = 0;
	
	for (var i=0; i<cont.length; i++)
	{
		if (cont[i].type == "checkbox")
		{
			if (cont[i].checked)
			{
			
			controls[counter] = cont[i].value;
			counter = counter + 1;
			}
		}
	}
	
	setSpanValue('removePhotoBatchCount',controls.length);
	if(controls.length == 0)
	{
		setControlDisplay('selectbatch','block');
		setControlDisplay('deletebatch','none');
		
	}
	else
	{
		setControlDisplay('deletebatch','block');
		setControlDisplay('selectbatch','none');
		
	}
	openModalWindow('removePhotoBatch');
	
}
 

function deleteSelectedPhotos(){
	var controls = new Array();
	var cont = document.getElementsByTagName("input");
	var counter = 0;
	
	for (var i=0; i<cont.length; i++)
		{
		if (cont[i].type == "checkbox")
			{
			if (cont[i].checked)
				{
				
				controls[counter] = cont[i].value;
				counter = counter + 1;
				}
			}

		}
		
	showFeedback('deletePhotoBatchActionContainer');
	engAlbumPhotos.deleteSelectedPhotos(controls, callback_deleteSelectedPhotos);
}

function callback_deleteSelectedPhotos(res)
{
	if (res.error!=null){alert(res.error)};
	if (res.value)
	{
		feedbackValid('Deleting','Deleted');
		window.setTimeout("hideRemoveBatchPhotos();", 2000);		
	}
	else
	{
		feedbackInvalid('deletePhotoBatchActionContainer');
	}	
}

function hideRemoveBatchPhotos()
{
	cleanupFeedback('deletePhotoBatchActionContainer');		
	var pageNum = getSpanValue('currPageNum');
	closeModalWindow('removePhotoBatch');
	//loadPage(pageNum);
	window.setTimeout("window.location='/myPhotos/photoAlbum.aspx';", 2000);
}


function showRemovePhoto(itemID)
{
	engAlbumPhotos.populatePhotoDetails(itemID, callback_showRemovePhoto);
}

function callback_showRemovePhoto(res)
{
	checkResponse(res.value);

	var dt = res.value;
	setSpanValue('removePhotoID', dt.Rows[0].Photo_ID);
	setSpanValue('removePhotoComments', dt.Rows[0].Comments);
	var img = document.getElementById("deletePhotoThumbnail");
	img.src = appendTimeStamp(dt.Rows[0].src);
	img.alt = dt.Rows[0].Caption;
	openModalWindow('removePhoto');
}	

function deletePhoto(){
	var photoID = getSpanValue('removePhotoID');
	showFeedback('deletePhotoActionContainer');
	engAlbumPhotos.removePhoto(photoID, callback_deletePhoto);
}

function callback_deletePhoto(res)
{
	checkResponse(res.value);
	if (res.value)
	{
		feedbackValid('Deleting','Deleted');
		window.setTimeout("hideRemovePhoto();",4000);
	}
	else
	{
		feedbackInvalid('deletePhotoActionContainer');
	}
}

function hideRemovePhoto()
{
	//var pageNum = getSpanValue('currPageNum');
	//loadPage(pageNum);
	closeModalWindow('removePhoto');
	cleanupFeedback('deletePhotoActionContainer');
	window.setTimeout("document.location = '/myPhotos/photoAlbum.aspx'", 1000);
}


function updateProfilePhoto(itemID){
	engAlbumPhotos.setNewProfilePhoto(itemID, callback_updateProfilePhoto);
}

function callback_updateProfilePhoto(res)
{
	if (res.value == "failed")
	{
		alert('profile photo was not updated');
	}
	else
	{
		//var pageNum = getSpanValue('currPageNum');
		//loadPage(pageNum);
		window.setTimeout("document.location = '/myPhotos/photo.aspx';", 800);
	}
}


function loadPages(){
	loadPage(1);
}

function showAllPages(){

var tbl = document.getElementById("tblPhotos");
	var rows = tbl.rows; 
    while(rows.length) // length=0 -> stop 
		{
		tbl.deleteRow(rows.length-1);
		}
	var insertTable = document.createElement("tr");
	tbl.appendChild(insertTable);
								
	//<img id="processLoadingPhotos" src="/images/indicators/processing_small.gif" alt="" /><span>&nbsp;Loading&#8230;</span>
	var tblCell1 = insertTable.insertCell(0)
	tblCell1.colSpan = "4";
	
	var img = document.createElement("img");
	img.src = "/images/indicators/processing_small.gif";
	
	var span = document.createElement("span");
	span.innerHTML = "&nbsp;Loading&#8230;";
	
	tblCell1.appendChild(img);
	tblCell1.appendChild(span);
					

	window.setTimeout("engAlbumPhotos.allPhotosSinglePage(callback_showAllPages);", 1000);
	
 
}

function callback_showAllPages(res){
checkResponse(res.value);
	
	var dt = res.value;
	
	//createPageControls(dt.Rows[0]);
	var ul = document.getElementById("pages");
	ul.innerHTML = "";
	
	var aSplit = document.createElement("a")
	aSplit.href = "javascript:loadPage(1);";
	aSplit.innerHTML = "Split onto separate pages";
	
	var liSplit = document.createElement("li")
	liSplit.className = "showAll";
	liSplit.appendChild(aSplit);
	
	ul.appendChild(liSplit);
	
	var tbl = document.getElementById("tblPhotos");
	var rows = tbl.rows; 
    while(rows.length) // length=0 -> stop 
		{
		tbl.deleteRow(rows.length-1);
		}
		
	if (dt.Rows.length!=0)
		{
			document.getElementById("numOfPhotosDisplayed").style.display = "block";
			document.getElementById("currRows").innerHTML = "1&nbsp;&#8211;&nbsp;" + dt.Rows.length + "&nbsp;";
			document.getElementById("totalRows").innerHTML = dt.Rows.length;
			
			for (var i=0; i<dt.Rows.length; i++)
				{
				
					var insertTable = document.createElement("tr");
					tbl.appendChild(insertTable);
								
					var tblCell1 = insertTable.insertCell(0)
					var tblCell2 = insertTable.insertCell(1)
					var tblCell3 = insertTable.insertCell(2)
					var tblCell4 = insertTable.insertCell(3)
					var tblCell5 = insertTable.insertCell(4)
	
					var spnNumber = document.createElement("span");
					spnNumber.innerHTML = (i + 1);
					
					tblCell1.appendChild(spnNumber);
					tblCell1.className = "imageNumber";
					
					var img = document.createElement("img");
					img.src = appendTimeStamp(dt.Rows[i].src);
					img.id = "img_" + dt.Rows[i].Photo_ID;
					img.alt = dt.Rows[i].Caption;
					img.style.visibility = "hidden";
					//img.style.display = "none";
					
					//if((img.offsetWidth>100)||(img.offsetHeight>80))
					//	{
					//		if (img.offsetWidth >= img.offsetHeight)
					//			{
					//				img.style.width='100px';
					//			}
					//		else
					//			{
					//				img.style.height='80px';
					//			}
					//	}
				
					
					
					var aImg = document.createElement("a");
					aImg.rel = "lightbox[album]";
					aImg.title = dt.Rows[i].Caption;
					aImg.href = dt.Rows[i].srcBig;
					aImg.className = "slide";
					aImg.id = "a_" + dt.Rows[i].Photo_ID;
					
					aImg.appendChild(img);
					
					//tblCell2.appendChild(aImg); // Ben 20071210
					var photoDiv = document.createElement("div");
					photoDiv.style.position = 'relative';
					
					photoDiv.appendChild(aImg);
					tblCell2.appendChild(photoDiv);
					tblCell2.className = "photo";
					
					var dl = document.createElement("dl");
					
					//Description
					var dt1 = document.createElement("dt");
					dt1.className = "description";
					dt1.innerHTML = "Description:";
					
					var dd1 = document.createElement("dd");
					dd1.className = "description";
					dd1.innerHTML = dt.Rows[i].Caption;
					
					dl.appendChild(dt1);
					dl.appendChild(dd1);
					
					//Uploaded Date Time
					var dt2 = document.createElement("dt");
					dt2.innerHTML = "Uploaded:";
					
					var dd2 = document.createElement("dd");
					dd2.innerHTML = dt.Rows[i].Short_Date;
					
					dl.appendChild(dt2);
					dl.appendChild(dd2);
					
					//Date Time
					var dt3 = document.createElement("dt");
					dt3.innerHTML = "Date & Time:";
					
					var dd3 = document.createElement("dd");
					dd3.innerHTML = dt.Rows[i].dateTimeCombo;
					
					dl.appendChild(dt3);
					dl.appendChild(dd3);
					
					//Location
					var dt4 = document.createElement("dt");
					dt4.innerHTML = "Location:";
					
					var dd4 = document.createElement("dd");
					dd4.innerHTML = dt.Rows[i].Photo_Location;
					
					dl.appendChild(dt4);
					dl.appendChild(dd4);

					//Tags
					var dt5 = document.createElement("dt");
					dt5.innerHTML = "Tags:";
					
					var dd5 = document.createElement("dd");
					dd5.innerHTML = dt.Rows[i].tagList == '' ? '&nbsp;' : dt.Rows[i].tagList;
					
					dl.appendChild(dt5);
					dl.appendChild(dd5);
					
					//Photographer
					var dt6 = document.createElement("dt");
					dt6.innerHTML = "Photographer:";
					
					var dd6 = document.createElement("dd");
					dd6.innerHTML = dt.Rows[i].Photo_Photog;
					
					dl.appendChild(dt6);
					dl.appendChild(dd6);
					
					tblCell3.appendChild(dl);
					tblCell3.className = "description";
					
					//Is Avatar
					var spnAvatar; 
					if (dt.Rows[i].Is_Profile != null)
						{
						spnAvatar = document.createElement("span");
						spnAvatar.innerHTML = "This is your profile pic.";
						spnAvatar.className = "isAvatar";
						tblCell3.appendChild(spnAvatar);
						}
					
					
					
					var lblSelect = document.createElement("label");
					lblSelect.innerHTML = "";
					
					var chk = document.createElement("input")
					chk.type = "checkbox";
					chk.id = "chk_" + dt.Rows[i].Photo_ID;
					chk.value = dt.Rows[i].Photo_ID;
					
					tblCell4.appendChild(chk);
					tblCell4.className = "downloadSelect";
					
					var ulButtons = document.createElement("ul");
				
					var aEdit = document.createElement("a")
					aEdit.innerHTML = "Edit";
					aEdit.href = "javascript:showEditPhoto(" + dt.Rows[i].Photo_ID + ");";
					
					var liEdit = document.createElement("li");
					liEdit.className = "edit";
					
					liEdit.appendChild(aEdit);
					ulButtons.appendChild(liEdit);
					
					
					var aDelete = document.createElement("a")
					aDelete.innerHTML = "Delete";
					aDelete.href = "javascript:showRemovePhoto(" + dt.Rows[i].Photo_ID + ");";
					
					var liDelete = document.createElement("li");
					liDelete.className = "delete";
					
					liDelete.appendChild(aDelete);
					ulButtons.appendChild(liDelete);
					
					var aComments = document.createElement("a")
					aComments.innerHTML = dt.Rows[i].comments + " comment(s)";
					aComments.href = "javascript:goToPhoto(" + dt.Rows[i].Photo_ID + ");";
					
					var liComment = document.createElement("li");
					liComment.className = "comments";
					
					liComment.appendChild(aComments);
					ulButtons.appendChild(liComment);
					
					var aProfileImg = document.createElement("a");
					aProfileImg.innerHTML = "Set Avatar";
					aProfileImg.href = "javascript:updateProfilePhoto(" + dt.Rows[i].Photo_ID + ");";
					
					var liAvatar = document.createElement("li");
					liAvatar.className = "setAvatar";
					
					liAvatar.appendChild(aProfileImg);
					ulButtons.appendChild(liAvatar);
					
					tblCell5.appendChild(ulButtons);
					tblCell5.className = "options";
					
				}
				
		}
	else
		{
		
		document.getElementById("numOfPhotosDisplayed").style.display = "none";
		var insertTable = document.createElement("tr");
		tbl.appendChild(insertTable);
								
		var tblCell1 = insertTable.insertCell(0)
		tblCell1.colSpan = "5";
		tblCell1.innerHTML = "There are no photos.";
		
		}
		
	sniffForBodyLoad();
	stripetableBody();
	initLightbox();
	window.setTimeout("resizeImages();", 1001);
	//document.getElementById("photoContent").style.display = "block";
	//document.getElementById("processLoadingPhotos").style.display = "none";
	document.getElementById("numOfPhotosDisplayed").style.display = "block";
	//document.getElementById("tblHeadPhotos").style = "";
	
	//window.setTimeout("loadPhotos();", 1000);
}

function loadPage(pageNum){
//alert(pageNum);
	//showProcessor('tblInbox');
	var tbl = document.getElementById("tblPhotos");
	var rows = tbl.rows; 
    while(rows.length) // length=0 -> stop 
		{
		tbl.deleteRow(rows.length-1);
		}
	var insertTable = document.createElement("tr");
	tbl.appendChild(insertTable);
								
	//<img id="processLoadingPhotos" src="/images/indicators/processing_small.gif" alt="" /><span>&nbsp;Loading&#8230;</span>
	var tblCell1 = insertTable.insertCell(0)
	tblCell1.colSpan = "4";
	
	var img = document.createElement("img");
	img.src = "/images/indicators/processing_small.gif";
	
	var span = document.createElement("span");
	span.innerHTML = "&nbsp;Loading&#8230;";
	
	tblCell1.appendChild(img);
	tblCell1.appendChild(span);
					
	//document.getElementById("numOfPhotosDisplayed").style.display = "none";
	
	setSpanValue('currPageNum', pageNum);
	window.setTimeout("engAlbumPhotos.getPhotoPage(" + pageNum + ", callback_loadPage);", 1000);
}

function createPageControls(row){
	var dt = row;
	if (dt.Pages == 1)
		{
		return;
		}
	var ul = document.getElementById("pages");
	ul.innerHTML = "";
	
	var pages = dt.Pages;
	var currP = getSpanValue('currPageNum');
	
	var imgPrev = document.createElement("img");
	imgPrev.src = "/images/arrow_medium_left.gif";
	imgPrev.alt = "Previous";
	
	var aPrev = document.createElement("a");
	aPrev.href = "javascript:loadPage(" + (parseInt(currP) - 1) + ");";
	aPrev.appendChild(imgPrev);
	
	var liPrev = document.createElement("li");
	liPrev.appendChild(aPrev);
	liPrev.className = "previous";
	
	var imgNext = document.createElement("img");
	imgNext.src = "/images/arrow_medium_right.gif";
	imgNext.alt = "Next";
	
	var aNext = document.createElement("a");
	aNext.href = "javascript:loadPage(" + (parseInt(currP) + 1) + ");";
	aNext.appendChild(imgNext);
	
	var liNext = document.createElement("li");
	liNext.appendChild(aNext);
	liNext.className = "next";
	
	var aShowAll = document.createElement("a");
	aShowAll.href = "javascript: showAllPages();";
	aShowAll.innerHTML = "Show all";
	
	var liShowAll = document.createElement("li")
	liShowAll.className = "showAll";
	
	liShowAll.appendChild(aShowAll);
	
	
	if (pages > 1)
			{
			if (getSpanValue('currPageNum') != "1")
				{
				ul.appendChild(liPrev);
				}
			}
			
		//<img src="/images/arrow_medium_left.gif" alt="Previous" />
		
		
	for (var i=0; i<pages; i++)
		{
		
		
		
		var a = document.createElement("a");
		
		a.innerHTML = i + 1;
		
		var li = document.createElement("li");
		
		
		if ((i + 1) == getSpanValue('currPageNum'))
			{
			li.className = "current";
			a.href = "#";
			}
		else
			{
			a.href = "javascript:loadPage(" + (i + 1) + ");";
			}
		
			
		
		li.appendChild(a);
		ul.appendChild(li);
		
		}
	if (pages > 1)
			{
			if (getSpanValue('currPageNum') != pages)
				{
				ul.appendChild(liNext);
				
				}
			ul.appendChild(liShowAll);
			}
	
}

function callback_loadPage(res){

checkResponse(res.value);
	
	var dt = res.value;
	var tbl = document.getElementById("tblPhotos");
	var rows = tbl.rows; 
	if (dt != null)
	{
	if (dt.Rows.length!=0)
		{
		createPageControls(dt.Rows[0]);
		}
		
    while(rows.length) // length=0 -> stop 
		{
		tbl.deleteRow(rows.length-1);
		}
		
	if (dt.Rows.length!=0)
		{
			document.getElementById("numOfPhotosDisplayed").style.display = "block";
			document.getElementById("photoTableContainer").style.display = "block";
			
			document.getElementById("noPhotos").style.display = "none";
		
			document.getElementById("currRows").innerHTML = dt.Rows[0].lower + "&nbsp;&#8211;&nbsp;" + dt.Rows[0].upper + "&nbsp;";
			document.getElementById("totalRows").innerHTML = dt.Rows[0].total;
			setSpanValue('qsvalue',dt.Rows[0].Publiclink);
			if(dt.Rows[0].Security_ID == 0)
			{
			document.getElementById("Publiclink").style.display = "block";
			}
			setSpanValue('photoAlbumName',dt.Rows[0].Album_Title);		
			for (var i=0; i<dt.Rows.length; i++)
				{
				
					var insertTable = document.createElement("tr");
					tbl.appendChild(insertTable);
								
					var tblCell1 = insertTable.insertCell(0)
					var tblCell2 = insertTable.insertCell(1)
					var tblCell3 = insertTable.insertCell(2)
					var tblCell4 = insertTable.insertCell(3)
					var tblCell5 = insertTable.insertCell(4)
	
					var spnNumber = document.createElement("span");
					spnNumber.innerHTML = (i + 1);
					
					tblCell1.appendChild(spnNumber);
					tblCell1.className = "imageNumber";
					
					var img = document.createElement("img");
					if (dt.Rows[i].Photo_ID == getSpanValue('editPhotoID'))
						{
						img.src = appendTimeStamp(dt.Rows[i].src);
					//	if((img.offsetWidth>100)||(img.offsetHeight>80))
					//	{
					//		if (img.offsetWidth >= img.offsetHeight)
					//			{
					//				img.style.width='100px';
					//			}
					//		else
					//			{
					//				img.style.height='80px';
					//			}
					//	}
						setSpanValue('editPhotoID','')
						}
					else
						{
						img.src = appendTimeStamp(dt.Rows[i].src);
						}
					img.id = "img_" + dt.Rows[i].Photo_ID;
					img.alt = dt.Rows[i].Caption;
					img.style.visibility = "hidden";
					//img.style.display = "none";
					
					//if((img.offsetWidth>100)||(img.offsetHeight>80))
					//	{
					//		if (img.offsetWidth >= img.offsetHeight)
					//			{
					//				img.style.width='100px';
					//			}
					//		else
					//			{
					//				img.style.height='80px';
					//			}
					//	}

					var aImg = document.createElement("a");
					aImg.rel = "lightbox[album]";
					aImg.title = dt.Rows[i].Caption;
					aImg.href = dt.Rows[i].srcBig;
					aImg.className = "slide";
					aImg.id = "a_" + dt.Rows[i].Photo_ID;
					
					aImg.appendChild(img);
					
					//tblCell2.appendChild(aImg); // Ben 20071210
					var photoDiv = document.createElement("div");
					photoDiv.style.position = 'relative';
					
					photoDiv.appendChild(aImg);
					tblCell2.appendChild(photoDiv);
					tblCell2.className = "photo";
					
					var dl = document.createElement("dl");
					
					//Description
					var dt1 = document.createElement("dt");
					dt1.className = "description";
					dt1.innerHTML = "Description:";
					
					var dd1 = document.createElement("dd");
					dd1.className = "description";
					dd1.innerHTML = dt.Rows[i].Caption;
					
					dl.appendChild(dt1);
					dl.appendChild(dd1);
					
					//Uploaded Date Time
					var dt2 = document.createElement("dt");
					dt2.innerHTML = "Uploaded:";
					
					var dd2 = document.createElement("dd");
					dd2.innerHTML = dt.Rows[i].Short_Date;
					
					dl.appendChild(dt2);
					dl.appendChild(dd2);
					
					//Date Time
					var dt3 = document.createElement("dt");
					dt3.innerHTML = "Date & Time:";
					
					var dd3 = document.createElement("dd");
					dd3.innerHTML = dt.Rows[i].dateTimeCombo;
					
					dl.appendChild(dt3);
					dl.appendChild(dd3);
					
					//Location
					var dt4 = document.createElement("dt");
					dt4.innerHTML = "Location:";
					
					var dd4 = document.createElement("dd");
					dd4.innerHTML = dt.Rows[i].Photo_Location;
					
					dl.appendChild(dt4);
					dl.appendChild(dd4);
					
					//Tags
					var dt5 = document.createElement("dt");
					dt5.innerHTML = "Tags:";
					
					var dd5 = document.createElement("dd");
					dd5.innerHTML = dt.Rows[i].tagList == '' ? '&nbsp;' : dt.Rows[i].tagList;
					
					dl.appendChild(dt5);
					dl.appendChild(dd5);
					
					//Photographer
					var dt6 = document.createElement("dt");
					dt6.innerHTML = "Photographer:";
					
					var dd6 = document.createElement("dd");
					dd6.innerHTML = dt.Rows[i].Photo_Photog;
					
					dl.appendChild(dt6);
					dl.appendChild(dd6);
					
					tblCell3.appendChild(dl);
					tblCell3.className = "description";
					
					//Is Avatar
					var spnAvatar; 
					if (dt.Rows[i].Is_Profile != null)
						{
						spnAvatar = document.createElement("span");
						spnAvatar.innerHTML = "This image is set as your avatar.";
						spnAvatar.className = "isAvatar";
						tblCell3.appendChild(spnAvatar);
						}
					
					
					
					var lblSelect = document.createElement("label");
					lblSelect.innerHTML = "";
					
					var chk = document.createElement("input")
					chk.type = "checkbox";
					chk.id = "chk_" + dt.Rows[i].Photo_ID;
					chk.value = dt.Rows[i].Photo_ID;
					
					tblCell4.appendChild(chk);
					tblCell4.className = "downloadSelect";
					
					var ulButtons = document.createElement("ul");
				
					var aEdit = document.createElement("a")
					aEdit.innerHTML = "Edit";
					aEdit.href = "javascript:showEditPhoto(" + dt.Rows[i].Photo_ID + ");";
					
					var liEdit = document.createElement("li");
					liEdit.className = "edit";
					
					liEdit.appendChild(aEdit);
					ulButtons.appendChild(liEdit);
					
					
					var aDelete = document.createElement("a")
					aDelete.innerHTML = "Delete";
					aDelete.href = "javascript:showRemovePhoto(" + dt.Rows[i].Photo_ID + ");";
					
					var liDelete = document.createElement("li");
					liDelete.className = "delete";
					
					liDelete.appendChild(aDelete);
					ulButtons.appendChild(liDelete);
					
					var aComments = document.createElement("a")
					aComments.innerHTML = dt.Rows[i].comments + " comment(s)";
					aComments.href = "javascript:goToPhoto(" + dt.Rows[i].Photo_ID + ");";
					
					var liComment = document.createElement("li");
					liComment.className = "comments";
					
					liComment.appendChild(aComments);
					ulButtons.appendChild(liComment);
					
					var aProfileImg = document.createElement("a");
					aProfileImg.innerHTML = "Set Avatar";
					aProfileImg.href = "javascript:updateProfilePhoto(" + dt.Rows[i].Photo_ID + ");";
					
					var liAvatar = document.createElement("li");
					liAvatar.className = "setAvatar";
					
					liAvatar.appendChild(aProfileImg);
					ulButtons.appendChild(liAvatar);
					
					tblCell5.appendChild(ulButtons);
					tblCell5.className = "options";
					
				}
				
		}
	else
		{
		document.getElementById("photoTableContainer").style.display = "none";
		document.getElementById("numOfPhotosDisplayed").style.display = "none";
		document.getElementById("noPhotos").style.display = "block";
			
	//	var insertTable = document.createElement("tr");
	//	tbl.appendChild(insertTable);
								
	//	var tblCell1 = insertTable.insertCell(0)
	//	tblCell1.colSpan = "5";
	//	tblCell1.innerHTML = "There are no photos.";
		
		}
		
	sniffForBodyLoad();
	stripetableBody();
	initLightbox();
	setTimeout('resizeImages();', 1000);
	//document.getElementById("photoContent").style.display = "block";
	//document.getElementById("processLoadingPhotos").style.display = "none";
	//document.getElementById("numOfPhotosDisplayed").style.display = "block";
	//document.getElementById("tblHeadPhotos").style = "";
	
	//window.setTimeout("loadPhotos();", 1000);
	}
	else
	{
		document.getElementById("photoTableContainer").style.display = "none";
		document.getElementById("numOfPhotosDisplayed").style.display = "none";
		document.getElementById("noPhotos").style.display = "block";
			
		var insertTable = document.createElement("tr");
		tbl.appendChild(insertTable);
								
		var tblCell1 = insertTable.insertCell(0)
		tblCell1.colSpan = "5";
		tblCell1.innerHTML = "There are no photos in this album.";
	}
	
}

function loadPhotos(){
	engAlbumPhotos.getPhotos(callback_loadPhotos);
}

function callback_loadPhotos(res){

checkResponse(res.value);

	var dt = res.value;
	var preLoadArray = new Array;
		
	//load image detail table	
	var tbl = document.getElementById("tblPhotos"); 

	var rows = tbl.tBodies[0].rows; 
    while(rows.length) // length=0 -> stop 
		{
		tbl.tBodies[0].deleteRow(rows.length-1);
		}
		
	if (dt.Rows.length!=0)
		{
			document.getElementById("numOfPhotosDisplayed").style.display = "block";
			document.getElementById("noPhotos").style.display = "none";
			document.getElementById("photoTableContainer").style.display = "block";
			
			for (var i=0; i<dt.Rows.length; i++)
				{
				
					var insertTable = document.createElement("tr");
					tbl.tBodies[0].appendChild(insertTable);
								
					var tblCell1 = insertTable.insertCell(0)
					var tblCell2 = insertTable.insertCell(1)
					var tblCell3 = insertTable.insertCell(2)
					var tblCell4 = insertTable.insertCell(3)
					var tblCell5 = insertTable.insertCell(4)
	
					var spnNumber = document.createElement("span");
					spnNumber.innerHTML = (i + 1);
					
					tblCell1.appendChild(spnNumber);
					tblCell1.className = "imageNumber";
					
					var img = document.createElement("img");
					img.src = appendTimeStamp(dt.Rows[i].src);
					img.id = "img_" + dt.Rows[i].Photo_ID;
					img.alt = dt.Rows[i].Caption;
					img.style.visibility = "hidden";
					//img.style.display = "none";
					
					//if((img.offsetWidth>100)||(img.offsetHeight>80))
					//	{
					//		if (img.offsetWidth >= img.offsetHeight)
					//			{
					//				img.style.width='100px';
					//			}
					//		else
					//			{
					//				img.style.height='80px';
					//			}
					//	}

					var aImg = document.createElement("a");
					aImg.rel = "lightbox[album]";
					aImg.title = dt.Rows[i].Caption;
					aImg.href = dt.Rows[i].src;
					aImg.className = "slide";
					aImg.id = "a_" + dt.Rows[i].Photo_ID;
					
					aImg.appendChild(img);
					
					//tblCell2.appendChild(aImg); // Ben 20071210
					var photoDiv = document.createElement("div");
					photoDiv.style.position = 'relative';
					
					photoDiv.appendChild(aImg);
					tblCell2.appendChild(photoDiv);
					tblCell2.className = "photo";
					
					var dl = document.createElement("dl");
					
					//Description
					var dt1 = document.createElement("dt");
					dt1.className = "description";
					dt1.innerHTML = "Description:";
					
					var dd1 = document.createElement("dd");
					dd1.className = "description";
					dd1.innerHTML = dt.Rows[i].Caption;
					
					dl.appendChild(dt1);
					dl.appendChild(dd1);
					
					//Uploaded Date Time
					var dt2 = document.createElement("dt");
					dt2.innerHTML = "Uploaded:";
					
					var dd2 = document.createElement("dd");
					var newDate = dt.Rows[i].Photo_Create_Date.toString().split("GMT");
					dd2.innerHTML = newDate[0];
					
					dl.appendChild(dt2);
					dl.appendChild(dd2);
					
					//Date Time
					var dt3 = document.createElement("dt");
					dt3.innerHTML = "Date & Time:";
					
					var dd3 = document.createElement("dd");
					dd3.innerHTML = dt.Rows[i].dateTimeCombo;
					
					dl.appendChild(dt3);
					dl.appendChild(dd3);
					
					//Location
					var dt4 = document.createElement("dt");
					dt4.innerHTML = "Location:";
					
					var dd4 = document.createElement("dd");
					dd4.innerHTML = dt.Rows[i].Photo_Location;
					
					dl.appendChild(dt4);
					dl.appendChild(dd4);
					
					//Tags
					var dt5 = document.createElement("dt");
					dt5.innerHTML = "Tags:";
					
					var dd5 = document.createElement("dd");
					dd5.innerHTML = dt.Rows[i].tagList == '' ? '&nbsp;' : dt.Rows[i].tagList;
					
					dl.appendChild(dt5);
					dl.appendChild(dd5);
					
					//Photographer
					var dt6 = document.createElement("dt");
					dt6.innerHTML = "Photographer:";
					
					var dd6 = document.createElement("dd");
					dd6.innerHTML = dt.Rows[i].Photo_Photog;
					
					dl.appendChild(dt6);
					dl.appendChild(dd6);
					
					tblCell3.appendChild(dl);
					tblCell3.className = "description";
					
					//Is Avatar
					var spnAvatar; 
					if (dt.Rows[i].Is_Profile != null)
						{
						spnAvatar = document.createElement("span");
						spnAvatar.innerHTML = "This image is set as your avatar.";
						spnAvatar.className = "isAvatar";
						tblCell3.appendChild(spnAvatar);
						}

					var lblSelect = document.createElement("label");
					lblSelect.innerHTML = "";
					
					var chk = document.createElement("input")
					chk.type = "checkbox";
					chk.id = "chk_" + dt.Rows[i].Photo_ID;
					chk.value = dt.Rows[i].Photo_ID;
					
					tblCell4.appendChild(chk);
					tblCell4.className = "downloadSelect";
					
					var ulButtons = document.createElement("ul");
				
					var aEdit = document.createElement("a")
					aEdit.innerHTML = "Edit";
					aEdit.href = "javascript:showEditPhoto(" + dt.Rows[i].Photo_ID + ");";
					
					var liEdit = document.createElement("li");
					liEdit.className = "edit";
					
					liEdit.appendChild(aEdit);
					ulButtons.appendChild(liEdit);
					
					
					var aDelete = document.createElement("a")
					aDelete.innerHTML = "Delete";
					aDelete.href = "javascript:showRemovePhoto(" + dt.Rows[i].Photo_ID + ");";
					
					var liDelete = document.createElement("li");
					liDelete.className = "delete";
					
					liDelete.appendChild(aDelete);
					ulButtons.appendChild(liDelete);
					
					var aComments = document.createElement("a")
					aComments.innerHTML = dt.Rows[i].comments + " comment(s)";
					aComments.href = "javascript:showComments(" + dt.Rows[i].Photo_ID + ");";
					
					var liComment = document.createElement("li");
					liComment.className = "comments";
					
					liComment.appendChild(aComments);
					ulButtons.appendChild(liComment);
					
					var aProfileImg = document.createElement("a");
					aProfileImg.innerHTML = "Set Avatar";
					aProfileImg.href = "javascript:updateProfilePhoto(" + dt.Rows[i].Photo_ID + ");";
					
					var liAvatar = document.createElement("li");
					liAvatar.className = "setAvatar";
					
					liAvatar.appendChild(aProfileImg);
					ulButtons.appendChild(liAvatar);
					
					tblCell5.appendChild(ulButtons);
					tblCell5.className = "options";					
				}
		}
	else
	{
		document.getElementById("numOfPhotosDisplayed").style.display = "none";
		document.getElementById("noPhotos").style.display = "block";
		document.getElementById("photoTableContainer").style.display = "none";		
	}
		
	
	stripetableBody();
	initLightbox();
	resizeImages();
	//lyMouseOverOutToImages();
	//populateImages();
}


function goToPhoto(itemID){
	engAlbumPhotos.goToPhotoDetails(itemID, callback_goToPhoto);
}

function callback_goToPhoto(res){

checkResponse(res.value);

	if (res.value)
		{
		window.location = "/myPhotos/photo.aspx";
		}
}
//publink function created by bhavesh on 29/09/2007
//To open Modalwindow publicAlbum link 
//set plink value to Album link
function publink()
{
	createModel();
	closeBackground();
	var photodiv=document.getElementById("photoslide");	
	photodiv.style.display="none";
	var navigation=document.getElementById("AlbumNavigation");	
	navigation.style.display="none";
	var link = getSpanValue('qsvalue');
	// Ben 20071128
	document.getElementById('albumPublicLink').value = document.getElementById('albumPublicLink').value + link;
	openModalWindow('publicAlbumLink');
}

//Email Friend function created by bhavesh on 29/09/2007
//Send public link to Entered Email Address
EmailFriend = function()
{
	var Email = getControlValue('txtEmail');
	var link = getSpanValue('qsvalue');
	var photoAlbumName = getSpanValue('photoAlbumName');
	showFeedback('addEmailActionContainer');
	engAlbumPhotos.Email_send( Email,link,photoAlbumName, callback_EmailFriend);	
	
}	

callback_EmailFriend = function(res)
{
	if (res.error!=null){alert(res.error)};
	if (res.value == "sent")
	{
		checkResponse(res.value);
		feedbackValid('Sending','Sent');
		window.setTimeout("hideEmailFriend();", 4000);
		window.setTimeout("cleanupFeedback('addEmailActionContainer');", 4000);
	}
	else
	{
		//feedbackValid('Fail','Failed');
		feedbackInvalid('addEmailActionContainer');
	}
				

}


hideEmailFriend = function()
{
	//setSpanValue('confirmAddFriend',"");
	//setControlDisplay('confirmAddFriend','none');
	closeModalWindowRefresh('publicAlbumLink');
}


function ThumbOver()
{
	this.style.border="1px solid #3f3f3f";
}

function ThumbOut()
{
	this.style.border="1px solid #ffffff";
}