/**
 * @classDescription This class is the base data element class used by the PhotoViewer
 * to allow it to cycle through various instances of this class.
 * As such this class only holds attributes which it offer (s|g)etters for.
 * 
 * @author Kit C. Dallege
 */
function Photo(){
	this.name = "";
	this.userId = "";
	this.imgSrc = "";
	this.image = new Image();
	this.date = "";
	this.submittedBy = "";
	this.description = "";
	this.viewCount = "";
	this.dataId = "";
	this.resultNumber = 0;
	
}

Photo.prototype.getName = function(){
	return this.name;
};	

Photo.prototype.getUserId = function(){
	return this.userId;
};

Photo.prototype.getImgSrc = function(){
	return this.imgSrc;
};

Photo.prototype.getImage = function(){
	return this.image;
};

Photo.prototype.getDate = function(){
	return this.date;
};

Photo.prototype.getSubmittedBy = function(){
	return this.submittedBy;
};

Photo.prototype.getDescription = function(){
	return this.description;
};

Photo.prototype.getViewCount = function(){
	return this.viewCount;
};

Photo.prototype.getDataId = function(){
	return this.dataId;
};

Photo.prototype.getResultNumber = function(){
	return this.resultNumber;
};

Photo.prototype.setName = function(newName){
	this.name = newName;
};	

Photo.prototype.setUserId = function(newUserId){
	this.userId = newUserId;
};

Photo.prototype.setImgSrc = function(newImgSrc){
	this.imgSrc = newImgSrc;
};

Photo.prototype.setImage = function(newImage){
	//console.info("Set image called");
	this.image = newImage;
};

Photo.prototype.setDate = function(newDate){
	this.date = newDate;
};

Photo.prototype.setSubmittedBy = function(newSubmittedBy){
	this.submittedBy = newSubmittedBy;
};

Photo.prototype.setDescription = function(newDescription){
	this.description = newDescription;
};

Photo.prototype.setViewCount = function(newViewCount){
	this.viewCount = newViewCount;
};

Photo.prototype.setDataId = function(newDataId){
	this.dataId = newDataId;
};

Photo.prototype.setResultNumber = function(newResultNumber){
	this.resultNumber = newResultNumber;
};

/**
 * @method isLoaded Whether or not the image member is loaded
 * @return boolean returns true if the image has been loaded..
 */
Photo.prototype.isLoaded = function(){
	var isLoaded = false;
	if(this.image.src.length > 0){
		isLoaded = true;
		return isLoaded;
	}else{
		return isLoaded;
	}	
};

/**
 * Used to load the image from the server into a JavaScript Image object
 * member variant of the Photo object... 
 * @method load
 * @param {Object} id
 */
Photo.prototype.load = function(id){
	//console.info("loading image \n name: " + this.name);
	this.image.id = id;
	this.image.src = this.imgSrc;
	this.image.name = this.name;
	this.image.onload = function(){/*console.info("Photo.load.onload Image has been loaded");*/};
};

/**
 * Used for debugging the Photo object, give a good dump of the current
 * values of everything... 
 * @method toString
 * @return string 	Debug output of all the Photo attributes...
 */
Photo.prototype.toString = function(){
	var returnString = "";
	returnString += " Name: " + this.name;
	returnString += "\n ImgSrc: " + this.imgSrc;
	returnString += "\n Date: " + this.date;
	returnString += "\n Submitted By: " + this.submittedBy;
	returnString += "\n Description: " + unescape(this.description);
	returnString += "\n ViewCount: " + this.viewCount;
	returnString += "\n Data Id: " + this.dataId;
	returnString += "\n Result Number: " + this.resultNumber;
	
	return returnString;
};


/**
 * @classDescription  This is the main class which acts as the controller for a 
 * NodeList of Photo objects. This class provides a high level
 * interface for use with an event driven Photo Gallery
 * slide show and navigation widget.
 * @constructor 
 * @author Kit C. Dallege
 */
function PhotoViewer(){
	this.baseUrl = "";
	this.photos = [];
	this.playDelay = 5;
	this.startNumber = 0;
	this.stopNumber = 0;
	this.totalPhotos = 0;
	this.pageSize = 0;
	this.photoElementId = "mainImage";
	this.descriptionId = "description";
	this.titleId = "title";
	this.submittedById = "userId";
	this.dateId = "dateSubmitted";
	this.viewCountId = "numOfViews";
	this.resultNumberId = "resultNumber";
	this.prevLinkId = "prevLink";
	this.nextLinkId = "nextLink";
	this.currentPhotoNumber = "";
	this.fileStripImageId = "results";
	this.emailLink = "emailLink";
}
PhotoViewer.prototype.setCurrentPhotoNumber = function(newCurrentPhotoNumber){
	this.currentPhotoNumber = newCurrentPhotoNumber;
	//this.setLinkVisibility();
};

