/* global functions */

if(LJ==undefined) var LJ={
	
	//declare variables
	blnRunGoogleAnalytics:false,
	
	
	//define functions
	
	initializePage:function()
	{
		LJSeason.initializeStyles();
		this.runGoogleAnalytics();
	},
	
	runGoogleAnalytics:function()
	{
		//check if indicator has been switched
		if(this.blnRunGoogleAnalytics)
		{
			var pageTracker = _gat._getTracker("UA-1204106-1");
			pageTracker._initData();
			pageTracker._trackPageview();
		}
	},
	
	//create a standard sized popup window
	popupWindow:function(url, windowname)
	{
		/* 
		url: can be a url string, or an anchor object with an href attribute
		windowname: can be anything (containing only letters and underscore characters),
		description: every popup window should have a unique name; more than one link can target 
		the same popup by using the same unique popup name.
		*/
		
		var href;
		var popupWin;
		
		//check for existence of window.focus method
		if(!window.focus)
			//if it doesn't exist, exit script, and open link in current window
			return true;
		
		//get the url from the url object
		if(typeof(url)=='string')
			href=url;
		else
			href=url.href;
		
		//open the popup window
		popupWin=window.open(href, windowname, "width=450,height=550,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes");
		//set focus to popup window, in case it was in the background
		popupWin.focus();
		//cancel the click on the link, so link isn't opened in current window
		return false;
	},
	
	//return a style class as an object
	getStyleClass:function(strClassName)
	{
		//declare variables
		var returnValue=null;
		
		try
		{
			if(document.styleSheets)
			{
				for(var s=0;s<document.styleSheets.length;s++)
				{
					if(document.styleSheets[s].rules)
					{
						//IE
						for(var r=0;r<document.styleSheets[s].rules.length;r++)
						{
							if (document.styleSheets[s].rules[r].selectorText == '.' + strClassName)
							{
								returnValue=document.styleSheets[s].rules[r];
							}
						}
					}
					else if(document.styleSheets[s].cssRules)
					{
						//regular browsers
						for(var r=0;r<document.styleSheets[s].cssRules.length;r++)
						{
							if (document.styleSheets[s].cssRules[r].selectorText == '.' + strClassName)
								returnValue=document.styleSheets[s].cssRules[r];
						}
					}
				}
			}
		}
		catch(err)
		{
			//do nothing
		}
		
		return returnValue;
	},

	addOverlay:function(intZIndex)
	{
		if(!document.getElementById("overlay"))
		{
			var eleOverlay=document.createElement("div");
			eleOverlay.id="overlay";
			if(intZIndex)
				eleOverlay.style.zIndex=Number(intZIndex);
			
			//add overlay to document
			var eleBody=document.getElementsByTagName("body")[0];
			eleBody.insertBefore(eleOverlay,eleBody.firstChild);
		}
	},
	
	setOverlayContents:function(eleChild)
	{
		if(document.getElementById("overlay"))
		{
			document.getElementById("overlay").appendChild(eleChild);
		}
	},
	
	showOverlay:function()
	{
		if(document.getElementById("overlay"))
		{
			document.getElementById("overlay").style.visibility="visible";
		}
	},
	
	hideOverlay:function()
	{
		if(document.getElementById("overlay"))
		{
			document.getElementById("overlay").style.visibility="hidden";
		}
	},
	
	removeOverlay:function()
	{
		if(document.getElementById("overlay"))
		{
			//remove overlay from document
			document.getElementsByTagName("body")[0].removeChild(document.getElementById("overlay"));
		}
	},

	//prevents mailto: links from being harvested
	mailTo:function(strPrefix,strDomain)
	{
		//declare variables
		var strAtSign="&#64;";
		
		var strEmail=strPrefix+strAtSign+strDomain;
		document.write("<" + "a" + " " + "href=" + "\"mail" + "to:" + strEmail + "\">" + strEmail + "<\/a>");
	},

	//checks for a valid email address format
	isValidEmailAddress:function(email)
	{
		//declare variables
		var atPos=email.indexOf("@");
		var dotPos=email.lastIndexOf(".");
		var returnValue=true;
		
		if(email.length==0) //check if email is blank
		{
			returnValue=false;
		}
		else if(atPos<1) //check if there are any characters before the "@" sign
		{
			returnValue=false;
		}
		else if(email.length-dotPos<2) //check if there are any characters after the "."
		{
			returnValue=false;
		}
		else if(dotPos-atPos<2) //check if there are any characters between the "@" and the "." and make sure they're in the right order
		{
			returnValue=false;
		}
		
		return returnValue;
	},
	
	//checks for a valid postal/zip code format
	isValidPostalZipCode:function(postalCode,countryName)
	{
		var returnValue=true;
		
		//validate specific content
		if(postalCode.length>0)
		{
			//verify postal code
			if(countryName=="Canada")
			{
				//ensure it is long enough
				if(postalCode.length<6)
				{
					returnValue=false;
				}
				//check for valid format
				else
				{
					var j=0;
					
					// Check for legal characters in string - note index starts at zero
					if('ABCEGHJKLMNPRSTVXY'.indexOf(postalCode.charAt(j)) < 0)
					{
						returnValue=false;
					}
					j++;
					if('0123456789'.indexOf(postalCode.charAt(j)) < 0)
					{
						returnValue=false;
					}
					j++;
					if('ABCEGHJKLMNPRSTVWXYZ'.indexOf(postalCode.charAt(j)) < 0)
					{
						returnValue=false;
					}
					j++;
					
					if(postalCode.charAt(j)==' ')
					{
						j++;
					}
					
					if('0123456789'.indexOf(postalCode.charAt(j)) < 0)
					{
						returnValue=false;
					}
					j++;
					if('ABCEGHJKLMNPRSTVWXYZ'.indexOf(postalCode.charAt(j)) < 0)
					{
						returnValue=false;
					}
					j++;
					if('0123456789'.indexOf(postalCode.charAt(j)) < 0)
					{
						returnValue=false;
					}
				}
			}
			//verify zip code
			else if(countryName=="United States")
			{
				//ensure it is long enough
				if(postalCode.length<5)
				{
					returnValue=false;
				}
				//check for valid format
				else
				{
					//check to make sure each character is numeric (or a space or hyphen)
					for(var i=0;i<postalCode.length;i++)
					{
						if('0123456789 -'.indexOf(postalCode.charAt(i)) < 0)
						{
							returnValue=false;
						}
					}
				}
			}
		}
		else
		{
			returnValue=false;
		}
		
		return returnValue;
	},
	
	disableSubmit:function(frm,returnValue)
	{
		//disable submit button if returnValue is true
		//to prevent people from submitting twice if the server 
		//response is slow in bringing up the next page.
		if(returnValue==true)
		{
			//insert "please wait" message
			document.getElementById("pleaseWait").style.display="inline";
			
			//disable submit button
			frm.submit.disabled=true;
		}
	},
	
	//create XMLHttpRequest object
	createRequest:function()
	{
		//declare variables
		var returnValue=null;
		
		try
		{
			returnValue = new XMLHttpRequest();
		}
		catch(microsoftOption1)
		{
			try
			{
				returnValue = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(microsoftOption2)
			{
				try
				{
					returnValue = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch(failed)
				{
					returnValue=null;
				}
			}
		}
		
		return returnValue;
	},
	
	clipText:function(strText,intChars)
	{
		var strSuffix=" [...]";
		
		if(strText.length>intChars)
		{
			strText=strText.substr(0,intChars-strSuffix.length); //cut off at maximum length
			strText=strText.substr(0,strText.lastIndexOf(" ")); //cut off at last space in text
			strText=strText+strSuffix; //add suffix
		}
		
		return strText;
	}
}

//cookie handling functions
if(LJCookie==undefined) var LJCookie={

	//set a cookie value
	set:function(strName, strValue, dtmExpires, strPath, strDomain, blnSecure)
	{
		document.cookie= strName + "=" + escape(strValue) +
			((dtmExpires) ? "; expires=" + dtmExpires.toGMTString() : "") +
			((strPath) ? "; path=" + strPath : "") +
			((strDomain) ? "; domain=" + strDomain : "") +
			((blnSecure) ? "; secure" : "");
	},
	
	//get a cookie value
	get:function(strName)
	{
		//declare variables
		var strSearch = strName + "=";
		var strCookie="";
		var intOffset=0;
		var intEnd=0;
		
		if (document.cookie.length > 0)
		{ // if there are any cookies
			intOffset = document.cookie.indexOf(strSearch);
			if (intOffset != -1) // if cookie name exists
			{
				intOffset += strSearch.length // set index of beginning of value
				intEnd = document.cookie.indexOf(";", intOffset); // set index of end of cookie value
				if (intEnd == -1)
				{
					intEnd = document.cookie.length;
				}
				strCookie=unescape(document.cookie.substring(intOffset, intEnd));
			}           
		}
		
		//for browsers that return "undefined" when a cookie is not found, return an empty string instead, for consistent return values across browsers
		if(strCookie=="undefined")
		{
			strCookie="";
		}
		return strCookie;
	},
	
	//delete a cookie
	del:function(strName)
	{
		this.set(strName,"",-1);
	}
}

/* fade functions */

//declare global variables
var objFadeIn=null;
var objFadeOut=null;
var objTimeoutFadeIn=null;
var objTimeoutFadeOut=null;

function fadeIn(obj,intFadeTime,intFadeIncrement,intFadeStep)
{
	//set default values
	if(!intFadeTime)
	{
		intFadeTime=1000; //milliseconds
	}
	if(!intFadeIncrement)
	{
		intFadeIncrement=10; //percent to change opacity at each step
	}
	if(!intFadeStep)
	{
		intFadeStep=0; //current step number
	}
	
	objFadeIn=obj;
	
	//check if object has not completed fade in
	if((intFadeIncrement*intFadeStep)<100)
	{
		//increment fade step
		intFadeStep++;
		
		//fade in object
		setOpacity(objFadeIn,(intFadeIncrement*intFadeStep));
		
		//call function recursively, with timeout
		objTimeoutFadeIn=setTimeout("fadeIn(objFadeIn,"+intFadeTime+","+intFadeIncrement+","+intFadeStep+");",intFadeTime/(100/intFadeIncrement));
	}

	//return timeout obj so fadeIn can be cancelled
	return objTimeoutFadeIn;
}

function fadeOut(obj,intFadeTime,intFadeIncrement,intFadeStep)
{
	//set default values
	if(!intFadeTime)
	{
		intFadeTime=1000; //milliseconds
	}
	if(!intFadeIncrement)
	{
		intFadeIncrement=10; //percent to change opacity at each step
	}
	if(!intFadeStep)
	{
		intFadeStep=0; //current step number
	}

	objFadeOut=obj;
	
	//check if object has not completed fade out
	if(100-(intFadeIncrement*intFadeStep)>0)
	{
		//increment fade step
		intFadeStep++;
		
		//fade out object
		setOpacity(objFadeOut,100-(intFadeIncrement*intFadeStep));
		
		//call function recursively, with timeout
		objTimeoutFadeIn=setTimeout("fadeOut(objFadeOut,"+intFadeTime+","+intFadeIncrement+","+intFadeStep+");",intFadeTime/(100/intFadeIncrement));
	}
	
	//return timeout obj so fadeOut can be cancelled
	return objTimeoutFadeIn;
}

function setOpacity(obj, intOpacity)
{
	//limit passed opacity value to between 0 and 100
	if(intOpacity<0)
	{
		intOpacity=0;
	}
	else if(intOpacity>100)
	{
		intOpacity=100;
	}
	
	//set display
	if(intOpacity>0)
	{
		obj.style.display='block';
	}
	else
	{
		obj.style.display='none';
	}
	
	//set opacity
	//obj.style.filter="alpha(opacity="+intOpacity+")"; //IE deprecated
	obj.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity="+intOpacity+")"; //IE
	obj.style.MozOpacity=intOpacity/100; //Mozilla/Netscape
	obj.style.opacity=intOpacity/100; //Opera + W3C standard
	
	if(intOpacity==100)
	{
		if(isSafari())
		{
			obj.style.opacity=.9999; /* objects in Safari disappear at 100 opacity (for some unknown reason) */
		}
	}
}

//check if browser is Safari
function isSafari()
{
	//declare variables
	var returnValue=false;
	
	if(navigator.vendor)
	{
		if(navigator.vendor.indexOf("Apple") != -1)
		{
			returnValue=true;
		}
	}
	
	return returnValue;
}

//declare global variable since static methods don't exist
var lj=new LeonJanzen();

//photo gallery variables
//arrPhotoSrc=new Array();
//arrPhotoOriginalSrc=new Array();
//arrPhotoThumbnailSrc=new Array();
//arrPhotoCaption=new Array();
//arrPhotoCredit=new Array();
arrAudioSrc=new Array();
strPhotoIdText="";
strCreditPrefix="";
intCurrentPhotoNum=0;

//class
function LeonJanzen()
{
	//declare "static" variables
	var arrShowHideObject=new Array(); //array of objects for show/hide transitions
	var arrShowHideInterval=new Array(); //array of interval indexes for show/hide transitions
	var intShowHideTime=300; //milliseconds
	var intShowHideIncrementPercent=10; //percent
	
	var arrGalleryObject=new Array(); //array of gallery objects for transition (only one is currently used)
	var arrGalleryInterval=new Array(); //array of interval indexes for transition (only one is currently used)
	var intGalleryTime=300; //milliseconds
	var intGalleryIncrementPercent=8; //percent
	var arrGalleryStep=new Array(); //array of current step values for transitions (only one is currently used)
	var arrGalleryHTML=new Array(); //array of gallery HTML strings (only one is currently used)
	var arrGalleryTransitionComplete=new Array(); //array of values indicating if transition is complete (only one is currently used)
	
	var intMaxUploads=1;
	var intPhotoSubmitFrameCount=0;
	var arrUploading=new Array();
	var arrUploadQueue=new Array();
	var arrPhotoId=new Array();
	
	//declare methods
	this.showHide=showHide;
	this.showHideInstant=showHideInstant;
	this.showHideTransition=showHideTransition;
	
	this.galleryInitialize=galleryInitialize;
	this.galleryOpen=galleryOpen;
	this.galleryTransition=galleryTransition;
	this.galleryShow=galleryShow;
	this.galleryClose=galleryClose;
	this.galleryEdit=galleryEdit;
	this.galleryDeleteConfirm=galleryDeleteConfirm;
	this.initializeGalleryEditor=initializeGalleryEditor;
	
	this.addPhotoSubmitFrame=addPhotoSubmitFrame;
	this.initializePhotoAdd=initializePhotoAdd;
	this.photoClick=photoClick;
	this.photoListItemClick=photoListItemClick;
	this.photoAddToQueue=photoAddToQueue;
	this.upload=upload;
	this.uploadComplete=uploadComplete;
	this.photoEdit=photoEdit;
	this.photoDelete=photoDelete;
	this.photoRotateRight=photoRotateRight;
	this.photoRotateLeft=photoRotateLeft;
	this.photoMoveUp=photoMoveUp;
	this.photoMoveDown=photoMoveDown;
	this.photoThumbnailSelect=photoThumbnailSelect;
	
	this.highlightPhotoListItem=highlightPhotoListItem;
	this.filename=filename;
	this.stripPx=stripPx;
	this.getXPosRelBody=getXPosRelBody;
	this.getYPosRelBody=getYPosRelBody;
	this.getXPosRelViewport=getXPosRelViewport;
	this.getYPosRelViewport=getYPosRelViewport;
	this.getViewportWidth=getViewportWidth;
	this.getViewportHeight=getViewportHeight;
	this.setMessage=setMessage;
	
	//show/hide an object
	function showHide(obj,btn)
	{
		var intShowHideIndex=null;
		var intTransitionType=0;
		var intTransitionPixels=0;
		var intTransitionInterval=0;
		
		//check if obj has been (or is currently being) transitioned
		for(var i=0;i<arrShowHideObject.length;i++)
		{
			if(arrShowHideObject[i]==obj)
			{
				//cancel current transition
				clearInterval(arrShowHideInterval[i]);
				//store current index
				intShowHideIndex=i;
				
				break;
			}
		}
		
		//check if variable has been defined (above)
		if(intShowHideIndex==null)
		{
			//set index for new transition
			intShowHideIndex=arrShowHideObject.length;
			//store object for new transition
			arrShowHideObject[intShowHideIndex]=obj;
		}
		
		//check current transition state based on className
		if(btn.className=="buttonHide")
		{
			//change button
			btn.className="buttonShow";
			btn.title="Show";
			btn.innerHTML="Show";
			//set transition type
			intTransitionType=-1; //hide
		}
		else if(btn.className=="buttonShow")
		{
			//change button
			btn.className="buttonHide";
			btn.title="Hide";
			btn.innerHTML="Hide";
			//set transition type
			intTransitionType=1; //show
		}
		
		//set initial style for object
		arrShowHideObject[intShowHideIndex].style.position="relative";
		arrShowHideObject[intShowHideIndex].style.overflow="hidden";
		//calculate transition values
		intTransitionInterval=Math.round(intShowHideTime/(100/intShowHideIncrementPercent));
		intTransitionPixels=Math.round(arrShowHideObject[intShowHideIndex].scrollHeight/(100/intShowHideIncrementPercent))*intTransitionType;
		//begin transition
		arrShowHideInterval[intShowHideIndex]=setInterval("lj.showHideTransition("+intShowHideIndex.toString()+","+intTransitionPixels.toString()+")",intTransitionInterval);
	}
	
	//show/hide an object
	function showHideInstant(obj,btn)
	{
		var intShowHideIndex=null;
		var intTransitionType=0;
		var intTargetHeight=0;
		
		//check if obj has been (or is currently being) transitioned
		for(var i=0;i<arrShowHideObject.length;i++)
		{
			if(arrShowHideObject[i]==obj)
			{
				//cancel current transition
				clearInterval(arrShowHideInterval[i]);
				//store current index
				intShowHideIndex=i;
				
				break;
			}
		}
		
		//check if variable has been defined (above)
		if(intShowHideIndex==null)
		{
			//set index for new transition
			intShowHideIndex=arrShowHideObject.length;
			//store object for new transition
			arrShowHideObject[intShowHideIndex]=obj;
		}
		
		//check current transition state based on className
		if(btn.className=="buttonHide")
		{
			//change button
			btn.className="buttonShow";
			btn.title="Show";
			btn.innerHTML="Show";
			//set target height
			intTargetHeight=0; //hide
		}
		else if(btn.className=="buttonShow")
		{
			//change button
			btn.className="buttonHide";
			btn.title="Hide";
			btn.innerHTML="Hide";
			//set target height
			intTargetHeight=arrShowHideObject[intShowHideIndex].scrollHeight; //show
		}
		
		//set style for object
		arrShowHideObject[intShowHideIndex].style.position="relative";
		arrShowHideObject[intShowHideIndex].style.overflow="hidden";

		//set height
		arrShowHideObject[intShowHideIndex].style.height=intTargetHeight.toString()+"px";
	}
	
	//perform transition step for show/hide
	function showHideTransition(intShowHideIndex,intTransitionPixels)
	{
		//calculate target height
		var intTargetHeight=arrShowHideObject[intShowHideIndex].offsetHeight+intTransitionPixels;
		//check for min height
		intTargetHeight=(intTargetHeight<0 ? 0 : intTargetHeight);
		//check for max height
		intTargetHeight=(intTargetHeight>arrShowHideObject[intShowHideIndex].scrollHeight ? arrShowHideObject[intShowHideIndex].scrollHeight : intTargetHeight)
		
		//set height
		arrShowHideObject[intShowHideIndex].style.height=intTargetHeight.toString()+"px";
		
		if(intTargetHeight<=0 || intTargetHeight>=arrShowHideObject[intShowHideIndex].scrollHeight)
		{
			//end transition
			clearInterval(arrShowHideInterval[intShowHideIndex]);
		}
	}
	
	
	//initialize gallery page
	function galleryInitialize()
	{
		window.onload=function()
		{
			var strGalleryIdSearch="galleryId=";
			var strPhotoIdSearch="photoId=";
			var strSubstring="";
			var strPhotoSubstring="";
			var intGalleryId=null;
			var intPhotoId=null;
			var intStart=0;
			var intEnd=0;
			
			//find passed galleryId
			intStart=location.search.indexOf(strGalleryIdSearch);
			if(intStart>-1)
			{
				strSubstring=location.search.substring(intStart);
				
				intEnd=strSubstring.indexOf("&");
				if(intEnd==-1)
				{
					intEnd=strSubstring.length;
				}
				
				intGalleryId=parseInt(strSubstring.substring(strGalleryIdSearch.length,intEnd),10);
				
				//find passed photoId
				intStart=location.search.indexOf(strPhotoIdSearch);
				if(intStart>-1)
				{
					strSubstring=location.search.substring(intStart);
					
					intEnd=strSubstring.indexOf("&");
					if(intEnd==-1)
					{
						intEnd=strSubstring.length;
					}
					
					intPhotoId=parseInt(strSubstring.substring(strPhotoIdSearch.length,intEnd),10);
				}
				
				//check if gallery exists on the page
				if(document.getElementById("gallerySrc"+intGalleryId))
				{
					//show gallery
					lj.galleryOpen(intGalleryId,document.getElementById("gallerySrc"+intGalleryId),intPhotoId);
				}
			}
		}
	}
	
	//open a gallery
	function galleryOpen(intGalleryId,objSrc,intPhotoId)
	{
		var objGallery=null;
		var dblWidthHeightRatio=1.7; //photo and screen dimensions are 1.333 (4/3)
		var intGalleryMargin=0; //pixels - any border width reduces this space
		var intGalleryPadding=10; //pixels
		var intGalleryIndex=null;
		var intMaxWidth=1024; //pixels
		var intMaxHeight=768; //pixels
		var intMinWidth=880; //pixels
		var intMinHeight=800; //pixels
		var intGalleryIniWidth=0;
		var intGalleryIniHeight=0;
		var intGalleryIniLeft=0;
		var intGalleryIniTop=0;
		var intGalleryWidth=0;
		var intGalleryHeight=0;
		var intGalleryLeft=0;
		var intGalleryTop=0;
		var intCentreX=0;
		var intCentreY=0;
		var intTransitionSteps=0;
		var intTransitionInterval=0;
		var intTransitionMoveX=0.0;
		var intTransitionMoveY=0.0;
		var intTransitionGrowX=0.0;
		var intTransitionGrowY=0.0;
		var objRequest=null;
		var strPost="";
		var strLoading="<div class=\"galleryLoading\">Loading...</div>";
		
		//check if gallery element already exists
		if(document.getElementById("gallery"))
		{
			objGallery=document.getElementById("gallery");
			
			//check if obj has been (or is currently being) transitioned
			for(var i=0;i<arrGalleryObject.length;i++)
			{
				if(arrGalleryObject[i]==objGallery)
				{
					//cancel current transition
					clearInterval(arrGalleryInterval[i]);
					//store current index
					intGalleryIndex=i;
					
					break;
				}
			}
		}
		else
		{
			//create gallery element
			objGallery=document.createElement("div");
			objGallery.setAttribute("id","gallery");
			objGallery.className="gallery";
			objGallery.style.position="absolute";
			objGallery.style.zIndex=2;
			objGallery.style.padding=intGalleryPadding.toString()+"px";
			
			//add element to document
			document.body.appendChild(objGallery);
		}
		
		//hide gallery
		objGallery.style.display="none";
			
		//calculate initial size and position
		intGalleryIniWidth=objSrc.offsetWidth-intGalleryPadding*2;
		intGalleryIniHeight=objSrc.offsetHeight-intGalleryPadding*2;
		intGalleryIniLeft=getXPosRelBody(objSrc);
		intGalleryIniTop=getYPosRelBody(objSrc);
		
		//set initial size and position
		objGallery.style.width=intGalleryIniWidth.toString()+"px";
		objGallery.style.height=intGalleryIniHeight.toString()+"px";
		objGallery.style.left=intGalleryIniLeft.toString()+"px";
		objGallery.style.top=intGalleryIniTop.toString()+"px";
		
		//calculate final size and position
//		intMaxWidth=getViewportWidth()-intGalleryMargin*2;
//		intMaxHeight=getViewportHeight()-intGalleryMargin*2;
//		if(intMaxWidth/dblWidthHeightRatio>intMaxHeight)
//		{
//			//calculate gallery size based on height
//			intGalleryHeight=intMaxHeight;
//			intGalleryWidth=intGalleryHeight*dblWidthHeightRatio;
//			intCentreX=Math.round((intMaxWidth-intGalleryWidth)/2);
//		}
//		else
//		{
//			//calculate gallery size based on width
//			intGalleryWidth=intMaxWidth;
//			intGalleryHeight=intGalleryWidth/dblWidthHeightRatio;
//			intCentreY=Math.round((intMaxHeight-intGalleryHeight)/2);
//		}
		//calculate final gallery size based on width
//		intGalleryWidth=Math.min(intMaxWidth,getViewportWidth()-intGalleryMargin*2);
//		intGalleryHeight=Math.min(intMaxHeight,getViewportHeight()-intGalleryMargin*2);
		intGalleryWidth=Math.max(intMinWidth,getViewportWidth()-intGalleryMargin*2);
		intGalleryHeight=Math.max(intMinHeight,getViewportHeight()-intGalleryMargin*2);
//		intCentreX=Math.round((getViewportWidth()-(intGalleryWidth+intGalleryMargin*2))/2);
		intCentreX=0;
		intCentreY=0;
		//subtract padding and add centre values
		intGalleryWidth=intGalleryWidth-intGalleryPadding*2;
		intGalleryHeight=intGalleryHeight-intGalleryPadding*2;
		intGalleryLeft=getXScroll()+intGalleryMargin+intCentreX;
		intGalleryTop=getYScroll()+intGalleryMargin+intCentreY;

		//calculate transition values
		intTransitionSteps=Math.round(100/intGalleryIncrementPercent);
		intTransitionInterval=Math.round(intGalleryTime/intTransitionSteps);
		intTransitionMoveX=Math.round((intGalleryLeft-intGalleryIniLeft)/intTransitionSteps);
		intTransitionMoveY=Math.round((intGalleryTop-intGalleryIniTop)/intTransitionSteps);
		intTransitionGrowX=Math.round((intGalleryWidth-intGalleryIniWidth)/intTransitionSteps);
		intTransitionGrowY=Math.round((intGalleryHeight-intGalleryIniHeight)/intTransitionSteps);

		//check if index variable has been defined
		if(intGalleryIndex==null)
		{
			//set index for new transition
			intGalleryIndex=arrGalleryObject.length;
			//store object for new transition
			arrGalleryObject[intGalleryIndex]=objGallery;
		}
		
		//set default transition complete value
		arrGalleryTransitionComplete[intGalleryIndex]=false;
		//set default gallery content
		arrGalleryHTML[intGalleryIndex]=strLoading;		
		
		//show gallery
		objGallery.style.display="block";
		//add close button and content tag
		objGallery.innerHTML="<div class=\"buttonClose\" title=\"Close\" onclick=\"lj.galleryClose(document.getElementById('gallery'));\">Close</div><div id=\"galleryContent"+intGalleryIndex.toString()+"\"></div>";

		//begin transition
		arrGalleryStep[intGalleryIndex]=0;
		arrGalleryInterval[intGalleryIndex]=setInterval("lj.galleryTransition("+intGalleryId.toString()+","+intGalleryIndex.toString()+","+intTransitionSteps.toString()+","+intTransitionMoveX.toString()+","+intTransitionMoveY.toString()+","+intTransitionGrowX.toString()+","+intTransitionGrowY.toString()+","+intGalleryWidth.toString()+","+intGalleryHeight.toString()+","+intGalleryLeft.toString()+","+intGalleryTop.toString()+")",intTransitionInterval);
		
		
		//create request object
		objRequest=LJ.createRequest();
		
		//set request object
		objRequest.open("POST","/assets/php/LJPhotos.receiver.php",true);
		objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		objRequest.onreadystatechange=function(){
			if(objRequest.readyState==4)
			{
				if(objRequest.status==200)
				{
					//set gallery content
					arrGalleryHTML[intGalleryIndex]=objRequest.responseXML.documentElement.getElementsByTagName("gallery")[0].childNodes[0].nodeValue;
					
					//show gallery content
					galleryShow(intGalleryIndex);
					
					//set javascript values
					arrElements=objRequest.responseXML.documentElement.getElementsByTagName("photoSrc");
					for(var i=0;i<arrElements.length;i++)
					{
						arrPhotoSrc[i]=arrElements[i].childNodes[0].nodeValue;
					}
					arrElements=objRequest.responseXML.documentElement.getElementsByTagName("photoOriginalSrc");
					for(var i=0;i<arrElements.length;i++)
					{
						arrPhotoOriginalSrc[i]=arrElements[i].childNodes[0].nodeValue;
					}
					arrElements=objRequest.responseXML.documentElement.getElementsByTagName("photoThumbnailSrc");
					for(var i=0;i<arrElements.length;i++)
					{
						arrPhotoThumbnailSrc[i]=arrElements[i].childNodes[0].nodeValue;
					}
					arrElements=objRequest.responseXML.documentElement.getElementsByTagName("photoCaption");
					for(var i=0;i<arrElements.length;i++)
					{
						arrPhotoCaption[i]=arrElements[i].childNodes[0].nodeValue;
					}
					arrElements=objRequest.responseXML.documentElement.getElementsByTagName("photoCredit");
					for(var i=0;i<arrElements.length;i++)
					{
						arrPhotoCredit[i]=arrElements[i].childNodes[0].nodeValue;
					}
					arrElements=objRequest.responseXML.documentElement.getElementsByTagName("audioSrc");
					for(var i=0;i<arrElements.length;i++)
					{
						arrAudioSrc[i]=arrElements[i].childNodes[0].nodeValue;
					}
					strPhotoIdText=objRequest.responseXML.documentElement.getElementsByTagName("photoIdText")[0].childNodes[0].nodeValue;
					strCreditPrefix=objRequest.responseXML.documentElement.getElementsByTagName("creditPrefix")[0].childNodes[0].nodeValue;
					intCurrentPhotoNum=objRequest.responseXML.documentElement.getElementsByTagName("currentPhotoNum")[0].childNodes[0].nodeValue;
					
					//get message
					xmlMessage=objRequest.responseXML.documentElement.getElementsByTagName("message")[0];
					//set message
					setMessage(xmlMessage);
					
					//initialize photos
					setTimeout("initializePhotos()",1000);
					//initializePhotos();
					
					//begin play, if specified
					if(objRequest.responseXML.documentElement.getElementsByTagName("play")[0].childNodes[0].nodeValue=="1" && objRequest.responseXML.documentElement.getElementsByTagName("hasAudio")[0].childNodes[0].nodeValue!="1")
					{
						photoPlay();
					}
				}
				else
				{
					//set gallery content error message
					arrGalleryHTML[intGalleryIndex]="<div class=\"galleryError\">Error loading gallery ("+objRequest.status+")</div>";
					
					//show gallery content
					galleryShow(intGalleryIndex);
				}
			}
		};
		//create post string
		strPost="action=showGallery&galleryId="+intGalleryId.toString()+(intPhotoId ? "&photoId="+intPhotoId.toString() : "");
		//send request
		objRequest.send(strPost);
		
		return false;
	}
	
	//perform transition step for gallery
	function galleryTransition(intGalleryId,intGalleryIndex,intTransitionSteps,intTransitionMoveX,intTransitionMoveY,intTransitionGrowX,intTransitionGrowY,intGalleryWidth,intGalleryHeight,intGalleryLeft,intGalleryTop)
	{
		var objGallery=arrGalleryObject[intGalleryIndex];
		
		//increment step
		arrGalleryStep[intGalleryIndex]++;
		
		//check for end step
		if(arrGalleryStep[intGalleryIndex]<intTransitionSteps)
		{
			//set size and position
			objGallery.style.left=(stripPx(objGallery.style.left)+intTransitionMoveX).toString()+"px";
			objGallery.style.top=(stripPx(objGallery.style.top)+intTransitionMoveY).toString()+"px";
			objGallery.style.width=(stripPx(objGallery.style.width)+intTransitionGrowX).toString()+"px";
			objGallery.style.height=(stripPx(objGallery.style.height)+intTransitionGrowY).toString()+"px";
		}
		else
		{
			//end transition
			clearInterval(arrGalleryInterval[intGalleryIndex]);
			
			//set final size and position
			objGallery.style.left=intGalleryLeft.toString()+"px";
			objGallery.style.top=intGalleryTop.toString()+"px";
			objGallery.style.width=intGalleryWidth.toString()+"px";
			objGallery.style.height=intGalleryHeight.toString()+"px";
			
			//set transition complete value
			arrGalleryTransitionComplete[intGalleryIndex]=true;
			
			//show gallery contents
			galleryShow(intGalleryIndex);
		}
	}
	
	//show gallery content
	function galleryShow(intGalleryIndex)
	{
		//check if transition is complete
		if(arrGalleryTransitionComplete[intGalleryIndex])
		{
			//display gallery
			document.getElementById("galleryContent"+intGalleryIndex.toString()).innerHTML=arrGalleryHTML[intGalleryIndex];
		}
	}
	
	//close a gallery
	function galleryClose(objGallery)
	{
		objGallery.style.display="none";
	}
	
	//edit/add a gallery
	function galleryEdit(frm)
	{
		var objRequest=LJ.createRequest();
		var strMessage="";
		var strPost="";
		var blnReturnValue=false;
		
		//trigger tinyMCE save
		if(tinyMCE)
		{
			tinyMCE.triggerSave();
		}
		
		//check if this is a new gallery or an existing gallery (gallerId exists)
		if(frm.galleryId.value.length==0)
		{
			blnReturnValue=true;
		}
		else
		{
			//set request object
			objRequest.open("POST","/assets/php/LJPhotos.receiver.php",true);
			objRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			objRequest.onreadystatechange=function(){
				if(objRequest.readyState==4)
				{
					if(objRequest.status==200)
					{
						//get response
						xmlSuccess=objRequest.responseXML.documentElement.getElementsByTagName("success")[0];
						//get message
						xmlMessage=objRequest.responseXML.documentElement.getElementsByTagName("message")[0];
						
						//set message
						setMessage(xmlMessage);
					}
					else
					{
						//set error message
						document.getElementById("message").innerHTML="<div>Error saving gallery details ("+objRequest.status+")</div>";
						blnSuccess=false;
					}
				}
			};
			//create post string from form elements
			//add all but last element
			for(var i=0;i<frm.length-1;i++)
			{
				//exclude tiny_mce elements
				if(frm.elements[i].name.indexOf("mce_editor")==-1)
				{
					strPost+=frm.elements[i].name+"="+frm.elements[i].value+"&";
				}
			}
			//add last element
			strPost+=frm.elements[frm.length-1].name+"="+frm.elements[frm.length-1].value;
			//send request
			objRequest.send(strPost);
		}
		
		return blnReturnValue;
	}
	
	//confirm gallery delete
	function galleryDeleteConfirm()
	{
		return confirm("Are you sure you want to delete the entire gallery?");
	}

	//initialize gallery editor page
	function initializeGalleryEditor(frm)
	{
		var objDoc=null;

		//set default focus
		frm.title.focus();
		
		//check for galleryId
		if(frm.galleryId && frm.galleryId.value.length>0)
		{
			//hide gallery details
			lj.showHideInstant(document.getElementById('galleryEditContainer'),document.getElementById('galleryDetailsShowHide'));
			
			//add photo submit frame
			addPhotoSubmitFrame(parseInt(frm.galleryId.value,10));
		}
	}
	
	//add new frame
	function addPhotoSubmitFrame(intGalleryId)
	{
		var objFrame=null;
		
		//incremeent counter
		intPhotoSubmitFrameCount++;
		
		//create new iframe
		objFrame=document.createElement("iframe");
		objFrame.setAttribute("src","/photos/edit/add.php?galleryId="+intGalleryId+"&photoSubmitFrame="+intPhotoSubmitFrameCount);
		objFrame.className="photoSubmit";
		objFrame.setAttribute("id","photoSubmitFrame"+intPhotoSubmitFrameCount);
		objFrame.setAttribute("name","photoSubmitFrame"+intPhotoSubmitFrameCount);
		objFrame.setAttribute("allowtransparency","true");
		objFrame.setAttribute("frameborder","0");
		
		//add to container
		document.getElementById("photoSubmitFrames").appendChild(objFrame);
	}
	
	function initializePhotoAdd(frm)
	{
		//set focus
		frm.photo.focus();
	}
	
	function photoListItemClick(frm,objInput)
	{
		var strPhotoCaption="";
		var blnPhotoCaptionsIdentical=true;
		var strPhotoCredit="";
		var blnPhotoCreditsIdentical=true;
		var strPhotoRating="";
		var blnPhotoRatingsIdentical=true;

		//highlight current item
		highlightPhotoListItem(objInput);
		
		//add to or remove from array
		if(objInput.checked)
		{
			//add to array of selected photos
			arrPhotoId[arrPhotoId.length]=parseInt(objInput.value,10);
		}
		else
		{
			//remove from array of selected photos
			for(var i=0;i<arrPhotoId.length;i++)
			{
				if(arrPhotoId[i]==parseInt(objInput.value,10))
				{
					//remove element
					arrPhotoId.splice(i,1);
					break;
				}
			}
		}
		
		//check if selected photos have identical captions
		if(arrPhotoId.length>=1)
		{
			//store initial caption
			strPhotoCaption=document.getElementById("photoCaption"+arrPhotoId[0]).innerHTML;
			
			for(var i=1;i<arrPhotoId.length;i++)
			{
				//check if next selected caption matches previous selected caption
				if(document.getElementById("photoCaption"+arrPhotoId[i]).innerHTML!=strPhotoCaption)
				{
					blnPhotoCaptionsIdentical=false;
					strPhotoCaption="";
					break;
				}
			}
		}
		
		//set caption field
		frm.caption.value=strPhotoCaption;
		//trigger tinyMCE update
		tinyMCE.updateContent("caption");
		
		//check if selected photos have identical credits
		if(arrPhotoId.length>=1)
		{
			//store initial credit
			strPhotoCredit=document.getElementById("photoCredit"+arrPhotoId[0]).innerHTML;
			
			for(var i=1;i<arrPhotoId.length;i++)
			{
				//check if next selected credit matches previous selected credit
				if(document.getElementById("photoCredit"+arrPhotoId[i]).innerHTML!=strPhotoCredit)
				{
					blnPhotoCreditsIdentical=false;
					strPhotoCredit="";
					break;
				}
			}
		}
		
		//set credit field
		frm.credit.value=strPhotoCredit;
		
		//check if selected photos have identical ratings
		if(arrPhotoId.length>=1)
		{
			//store initial rating
			strPhotoRating=document.getElementById("photoRating"+arrPhotoId[0]).innerHTML;
			
			for(var i=1;i<arrPhotoId.length;i++)
			{
				//check if next selected caption matches previous selected caption
				if(document.getElementById("photoRating"+arrPhotoId[i]).innerHTML!=strPhotoRating)
				{
					blnPhotoRatingsIdentical=false;
					strPhotoRating="";
					break;
				}
			}
		}
		
		//set rating field
		for(var i=0;i<frm.rating.length;i++)
		{
			if(frm.rating.options[i].value==strPhotoRating)
			{
				frm.rating.options[i].selected=true;
				break;
			}
		}
	}
	
	//add photo
	function photoClick(frm)
	{
		var objParentDoc=null;
		var strNewPhoto="";
		var objNewPhoto=null;
		var blnReturnValue=false;
		
		if(window.parent.document)
		{
			objParentDoc=window.parent.document;
			objNewPhoto=null;
			strNewPhoto="";
			
			//create new photo item
//			objNewPhoto=document.createElement("div");
//			objNewPhoto.setAttribute("id","newPhoto"+frm.newPhotoNumber.value);
//			objNewPhoto.className="photoListItem";
			//add content to new photo item
//			objNewPhoto.appendChild(document.createTextNode(filename(frm.photo.value)+" waiting to upload..."));
			//for IE
			strNewPhoto="<div id=\"newPhoto"+frm.newPhotoNumber.value+"\" class=\"photoListItem\">"+filename(frm.photo.value)+" waiting to upload...</div>";

			//add new photo item to list
//			objParentDoc.getElementById("photoList").appendChild(objNewPhoto);
			//for IE
			objParentDoc.getElementById("photoList").innerHTML+=strNewPhoto;
			
			//hide current frame
			objParentDoc.getElementById("photoSubmitFrame"+frm.newPhotoNumber.value).style.height="0px";
			objParentDoc.getElementById("photoSubmitFrame"+frm.newPhotoNumber.value).style.visibility="hidden";
			//objParentDoc.getElementById("photoSubmitFrame"+frm.newPhotoNumber.value).style.border="1px solid green";
			
			//add new frame
			window.parent.lj.addPhotoSubmitFrame(parseInt(frm.galleryId.value,10));

			//trigger function in parent window
			window.parent.lj.photoAddToQueue(frm.newPhotoNumber.value);
		}
		
		return blnReturnValue;
	}
	
	function photoAddToQueue(intNewPhotoNumber)
	{
		//add photo to upload queue
		arrUploadQueue[arrUploadQueue.length]=intNewPhotoNumber;
		
		//process next item in queue
		upload();
	}
	
	//process next item in queue
	function upload()
	{
		var objFrameDoc=null;
		var intNewPhotoNumber=null;
		
		if(arrUploadQueue.length>0 && arrUploading.length<intMaxUploads)
		{
			//find next photo number and remove from queue array
			intNewPhotoNumber=arrUploadQueue.shift(arrUploadQueue);
			//add to uploading array
			arrUploading[arrUploading.length]=intNewPhotoNumber;
			
			//begin uploading
			if(document.getElementById("photoSubmitFrame"+intNewPhotoNumber).contentWindow.document)
			{
				objFrameDoc=document.getElementById("photoSubmitFrame"+intNewPhotoNumber.toString()).contentWindow.document;
				
				//add session id to action attribute (doesn't seem to help)
				//objFrameDoc.forms[0].setAttribute("action",objFrameDoc.forms[0].getAttribute("action")+"?"+objFrameDoc.forms[0].sessionName.value+"="+LJCookie.get(objFrameDoc.forms[0].sessionName.value))
				
				//trigger form submit
				objFrameDoc.forms[0].submit();
				
				//change display
				document.getElementById("newPhoto"+intNewPhotoNumber).innerHTML=filename(objFrameDoc.photoAdd.photo.value)+" uploading...";
			}
			else
			{
				alert("Error uploading file");
			}
		}
	}
	
	function uploadComplete(intNewPhotoNumber,objPhotoListItem)
	{
		var intIndex=null;
		var objParent=null;
		
		//find in uploading queue
		for(var i=0;i<arrUploading.length;i++)
		{
			if(arrUploading[i]==intNewPhotoNumber)
			{
				intIndex=i;
				break;
			}
		}
		
		//remove from uploading queue
		arrUploading.splice(intIndex,1);
		
		//process next item in queue
		upload();
		
		//change display
//		objParent=document.getElementById("newPhoto"+intNewPhotoNumber).parentNode;
//		objReplace=document.getElementById("newPhoto"+intNewPhotoNumber);
//		objParent.replaceChild(objPhotoListItem,objReplace);

		//for IE
		document.getElementById("newPhoto"+intNewPhotoNumber).className="";
		document.getElementById("newPhoto"+intNewPhotoNumber).innerHTML=objPhotoListItem.innerHTML;
	}
	
	
	//edit photo details
	function photoEdit(frm)
	{
		//create request object
		objRequest=LJ.createRequest();
		strPost="";
		blnContinue=true;
		blnSuccess=true;
		blnReturnValue=false;
		arrPhotoIdCopy=new Array();
		
		//trigger tinyMCE save
		if(tinyMCE)
		{
			tinyMCE.triggerSave();
		}
		
		if(arrPhotoId.length>1)
		{
			if(frm.caption.value.length>0 && blnContinue)
			{
				blnContinue=confirm("Are you sure you want to use the same caption for all selected photos?");
			}
		}
		else if(arrPhotoId.length==0)
		{
			blnContinue=false;
		}
		
		if(blnContinue)
		{
			//set request object
			objRequest.open("POST","/assets/php/LJPhotos.receiver.php",true);
			objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			objRequest.onreadystatechange=function(){
				if(objRequest.readyState==4)
				{
					if(objRequest.status==200)
					{
						//get response
						xmlSuccess=objRequest.responseXML.documentElement.getElementsByTagName("success")[0];
						//get message
						xmlMessage=objRequest.responseXML.documentElement.getElementsByTagName("message")[0];
						
						if(xmlSuccess.childNodes[0].nodeValue=="1")
						{
							//check if photos have been moved to a different gallery
							if(frm.destGalleryId.value.length>0 && frm.galleryId.value!=frm.destGalleryId.value)
							{
								//remove photos from list
								for(var i=0;i<arrPhotoId.length;i++)
								{
									objParent=document.getElementById("photoListItem"+arrPhotoId[i]).parentNode;
									objParent.removeChild(document.getElementById("photoListItem"+arrPhotoId[i]));
								}
								
								//empty array of selected photos
								arrPhotoId=new Array();
							}
							for(var i=0;i<arrPhotoId.length;i++)
							{
								//update captions
								if(frm.caption.value.length>0)
								{
									document.getElementById("photoCaption"+arrPhotoId[i]).innerHTML=frm.caption.value;
								}
								//update captions
								if(frm.credit.value.length>0)
								{
									document.getElementById("photoCredit"+arrPhotoId[i]).innerHTML=frm.credit.value;
								}
								//update ratings
								if(frm.rating.value.length>0)
								{
									document.getElementById("photoRating"+arrPhotoId[i]).innerHTML=frm.rating.value;
								}
								//store copy of photo id array, so it doesn't change when items are deselected
								arrPhotoIdCopy[arrPhotoIdCopy.length]=arrPhotoId[i];
							}
							
							for(var i=0;i<arrPhotoIdCopy.length;i++)
							{
								//deselect photos
								if(document.getElementById("photo"+arrPhotoIdCopy[i]))
								{
									document.getElementById("photo"+arrPhotoIdCopy[i]).checked=false;
									lj.photoListItemClick(frm,document.getElementById("photo"+arrPhotoIdCopy[i]));
								}
							}
							
							//select current gallery in drop down
							for(var i=0;i<frm.destGalleryId.length;i++)
							{
								if(frm.destGalleryId.options[i].value==frm.galleryId.value)
								{
									//select item
									frm.destGalleryId.options[i].selected=true;
									break;
								}
							}
						}
						
						//set message
						setMessage(xmlMessage);
					}
					else
					{
						//set error message
						document.getElementById("message").innerHTML="<div>Error saving photo details ("+objRequest.status+")</div>";
						blnSuccess=false;
					}
				}
			};
			//create post string from form elements
			//add all but last element
			for(var i=0;i<frm.length-1;i++)
			{
				//exclude tiny_mce elements
				if(frm.elements[i].name.indexOf("mce_editor")==-1)
				{
					if(frm.elements[i].value.length>0)
					{
						if(frm.elements[i].type!="checkbox" || (frm.elements[i].type=="checkbox" && frm.elements[i].checked))
						{
							strPost+=frm.elements[i].name+"="+frm.elements[i].value+"&";
						}
					}
				}
			}
			//add last element
			strPost+=frm.elements[frm.length-1].name+"="+frm.elements[frm.length-1].value;
			//send request
			objRequest.send(strPost);
		}
		
		return blnReturnValue;
	}
	
	//delete a photo
	function photoDelete(intGalleryId,intPhotoId)
	{
		if(confirm("Are you sure you want to delete the photo?"))
		{
			//create request object
			objRequest=LJ.createRequest();
			blnSuccess=true;
			
			//set request object
			objRequest.open("POST","/assets/php/LJPhotos.receiver.php",true);
			objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			objRequest.onreadystatechange=function(){
				if(objRequest.readyState==4)
				{
					if(objRequest.status==200)
					{
						//get response
						xmlSuccess=objRequest.responseXML.documentElement.getElementsByTagName("success")[0];
						//get message
						xmlMessage=objRequest.responseXML.documentElement.getElementsByTagName("message")[0];
						
						//remove photo from list
						if(xmlSuccess.childNodes[0].nodeValue=="1")
						{
							//find parent
							objParent=document.getElementById("photoListItem"+intPhotoId).parentNode;
							//remove child
							objParent.removeChild(document.getElementById("photoListItem"+intPhotoId));
						}
						
						//set message
						setMessage(xmlMessage);
					}
					else
					{
						//set error message
						document.getElementById("message").innerHTML="<div>Error deleting photo ("+objRequest.status+")</div>";
						blnSuccess=false;
					}
				}
			};
			//create post string
			strPost="action=deletePhoto&galleryId="+intGalleryId.toString()+"&photoId="+intPhotoId.toString();
			//send request
			objRequest.send(strPost);
		}
	}
	
	//rotate a photo 90 degrees right
	function photoRotateRight(intGalleryId,intPhotoId)
	{
		//create request object
		objRequest=LJ.createRequest();
		blnSuccess=true;
		
		//set request object
		objRequest.open("POST","/assets/php/LJPhotos.receiver.php",true);
		objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		objRequest.onreadystatechange=function(){
			if(objRequest.readyState==4)
			{
				if(objRequest.status==200)
				{
					//get response
					xmlSuccess=objRequest.responseXML.documentElement.getElementsByTagName("success")[0];
					//get message
					xmlMessage=objRequest.responseXML.documentElement.getElementsByTagName("message")[0];
					
					//update thumbnail
					if(xmlSuccess.childNodes[0].nodeValue=="1")
					{
						//find image
						objImg=document.getElementById("photoImg"+intPhotoId);
						//reload image
						objImg.src=objImg.src+"?"+((new Date()).getTime()).toString();
					}
					
					//set message
					setMessage(xmlMessage);
				}
				else
				{
					//set error message
					document.getElementById("message").innerHTML="<div>Error deleting photo ("+objRequest.status+")</div>";
					blnSuccess=false;
				}
			}
		};
		//create post string
		strPost="action=rotateRight&galleryId="+intGalleryId.toString()+"&photoId="+intPhotoId.toString();
		//send request
		objRequest.send(strPost);
	}
	
	//rotate a photo 90 degrees left
	function photoRotateLeft(intGalleryId,intPhotoId)
	{
		//create request object
		objRequest=LJ.createRequest();
		blnSuccess=true;
		
		//set request object
		objRequest.open("POST","/assets/php/LJPhotos.receiver.php",true);
		objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		objRequest.onreadystatechange=function(){
			if(objRequest.readyState==4)
			{
				if(objRequest.status==200)
				{
					//get response
					xmlSuccess=objRequest.responseXML.documentElement.getElementsByTagName("success")[0];
					//get message
					xmlMessage=objRequest.responseXML.documentElement.getElementsByTagName("message")[0];
					
					//update thumbnail
					if(xmlSuccess.childNodes[0].nodeValue=="1")
					{
						//find image
						objImg=document.getElementById("photoImg"+intPhotoId);
						//reload image
						objImg.src=objImg.src+"?"+((new Date()).getTime()).toString();
					}
					
					//set message
					setMessage(xmlMessage);
				}
				else
				{
					//set error message
					document.getElementById("message").innerHTML="<div>Error deleting photo ("+objRequest.status+")</div>";
					blnSuccess=false;
				}
			}
		};
		//create post string
		strPost="action=rotateLeft&galleryId="+intGalleryId.toString()+"&photoId="+intPhotoId.toString();
		//send request
		objRequest.send(strPost);
	}
	
	//change order position of photo
	function photoMoveUp(intGalleryId,intPhotoId)
	{
		//create request object
		objRequest=LJ.createRequest();
		objListItem=null;
		objListItemLower=null;
		objListItemHolder=null;
		blnSuccess=true;
		
		//set request object
		objRequest.open("POST","/assets/php/LJPhotos.receiver.php",true);
		objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		objRequest.onreadystatechange=function(){
			if(objRequest.readyState==4)
			{
				if(objRequest.status==200)
				{
					//get response
					xmlSuccess=objRequest.responseXML.documentElement.getElementsByTagName("success")[0];
					//get message
					xmlMessage=objRequest.responseXML.documentElement.getElementsByTagName("message")[0];
					//get photoId of switched item
					xmlOrderId=objRequest.responseXML.documentElement.getElementsByTagName("orderId")[0];
					
					//move up in list
					if(xmlSuccess.childNodes[0].nodeValue=="1")
					{
						//find list item
						objListItem=document.getElementById("photoListItem"+intPhotoId);
						objListItemLower=document.getElementById("photoListItem"+xmlOrderId.childNodes[0].nodeValue);
						
						//switch list items
						objListItemHolder=objListItem.cloneNode(true);
						objParent=objListItem.parentNode;
						objParent.replaceChild(objListItemLower.cloneNode(true),objListItem);
						objParent.replaceChild(objListItemHolder,objListItemLower);
					}
					
					//set message
					setMessage(xmlMessage);
				}
				else
				{
					//set error message
					document.getElementById("message").innerHTML="<div>Error moving photo ("+objRequest.status+")</div>";
					blnSuccess=false;
				}
			}
		};
		//create post string
		strPost="action=moveUp&galleryId="+intGalleryId.toString()+"&photoId="+intPhotoId.toString();
		//send request
		objRequest.send(strPost);
	}
	
	//change order position of photo
	function photoMoveDown(intGalleryId,intPhotoId)
	{
		//create request object
		objRequest=LJ.createRequest();
		objListItem=null;
		objListItemHigher=null;
		objListItemHolder=null;
		blnSuccess=true;
		
		//set request object
		objRequest.open("POST","/assets/php/LJPhotos.receiver.php",true);
		objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		objRequest.onreadystatechange=function(){
			if(objRequest.readyState==4)
			{
				if(objRequest.status==200)
				{
					//get response
					xmlSuccess=objRequest.responseXML.documentElement.getElementsByTagName("success")[0];
					//get message
					xmlMessage=objRequest.responseXML.documentElement.getElementsByTagName("message")[0];
					//get photoId of switched item
					xmlOrderId=objRequest.responseXML.documentElement.getElementsByTagName("orderId")[0];
					
					//move up in list
					if(xmlSuccess.childNodes[0].nodeValue=="1")
					{
						//find list item
						objListItem=document.getElementById("photoListItem"+intPhotoId);
						objListItemHigher=document.getElementById("photoListItem"+xmlOrderId.childNodes[0].nodeValue);
						
						//switch list items
						objListItemHolder=objListItem.cloneNode(true);
						objParent=objListItem.parentNode;
						objParent.replaceChild(objListItemHigher.cloneNode(true),objListItem);
						objParent.replaceChild(objListItemHolder,objListItemHigher);
					}
					
					//set message
					setMessage(xmlMessage);
				}
				else
				{
					//set error message
					document.getElementById("message").innerHTML="<div>Error moving photo ("+objRequest.status+")</div>";
					blnSuccess=false;
				}
			}
		};
		//create post string
		strPost="action=moveDown&galleryId="+intGalleryId.toString()+"&photoId="+intPhotoId.toString();
		//send request
		objRequest.send(strPost);
	}
	
	//select photo to be the thumbnail for the gallery
	function photoThumbnailSelect(intGalleryId,intPhotoId)
	{
		//create request object
		objRequest=LJ.createRequest();
		blnSuccess=true;
		
		//set request object
		objRequest.open("POST","/assets/php/LJPhotos.receiver.php",true);
		objRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		objRequest.onreadystatechange=function(){
			if(objRequest.readyState==4)
			{
				if(objRequest.status==200)
				{
					//get response
					xmlSuccess=objRequest.responseXML.documentElement.getElementsByTagName("success")[0];
					//get message
					xmlMessage=objRequest.responseXML.documentElement.getElementsByTagName("message")[0];
					
					//set message
					setMessage(xmlMessage);
				}
				else
				{
					//set error message
					document.getElementById("message").innerHTML="<div>Error selecting gallery thumbnail ("+objRequest.status+")</div>";
					blnSuccess=false;
				}
			}
		};
		//create post string
		strPost="action=thumbnailSelect&galleryId="+intGalleryId.toString()+"&photoId="+intPhotoId.toString();
		//send request
		objRequest.send(strPost);
	}
	
	//highlight a photo list item when checked
	function highlightPhotoListItem(objInput)
	{
		objTr=objInput;
		
		//find parent tr tag
		while(!objTr.tagName || objTr.tagName.toLowerCase()!="tr")
		{
			objTr=objTr.parentNode;
		}
		
		//toggle className of tr tag
		if(objInput.checked)
		{
			objTr.className="highlight";
		}
		else
		{
			objTr.className="";
		}
	}
	
	//return the filename part of a complete path/filename
	function filename(strPath)
	{
		var intPos=0;
		
		//find last back slash
		intPos=strPath.lastIndexOf("\\");
		
		if(intPos==-1)
		{
			//find last forward slash
			intPos=strPath.lastIndexOf("/");
		}
		
		if(intPos!=-1)
		{
			strPath=strPath.substring(intPos+1);
		}
		
		return strPath;
	}
	
	//strips the "px" from a style value and return an integer
	function stripPx(strValue)
	{
		return parseInt(strValue.replace("px",""),10);
	}

	//return the x coordinate of an object relative to the body
	function getXPosRelBody(obj)
	{
		//declare variables
		var intReturnValue=0;
		
		//add current offsetLeft
		intReturnValue+=obj.offsetLeft;
		
		if(obj.offsetParent && obj.offsetParent.tagName.toLowerCase()!="body")
		{
			//add parent offsetLeft
			intReturnValue+=getXPosRelBody(obj.offsetParent);
		}
		
		return intReturnValue;
	}
	
	//return the y coordinate of an object relative to the body
	function getYPosRelBody(obj)
	{
		//declare variables
		var intReturnValue=0;
		
		//add current offsetLeft
		intReturnValue+=obj.offsetTop;
		
		if(obj.offsetParent && obj.offsetParent.tagName.toLowerCase()!="body")
		{
			//add parent offsetLeft
			intReturnValue+=getYPosRelBody(obj.offsetParent);
		}
		
		return intReturnValue;
	}
	
	//return the x coordinate of an object relative to the viewport
	function getXPosRelViewport(obj)
	{
		//declare variables
		var intReturnValue=0;

		//calculate position
		intReturnValue=getXPosRelBody(obj)-getXScroll;
		
		return intReturnValue;
	}
	
	//return the y coordinate of an object relative to the viewport
	function getYPosRelViewport(obj)
	{
		//declare variables
		var intReturnValue=0;

		//calculate position
		intReturnValue=getYPosRelBody(obj)-getYScroll();
		
		return intReturnValue;
	}
	
	//return current scroll amount from the top
	function getXScroll()
	{
		//declare variables
		var intReturnValue=0;
		
		//get horizontal scroll
		if(document.documentElement && document.documentElement.scrollLeft) //all except Safari
		{
			intReturnValue=document.documentElement.scrollLeft;
		}
		else if(self.pageXOffset) //Safari
		{
			intReturnValue=self.pageXOffset;
		}

		return intReturnValue;
	}
	
	//return current scroll amount from the left
	function getYScroll()
	{
		//declare variables
		var intReturnValue=0;
		
		//get vertical scroll
		if(self.pageYOffset) //all except Explorer
		{
			intReturnValue=self.pageYOffset;
		}
		else if(document.documentElement && document.documentElement.scrollTop) //all except Safari
		{
			intReturnValue=document.documentElement.scrollTop;
		}

		return intReturnValue;
	}
	
	//return viewport width
	function getViewportWidth()
	{
		//declare variables
		var intReturnValue=0;
		
		/*
		if(document.documentElement && document.documentElement.clientWidth) //all
		{
			intReturnValue=document.documentElement.clientWidth;
		}
		else if(self.innerWidth) //backup
		{
			intReturnValue=self.innerWidth;
		}
		*/
		
		//use offsetWidth instead of innerWidth or clientWidth, since FireFox and Opera don't account for the scroll bar with those
		intReturnValue=document.body.offsetWidth;
		
		return intReturnValue;
	}
	
	//return viewport height
	function getViewportHeight()
	{
		//declare variables
		var intReturnValue=0;
		
		if(document.documentElement && document.documentElement.clientHeight) //all (inaccurate for Opera)
		{
			intReturnValue=document.documentElement.clientHeight;
		}
		else if(self.innerHeight) //all except IE
		{
			intReturnValue=self.innerHeight;
		}
		
		/*
		//Opera has reveresed values for document.documentElement and document.body
		if(isOpera() && document.body.clientHeight)
		{
			intReturnValue=document.body.clientHeight;
		}
		*/
		
		return intReturnValue;
	}
	
	//set the message on the page from a passed xml message object
	function setMessage(xmlMessage)
	{
		//set message
		if(xmlMessage)
		{
			if(xmlMessage.childNodes[0] && xmlMessage.childNodes[0].nodeValue.length>0)
			{
				document.getElementById("message").innerHTML="<div>"+xmlMessage.childNodes[0].nodeValue+"</div>";
			}
			else
			{
				if(document.getElementById("message").innerHTML!="")
				{
					document.getElementById("message").innerHTML="";
				}
			}
		}
	}
}