$(document).ready(function(){
var intCurrentImg = 0;
var intTotalImages = ($("#photoGallery dd img").length)-1;

	$("#photoGallery dt").append("<img class=\"0\" src=\""+$("#photoGallery dd img:eq(0)").attr("src")+"\" />");  //onload Load first image
	$("#photoGallery dd > a:first").addClass("active");
	
	$("#photoGallery dd").each(function(ctNumber){
		$("#photoGallery dd img:eq("+ctNumber+")").addClass(""+ctNumber+"");
	});
	
	function removeActiveBorder(){ // remove active border
		$("#photoGallery dd > a").each(function(ctNumber){
			$("#photoGallery dd:eq("+ctNumber+") > a").removeClass("active");
		});
	}
	
	$("#photoGallery dd img").click(function(){ // thumbnails onClick Functionality
		removeActiveBorder();
		$("#photoGallery dt > img").attr("src", $(this).attr("src"));
		$("#photoGallery dt > img").attr("class", $(this).attr("class"));
		$("#photoGallery dd:eq("+$(this).attr("class")+") > a").addClass("active");
	});

	$("#nextGalleryButton").click(function(){ // next button function
		removeActiveBorder();
		var intCurrentImage = parseInt($("#photoGallery dt > img").attr("class"));
		
		if (intCurrentImage < intTotalImages){
			intImageEq = intCurrentImage+1;
		}else{
			intImageEq = 0;
		}
		
		$("#photoGallery dt > img").attr("src", $("#photoGallery dd img:eq("+intImageEq+")").attr("src"));
		$("#photoGallery dt > img").attr("class", intImageEq);
		$("#photoGallery dd:eq("+intImageEq+") > a").addClass("active");
	});

	
	$("#previousGalleryButton").click(function(){ // prevoius button function
		removeActiveBorder();
		var intCurrentImage = parseInt($("#photoGallery dt > img").attr("class"));
		
		if (intCurrentImage == 0){
			intImageEq = intTotalImages;
		}else{
			intImageEq = intCurrentImage-1;
		}
		$("#photoGallery dt > img").attr("src", $("#photoGallery dd img:eq("+intImageEq+")").attr("src"));
		$("#photoGallery dt > img").attr("class", intImageEq);
		$("#photoGallery dd:eq("+intImageEq+") > a").addClass("active");
	});
	
});		