PhotoViewer.prototype.getCurrentPhotoNumber = function(){
	return this.currentPhotoNumber;
};

PhotoViewer.prototype.setBaseUrl = function(newBaseUrl){
	this.baseUrl = newBaseUrl;
};

PhotoViewer.prototype.getBaseUrl = function(){
	return this.baseUrl;
};

PhotoViewer.prototype.add = function(newPhoto){
	this.photos[this.photos.length] = newPhoto;
};

PhotoViewer.prototype.toString = function(){
	var returnString = "";
	//console.info("Photo Array().length = " +this.photos.length);
	for(var x = 0, y = this.photos.length; x < y; x++){
		returnString += this.photos[x].toString();
		returnString += "\n===============================\n";
	}
	return returnString;
};
PhotoViewer.prototype.setTotalPhotos = function(totalNum){
	this.totalPhotos = totalNum;	
};

PhotoViewer.prototype.getTotalPhotos = function(){
	return this.totalPhotos;
};

PhotoViewer.prototype.setPageSize = function(newPageSize){
	this.pageSize = newPageSize;
};

PhotoViewer.prototype.setStartNumber = function(newStartNumber){
	this.startNumber = (parseInt(newStartNumber,10) -1);
	this.setCurrentPhotoNumber(this.startNumber);
	this.photos[this.startNumber].load(this.photoElementId);
};
/**
 * 
 * @param {Object} photoNumber
 */
PhotoViewer.prototype.setCurrentPhoto = function(photoNumber){
	//console.info("PhotoViewer.setCurrentPhoto(" + photoNumber + ") \n Photo Name: "+ this.photos[photoNumber].name);

	if(photoNumber < this.photos.length && photoNumber >= 0){
		try{
			//set the email a friend link
				document.getElementById("emailLink").href = '/sp?p=photogallery/emailfriend&id=' +	this.photos[photoNumber].getDataId() + "&skin=" + getURLParam("skin");
						
			//set the image 
			//check to see if the image has been loaded
			//console.info("Image is loaded... = " + image_loaded);
			if(this.photos[photoNumber].isLoaded() === false){					
				this.photos[photoNumber].load(this.photoElementId);
			}
			
			//try to set the image from the photo's Image element
			//if that element isn't loaded yet
			//then set it with the src addess for the image and load it at render time
				document.getElementById(this.photoElementId).src = this.photos[photoNumber].getImage().src.length === 0?this.photos[photoNumber].getImgSrc():this.photos[photoNumber].getImage().src;
			//set the title
				document.getElementById(this.titleId).innerHTML = unescape(this.photos[photoNumber].getName());
			//set the date
				document.getElementById(this.dateId).innerHTML = this.photos[photoNumber].getDate();
			//set submitted by
				try{
					document.userSearch.userId.value = this.photos[photoNumber].getUserId();
					document.userSearch.name.value = this.photos[photoNumber].getSubmittedBy() + '\'s';
					document.getElementById("submittedBy").innerHTML =  this.photos[photoNumber].getSubmittedBy();
				}catch(e){}
		
			//set the viewCount
				document.getElementById(this.viewCountId).innerHTML = this.photos[photoNumber].getViewCount();
			//set the currently displayed result number
				document.getElementById(this.resultNumberId).innerHTML = this.photos[photoNumber].getResultNumber();
			//set highlight around image on film strip
				document.getElementById((this.fileStripImageId+ (photoNumber+1))).style.border = '2px solid #FF6600';
			//remove the highlight around the previously selected image	
				document.getElementById(this.fileStripImageId + (parseInt(this.currentPhotoNumber,10)+1)).style.border = "2px solid black";
			
			//set the description
				document.getElementById("pd_description").innerHTML = (unescape(this.photos[photoNumber].getDescription()));
			
		}catch(e){
			//alert(e);
			//console.info(e);
		}
		this.setCurrentPhotoNumber(photoNumber);
		//make a ajax call out and incriment the view count of the current photo
		setTimeout("incrimentCount(" + this.photos[this.currentPhotoNumber].getDataId() + "," + this.photos[this.currentPhotoNumber].getViewCount() + ")", 0);	
	}	
};

PhotoViewer.prototype.nextPhoto = function(){
	this.setCurrentPhoto(parseInt(this.currentPhotoNumber, 10)+1);
};

PhotoViewer.prototype.prevPhoto = function(){
	this.setCurrentPhoto(parseInt(this.currentPhotoNumber, 10)-1);
};

PhotoViewer.prototype.hasNext = function(){
	if(this.currentPhotoNumber < this.photos.length-1){
		return true;
	}else{
		return false;
	}
};

PhotoViewer.prototype.hasPrevious = function(){
	if(this.currentPhotoNumber > 0){
		return true;
	}else{
		return false;
	}
};

PhotoViewer.prototype.getNumberOfPhotos = function(){
	return this.photos.length + 1;
};

PhotoViewer.prototype.setLinkVisibility = function(){
	try{
		document.getElementById(this.nextLinkId).style.visibility = 'visible';
		document.getElementById(this.nextLinkId).style.visibility = 'visible';
	}catch(e){}
};

/**
 * The following is the implementation portion of the code..
 * It uses a series of functions which are called via html click events.
 * This code also makes use of a simple state machine in order to keep
 * from having a race condition if a user keeps hitting a perticular button
 */
	//constants 
	var STOP_STATE = 0;
	var PLAY_STATE = 1;
	var PAUSE_STATE = 2;
	
	var photoViewer = new PhotoViewer();
	var currentState = 0;
	
		
/**
 * This function acts as a central way to manage the current state of the photoviewer
 * based on UI input. In a way this function acts as a basic adapter between the 
 * UI and the PhotoViewer itself..
 * @param {String} A string containing the function you wish to call
 * @param {PhotoViewer} An instance of the PhotoViewer object..
 */
	function CALL(funct, photoViewer){
		//console.info("CALL(" +funct+ ", photoViewer)");
			updateButtonsState(funct);	//update the state of the buttons first so 
										//they remain responsive feeling...
										//-------------------------------------------
		switch(funct){
			case "Play":
				if(currentState != PLAY_STATE){
					//console.info("calling Play()");
					//console.info("setting currentState to PLAY_STATE");
					currentState = PLAY_STATE;
					togglePlayButton("on");
					Play(photoViewer);
				}
			break;
			case "Stop":
				if(currentState != STOP_STATE){
					//console.info("setting currentState to STOP_STATE");
					currentState = STOP_STATE;
					togglePlayButton("off");
					photoViewer.setCurrentPhoto(photoViewer.startNumber);					
				}
			break;
			case "Pause":
				if(currentState != PAUSE_STATE){
					//console.info("setting currentState to PAUSE_STATE");
					currentState = PAUSE_STATE;
					togglePlayButton("off");
				}
			break;
			case "Next":
				if(currentState != PLAY_STATE){
					if(photoViewer.hasNext()){
						photoViewer.nextPhoto();
					}else{
						if((photoViewer.getTotalPhotos()) > photoViewer.photos[photoViewer.photos.length-1].resultNumber){
							if(document.getElementById("photoViewerForm")){
								//console.info("document.photoViewerForm.sNum.vaule + photoViewer.photos.length: " + (parseInt(document.photoViewerForm.sNum.value,10) + parseInt(photoViewer.photos.length,10)));
								CALL("Pause", photoViewer);
								document.photoViewerForm.sNum.value = (parseInt(document.photoViewerForm.sNum.value,10)) + (parseInt(photoViewer.photos.length,10));
								document.photoViewerForm.photoViewerCurrentState.value = "PAUSE_STATE";
								document.photoViewerForm.selectedPhotoNumber.value = 'start';
								setTimeout("document.photoViewerForm.submit()", 0);
								//console.info("loading next page...");
								return; 
							}
						}
					}
				}
			break;
			case "Previous":
				if(currentState != PLAY_STATE){
					if(photoViewer.hasPrevious()){
						photoViewer.prevPhoto();	
					}else{
						if(photoViewer.photos[0].resultNumber > 1){
							if(document.getElementById("photoViewerForm")){
								//console.info("document.photoViewerForm.sNum.vaule + photoViewer.photos.length: " + (parseInt(document.photoViewerForm.sNum.value,10) + parseInt(photoViewer.photos.length,10)));
								CALL("Pause", photoViewer);
								document.photoViewerForm.sNum.value = (parseInt(document.photoViewerForm.sNum.value,10)) - (parseInt(photoViewer.pageSize,10));
								document.photoViewerForm.photoViewerCurrentState.value = "PAUSE_STATE";
								document.photoViewerForm.selectedPhotoNumber.value = 'end';
								setTimeout("document.photoViewerForm.submit()", 0);
								//console.info("loading next page...");
								return; 
							}
						}
					}
				}
			break;
		}//end of switch
	}//end of function
	
	function resumeState(state){
		//console.info("resumeState:" + state);
		if(state == "PLAY_STATE"){			
			if(document.photoViewerForm.photo.value != (parseInt(photoViewer.photos[photoViewer.getCurrentPhotoNumber()].resultNumber,10))){
				CALL("Play", photoViewer);			
			}else{
				//console.info("Were at the end of our photos");
			}
		}else if(state == "STOP_STATE"){
			CALL("Stop", photoViewer);
		}else if(state == "PAUSE_STATE"){
			CALL("Pause", photoViewer);
		}	
	}
/***
 * The following method is a ugly but effective way of managing button states
 * for the Photo Viewer Application...
 * 
 * @author Kit C. Dallege
 * @param {Object} buttonPressed
 */
	function updateButtonsState(buttonPressed){
		//alert("updateButtonState called \n");
		if(currentState == PLAY_STATE){
			switch(buttonPressed){
				case "Stop":
					togglePlayButton("off");
				break;
				case "Play":
					//do nothing
				break;
				case "Pause":
					togglePlayButton("off");
					togglePauseButton("on");				
				break;	
			}					
		}else if(currentState == PAUSE_STATE){
			switch(buttonPressed){
				case "Stop":
					togglePlayButton("off");
					togglePauseButton("off");	
				break;
				case "Play":
					togglePlayButton("on");
					togglePauseButton("off");
				break;
				case "Pause":
					togglePauseButton("on");					
				break;	
			}
		}else if(currentState == STOP_STATE){
			switch(buttonPressed){
				case "Stop":
					//do nothing
				break;
				case "Play":
					togglePlayButton("on");
				break;
				case "Pause":
					//do nothing	
				break;	
			}
		}
	}
	
	function toggleStopButton(toggle){
		if(toggle == "on"){
			document.getElementById("pauseButton").src = '/photogallery/graphics/pauseButtonOn.gif'; 
		}else if(toggle == "off"){
			document.getElementById("pauseButton").src = '/photogallery/graphics/pauseButton.png';
			
		}		
	}
	
	function togglePauseButton(toggle){
		if(toggle == "on"){
			document.getElementById("pauseButton").src = '/photogallery/graphics/pauseButtonOn.gif'; 
		}else if(toggle == "off"){
			document.getElementById("pauseButton").src = '/photogallery/graphics/pauseButton.png';
			
		}
	}
	
	function togglePlayButton(toggle){
		if(toggle == "on"){
			document.getElementById("playButton").src = '/photogallery/graphics/playButtonOn.gif'; 
		}else if(toggle == "off"){
			document.getElementById("playButton").src = '/photogallery/graphics/playButton.png';
			
		}
	}
/**
 * 
 * @param {Object} photoViewer
 */
function Play(photoViewer){
	//console.info("Play Called");
	//set or global var with the current image number
	var currentlyVisibleImage = photoViewer.getCurrentPhotoNumber();
	preloadNextImage(photoViewer, parseInt(currentlyVisibleImage,10));
	//console.info("current photo is: "+ currentlyVisibleImage);	
	setTimeout("incrimentImage(photoViewer,"+ (currentlyVisibleImage + 1) +")", 2500);

}

/**
 * 
 * @param {Object} photoViewer
 * @param {Object} photoNum
 */
function incrimentImage(photoViewer, photoNum){
	//console.info("==============================\n");
	//console.info("incrimentImage called... \nPhoto Num = " + photoNum +"\n");
	
	//----------------------------------------------
	//If were playing still preload the next image
	//and set the current one
	//----------------------------------------------
	if(currentState == PLAY_STATE && photoNum < photoViewer.photos.length){
		preloadNextImage(photoViewer, photoNum);		
		photoViewer.setCurrentPhoto(photoNum);
	}
		
	//--------------------------------------------------------------------------
	//The following loads another page if there are still more photo's to show
	//--------------------------------------------------------------------------
	if(photoNum == photoViewer.photos.length){
		//console.info("if(photoNum == photoViewer.photos.length");
		//----------------------------------
		//if there are more pages of photos
		//-----------------------------------
		if((photoViewer.getTotalPhotos()) > photoViewer.photos[photoViewer.photos.length-1].resultNumber){
			if(document.getElementById("photoViewerForm")){
				//console.info("document.photoViewerForm.sNum.vaule + photoViewer.photos.length: " + (parseInt(document.photoViewerForm.sNum.value,10) + parseInt(photoViewer.photos.length,10)));
				CALL("Pause", photoViewer);
				document.photoViewerForm.sNum.value = (parseInt(document.photoViewerForm.sNum.value,10)) + (parseInt(photoViewer.photos.length,10));
				document.photoViewerForm.photoViewerCurrentState.value = "PLAY_STATE";
				document.photoViewerForm.selectedPhotoNumber.value = 'start'; 
				setTimeout("document.photoViewerForm.submit()",0);
				//console.info("loading next page...");
				return; 
			}
		}else if((photoViewer.getTotalPhotos()) == (parseInt(photoViewer.photos[photoViewer.photos.length-1].resultNumber,10))){
			//----------------------------------------------
			//we are on the last page so now load the first
			//----------------------------------------------
			if(document.getElementById("photoViewerForm")){
				//console.info("document.photoViewerForm.sNum.vaule + photoViewer.photos.length: " + (parseInt(document.photoViewerForm.sNum.value,10) + parseInt(photoViewer.photos.length,10)));
				CALL("Pause", photoViewer);
				document.photoViewerForm.sNum.value = 1;								  
				document.photoViewerForm.photoViewerCurrentState.value = "PLAY_STATE";
				
				document.photoViewerForm.selectedPhotoNumber.value = 'start'; 
				//document.photoViewerForm.photo.value = 1;
								
				setTimeout("document.photoViewerForm.submit()", 0);
				//console.info("loading first page...");
				return; 
			}					
		}//if((photoViewer.getTotalPhotos()-1) > photoViewer.photos[photoViewer.photos.length-1].resultNumber){
	}//if(photoNum == photoViewer.photos.length){
	
	//----------------------------------
	//if were at the start then stop...
	//----------------------------------
	if(photoViewer.photos[photoNum].resultNumber == document.photoViewerForm.photo.value){
		//console.info("photoViewer.photos[photoNum].resultNumber" + photoViewer.photos[photoNum].resultNumber + " == document.photoViewerForm.photo.value" + document.photoViewerForm.photo.value);
		photoViewer.startNumber = document.photoViewerForm.photo.value -1;
		CALL("Stop", photoViewer);
		return;
	}
	
	//console.info("Photo Name: "+photoViewer.photos[photoNum].name);
	//--------------------------------------------------------------
	//If were still in PLAY_STATE and still within the array bounds
	//we'll do another level of recursion.. 
	//--------------------------------------------------------------
	//console.info("if("+currentState + " == " + PLAY_STATE + ")");		
	if(currentState == PLAY_STATE){
		setTimeout("incrimentImage(photoViewer,"+ (photoNum + 1) +")", photoViewer.playDelay * 1000);
	}else{
		//console.info("currentState != PLAY_STATE");
	}
}

function preloadNextImage(photoViewer, photoNum){
	var nextPhotoNumber = photoNum + 1;	
	//console.info("preloadNextImage: nextPhotoNumber = " + nextPhotoNumber);
	//if we started on a photo other than the first one
	if(photoViewer.startNumber > 0){
		if(nextPhotoNumber == photoViewer.photos.length){
			nextPhotoNumber = 0;
		}
	}
	//if the next photo exsists call it's load method
	if(nextPhotoNumber < photoViewer.photos.length){
		//check if the image is already loaded
		if(photoViewer.photos[nextPhotoNumber].isLoaded() === false){
			photoViewer.photos[nextPhotoNumber].load(photoViewer.photoElementId);
		}else{
			//console.info("Image already loaded...");
		}
	}	
}

function preloadPreviousImage(photoViewer, photoNum){
	var prevPhotoNumber = photoNum -1;
	if(prevPhotoNumber <= 0){
		if(photoViewer.photos[prevPhotoNumber].isLoaded() === false){
			photoViewer.photos[prevPhotoNumber].load(photoViewer.photoElementId);
		}
	}
}
/**
 * 
 * @param {Object} photoViewer
 */
function loadImages(photoViewer){
	//console.info("loadImage called...\n loading image "+ photoViewer.getCurrentPhotoNumber() +" of " + photoViewer.photos.length);
	var img = new Image();
	img.id = photoViewer.photos[photoViewer.getCurrentPhotoNumber()].photoElementId;
	img.src = photoViewer.photos[photoViewer.getCurrentPhotoNumber()].getImgSrc();
	img.onload = function(){
		setImg(img, photoViewer, parseInt(photoViewer.getCurrentPhotoNumber(),10));
		photoViewer.setCurrentPhotoNumber(photoViewer.getCurrentPhotoNumber()+1);		
		if(photoViewer.getCurrentPhotoNumber() < photoViewer.photos.length){
			loadImages(photoViewer);
		}
	};	
}
	/**
	 * 
	 * @param {Object} img
	 * @param {Object} photoViewer
	 * @param {Object} imageNum
	 */
	function setImg(img, photoViewer, imageNum){
		 	//console.info("onload function called for photo " + photoViewer.getCurrentPhotoNumber());
		 	photoViewer.photos[imageNum].setImage(img);
		 	photoViewer.setCurrentPhotoNumber(imageNum);
	}	
/**
 * @param {PhotoViewer} Set to the desired image to open.
 */
	var myWindow = '';
	function openExpandedImage(photoViewer){
		
		var minWinWidth = minExpandedImageWindowSize<0?440:minExpandedImageWindowSize;
		if(photoViewer.photos[photoViewer.getCurrentPhotoNumber()].isLoaded() === false){
			//console.info("Image wasn't loaded\n loading image ");
			photoViewer.photos[photoViewer.getCurrentPhotoNumber()].load(photoViewer.photoElementId);
			setTimeout("openExpandedImage(photoViewer)", 2000);
		}else{
		
			var imgHeight = photoViewer.photos[photoViewer.getCurrentPhotoNumber()].getImage().height;
			imgHeight = imgHeight==0?0:imgHeight + 150;
			
			var imgWidth =  photoViewer.photos[photoViewer.getCurrentPhotoNumber()].getImage().width;
			imgWidth = imgWidth==0||imgWidth<minWinWidth?400:imgWidth;

			var filePath = "/sp?p=/photogallery/expandedImage&";
			var parameters = "dataId=" +photoViewer.photos[photoViewer.getCurrentPhotoNumber()].getDataId();
			parameters += "&skin=" +getURLParam("skin");
			
			if(!myWindow.closed && myWindow.location){
				myWindow.resizeTo((imgWidth+40), imgHeight);
				//myWindow.innerHeight = imgHeight;
				//myWindow.innerWidth = (imgWidth+40);
				myWindow.location = photoViewer.getBaseUrl()+ filePath + parameters;				
			}else{
				myWindow = window.open(photoViewer.getBaseUrl()+filePath+ parameters, "Enlarged", 'height='+imgHeight+', width='+(imgWidth+40)+',status=no, menubar=no, copyhistory=no, directories=no, scrollbars=yes, resizable=yes');
			}
			//console.info("Opening window with a width of "+ (imgWidth+40)+" and a height of "+ (imgHeight));
			
			if(window.focus){
				myWindow.focus();
			}
			incrimentCount(photoViewer.photos[photoViewer.currentPhotoNumber].getDataId(), photoViewer.photos[photoViewer.currentPhotoNumber].getViewCount());
		
		}
		return false;	
	}

function getURLParam(strParamName){
		var strReturn = "";
		var strHref = window.location.href;

		if ( strHref.indexOf("?") > -1 ){
			var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
			var aQueryString = strQueryString.split("&");

			for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
				if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
					var aParam = aQueryString[iParam].split("=");
					strReturn = aParam[1];
					break;
				}
			}
		}
		return strReturn;
	}

function incrimentCount(dataId, timesViewed){
	var PAGE = "/photogallery/lib/incrementCount.jsp";
	var request;
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
   	 	request = new XMLHttpRequest();
	} else if (window.ActiveXObject) { // IE
    	request = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if(request){
		request.open('GET', PAGE + "?dataId=" + dataId + "&type=view"+"&currentCount=" + timesViewed, true);
		request.send(null);
	}
}