var NYM = NYM || {};
NYM.ss = NYM.ss || {};

NYM.ss.fn = function () {

	var C = { // CONFIGS && CONSTANTS
		"preLoadImgs": 3
	}

	var E = { // ELEMENTS
		"content": $("#gallery_content"),
		"slide": $("#gallery_main"),
		"thumb": $("#gallery_thumbs"),
		"title": $("#gallery_headline"),
		"description": $("#gallery_caption"),
		"credit": $("#gallery_credit"),
		"slideNum": $("#gallery_num"),
		"slideCount": $("#gallery_total"),
		"prev": $("#gallery_previous_top"),
		"next": $("#gallery_next_top"),
		"lastSlide": $("#gallery_finish")
	}

	// private, empty objects. we'll use these later and attach things to them.
 	var ssPrevSlide = {};
 	var ssCurrentSlide = {};
 	var ssNextSlide = {};
	var is_list = false;
	var is_countdown;

	// private vars
	var ssUrl,ssData,slideshowClass,lastslideClass;
	
	
	return {
	    showHide: function (action) {
	    	
	    	if (action == "show"){
	    		E.content.addClass('active');
				if ($("#blog").hasClass(lastslideClass)) {
					$("#blog").removeClass(lastslideClass);
					$("#blog").addClass(slideshowClass);
				} else {
					$("#blog").addClass(slideshowClass);
				}
				$("#entry_content, #gallery_finish").hide();
				$("#gallery_content, #gallery_main, #nav_top, #nav_bottom").show();
				$("#kicker").css("visibility","visible");

				if (is_list) {
					$(".slide-kicker").find("h5.slide-count, h4.slide-title").remove();
				} else {
					$("#gallery_num").css("display","inline");
				}
			} else if (action == "hide") {
				E.content.removeClass('active');
				$("#blog").removeClass(lastslideClass + " " + slideshowClass);
				$("#entry_content").show();
				$("#gallery_content").hide();
			}
		
	    },
	    getData: function () {
	    	
				$.ajax({
					url: NYM.ss.data.url,
					success: function(data){
						ssData = data;					
						if (ssData.numberingMode.name.toLowerCase() == "countup" || ssData.numberingMode.name.toLowerCase() == "countdown") {
							is_list = true;
							if (ssData.numberingMode.name.toLowerCase() == "countdown") {
								is_countdown = true;
							}
						}
                                		if (is_list) {
                                        		slideshowClass = 'slideshow-list-single';
		                                        lastslideClass = 'slideshow-list-lastslide';
       			                        } else {
                       			                 slideshowClass = 'slideshow-single';
                                       			 lastslideClass = 'slideshow-lastslide';
                                		}
						NYM.ss.fn.init();
						var firstSlideId = ssData.slides[0].assetId;
						$(".launch-slideshow a, .photo-gallery-link a").attr("href","#photo=1x" + firstSlideId);
					}
				});
	    },
	    checkHash: function () {
	    		if(typeof ssData.slides == "undefined"){
	    			NYM.ss.fn.getData();
	    		} else {
				var hash = location.hash;
				var num = 0;
				if (hash.match(/#photo=(\d+)/)){ //check for a #photo= pattern in the URL
					if (!(E.content.hasClass('active'))) {
						NYM.ss.fn.showHide("show");
					}
					num = hash.match(/#photo=(\d+)/)[1] - 1; //set the slide position by matching the number URL
					if (hash.match(/#photo=(\d+)x(\d+)/)) { //check for a #photo=NxID pattern in the URL
						for (var i = ssData.slides.length; i > 0; i -= 1) { // has the slide order changed? we should try to make a match on the assetID.
                                                       if (hash.match(/#photo=(\d+)x(\d+)/)[2] == ssData.slides[i-1].assetId) { //if we make a match and it is not what is currently displayed
								num = i - 1; // set the position to this slide
							}
						}
					}
					NYM.ss.fn.loadSlide(num); // load the correct slide
					NYM.ss.fn.preLoadSlides(num);
					NYM.ss.fn.recordPageView();
					;
				} else if (hash == "#end-slideshow") {
					num = ssData.slides.length -1;
					NYM.ss.fn.lastSlide(num);
					NYM.ss.fn.recordPageView();
				} else {
					// closes slideshow if no hash
					if ($("#gallery_content").hasClass("active")) {
						hideSlideshow();
					}
				}

				}
	    },
	    getAssetId: function(n) {
		return ssData.slides[n].assetId;
	    },
	    lastSlide: function (n) {
	    	
				E.content.removeClass('active');
				window.nymag.dcads.reloadAds();
				ssCurrentSlide = ssData.slides[n];
				ssCurrentSlide.num = n + 1;
				ssCurrentSlide.display = false;
				$("#blog").removeClass(slideshowClass).addClass(lastslideClass);
				$("#entry_content, #gallery_main, #nav_bottom, h5#gallery_num, #kicker #gallery_num").hide();
				$("#gallery_finish, #gallery_content, #nav_top").show();
				$("#kicker").css("visibility", "hidden");
				E.content.addClass("lastSlideActive")
				NYM.ss.fn.prevNext();

	    },
	    loadSlide: function (n) {
		window.nymag.dcads.reloadAds();
	    	ssCurrentSlide = ssData.slides[n];
	    	ssCurrentSlide.num = n + 1;
	    	ssCurrentSlide.display = true;
			ssCurrentSlide.displayNumber = n + 1;

			if (is_countdown) {
				ssCurrentSlide.displayNumber = ssData.slides.length - n;
			}
			var slideClass = "no-" + ssCurrentSlide.displayNumber;
			var slideTitle = ssCurrentSlide.title;

	    	if (E.content.hasClass("lastSlideActive")) {
			E.content.removeClass("lastSlideActive")
	    	}

			E.title.html(ssCurrentSlide.title);
			E.description.html(ssCurrentSlide.description);
			if (ssCurrentSlide.photoCredit) {
				E.credit.html(ssCurrentSlide.photoCreditLabel + ": " +ssCurrentSlide.photoCredit);
			} else {
				E.credit.empty();
			}
			E.slideNum.html(ssCurrentSlide.num);
				$("#gallery_num").show();
			if (ssCurrentSlide.videoEmbedHtml) {
				var elem = document.createElement("div");
                                    var video = ssCurrentSlide.videoEmbedHtml;
				elem.setAttribute("id","video-embed");
				elem.innerHTML = video;
				var w = $(elem).find("object").attr("width");
				var h = $(elem).find("object").attr("height");
				if (is_list) {
					// resize videos for list view
					var nh = (425*h)/w;
					nh = Math.round(nh);
					$(elem).find("object, embed").attr("width",425);
					$(elem).find("object, embed").attr("height",nh);
				}
				
                                    E.slide.html(elem);
			} else if (ssCurrentSlide.assetPath.length > 0) {
				imgSrc = ssCurrentSlide.assetPath;
				var elem = "<img src='"+imgSrc+"' />";
				E.slide.html(elem);
			}
			$("h5#gallery_num").removeClass().addClass("slidecount " + slideClass).html(slideClass);
			$("h4#gallery_headline").html(slideTitle);
			NYM.ss.fn.prevNext();
			var currHash = window.location.hash;
			var isSlide = currHash.indexOf("x");
	    },
	    preLoadSlides: function(n) {
	    	
			var prevSlide;
			var nextSlide;
			var totalSlides = ssData.slides.length - 1;
			if (n == totalSlides) {
				nextSlide = ssData.slides[0].assetPath;
			} else {
				nextSlide = ssData.slides[n+1].assetPath;
			}
			if (n == 0) {
				prevSlide == null;
			} else {
				prevSlide = ssData.slides[n-1].assetPath;
			}
			if ($('#preloading').length == 0) {
				$('body').append('<div style="display:none;" id="preloading"></div>');
			}
			if (nextSlide) { var nextPath = '<img src="'+nextSlide+'" />'; }
			if (prevSlide) { var prevPath = '<img src="'+prevSlide+'" />'; }
			$("#preloading").html(prevPath + nextPath);
			$("#preloading img").load(function() {
				$(this).remove();
			});
		
	    },
	    prevNext: function () {
	    	
	    	var prevHref,nextHref;
	    	ssCurrentSlide.num;
		lastSlideNum = ssData.slides.length -1;
		lastAssetId = NYM.ss.fn.getAssetId(lastSlideNum);
		
	    	//PREV LOGIC
	    	if (!(ssCurrentSlide.display)) {
	    		ssPrevSlide.num = ssCurrentSlide.num;
	    		prevHref = "#photo=" + ssPrevSlide.num + "x" + lastAssetId;
	    		E.prev.attr("href",prevHref);
	    	} else if (ssCurrentSlide.num <= 1 && ssCurrentSlide.display) {
	    		prevHref = "#";
	    		E.prev.attr("href",prevHref).parent("li").addClass("inactive").removeClass("active");
	    	} else if (ssCurrentSlide.num > 1 && ssCurrentSlide.display) {
	    		ssPrevSlide.num = ssCurrentSlide.num - 1;
			prevAssetId = NYM.ss.fn.getAssetId(ssPrevSlide.num-1);
	    		var prevHref = "#photo=" + ssPrevSlide.num + "x" + prevAssetId;
	    		E.prev.attr("href",prevHref).parent("li").addClass("active").removeClass("inactive");
	    	}
	    	
	    	//NEXT LOGIC
	    	if (!(ssCurrentSlide.display)) {
	    		nextHref = "#";
	    		E.next.attr("href",nextHref).parent("li").addClass("inactive").removeClass("active");  	
	    	} else if (ssCurrentSlide.num >= ssData.slides.length && ssCurrentSlide.display) {
	    		nextHref = "#end-slideshow";
	    		E.next.attr("href",nextHref).parent("li").addClass("active").removeClass("inactive");
	    	} else if (ssCurrentSlide.num < ssData.slides.length && ssCurrentSlide.display) {
	    		ssNextSlide.num = ssCurrentSlide.num + 1;
			var nextAssetId = NYM.ss.fn.getAssetId(ssNextSlide.num-1);
	    		nextHref = "#photo=" + ssNextSlide.num + "x" + nextAssetId;
	    		E.next.attr("href",nextHref).parent("li").addClass("active").removeClass("inactive");;
	    	}
	    },
	    recordPageView: function() {
			var title = document.title;
			var url = window.location.href;
			nymag_setMetadata({'content.type' : 'Blog'});
			nymag_setMetadata({'content.subtype' : 'Blog Slideshow'});
			nymag_setMetadata({'content.pagename' : url});
			nymag_pageView();
	    },
			primer: function () {
				NYM.ss.fn.getData();
			},
			init: function () {
				
				// Bind an event to window.onhashchange that, when the hash changes, gets the
			  // hash and adds the class "selected" to any matching nav link.
				$(window).hashchange( function() {
					NYM.ss.fn.checkHash();
				});
			  // Since the event is only triggered when the hash changes, we need to trigger
			  // the event now, to handle the hash the page may have loaded with.
				$(window).hashchange();
				//NYM.ss.fn.ui();  commenting out for now
				E.slideCount.html(ssData.slideCount);
			} // end init()
	};

}(); // end NYM.ss.fn

var is_list = '';
var is_countdown = 0;
var mainImage = 'gallery_main';
var thumbContainer = 'gallery_thumbs';
var headlineContainer = 'gallery_headline';
var captionContainer = 'gallery_caption';
var textContainer = 'gallery_text';
var creditContainer = 'gallery_credit';
var imageNumber = 'gallery_num';
var galleryTotal = 'gallery_total';
var previousButtonTop = 'gallery_previous_top';
var nextButtonTop = 'gallery_next_top';
var previousButtonBottom = 'gallery_previous_bottom';
var nextButtonBottom = 'gallery_next_bottom';
var tagContainer = 'gallery_tags';
var first=true;
/* end of container names */
/* global stuff */
var numPhotos;
var galleryNext;
var galleryPrev;
// init
var thumbsLoaded = 0;
var galleryArray;
var currentPhoto;
/* ** */
try {jQuery(document).ready(function(){
	if(typeof window.nymag == 'undefined') window.nymag = {};
	window.nymag_config = function nymag_config(s) {
		s.charSet="ISO-8859-1";
		s.currencyCode="USD";
		s.trackDownloadLinks=true;
		s.trackExternalLinks=true;
		s.trackInlineStats=true;
		s.linkDownloadFileTypes="exe,zip,wav,mp3,mov,mpg,avi,wmv,doc,pdf,xls";
		s.linkInternalFilters="javascript:,nymag.com,#";
		s.linkLeaveQueryString=false;
		s.linkTrackVars="None";
		s.linkTrackEvents="None";

		s.visitorNamespace="newyorkmagazine";
		s.dc=112;
		s.trackingServer="stats.nymag.com";
		s.trackingServerSecure="sstats.nymag.com";
		return s;
	}

	window.nymag_blogSlideTags = function(photo) {
		if((photo!=0) && !photo) return '';
		if(isNaN(parseInt(photo))) return '';
		photos = window.galleryData.photos;
		if(photos.length <= photo) return '';
		this_photo = photos[photo];
		tags = this_photo.tags;
		names = new Array();
		for(tag in tags) {
			names.push(";" + tags[tag].tagName);
		}
		return(names.join());
	}

	window.nymag_pageViewSlide = function(slide){
		nymag_setMetadata({
			'content.subtype' : 'Blog Slideshow',
			   'content.tags' : nymag_blogSlideTags(slide)
		});

		if(0>window.location.href.search('#')){
			nymag_setMetadata({'content.tags' : nymag_blogSlideTags(0)});
			nymag_pageView();
			window.nymag['pageViewRequestedBlog'] = true;
			return;
		}
		if(typeof window.nymag['pageViewRequestedBlog'] == "undefined"){
			nymag_setMetadata({'content.tags' : nymag_blogSlideTags(slide)});
			window.nymag['pageViewRequestedBlog'] = false;
			return;
		}
		nymag_pageView();
		window.nymag['pageViewRequestedBlog'] = true;
	};

});} catch (e) {}

function galleryInit() {
	if (typeof galleryData.photos === "undefined" || !NYM.ss){
	
		NYM.ss.fn.primer();
	
	}else{

		galleryArray = galleryData.photos
		numPhotos = galleryArray.length;
		currentPhoto = (r = document.location.href.match(/#photo=(\d+)/))?r[1]:0;
		currentPhoto = parseInt(currentPhoto);
		if (is_countdown && currentPhoto > 0) {
			//currentPhoto = Math.abs(numPhotos-currentPhoto)+1;
		}
	
		if (document.location.href.match(/#photo=(\d+)x(\d+)/)) {
			for (i=0; i<galleryArray.length; i++) {
				if (document.location.href.match(/#photo=(\d+)x(\d+)/)[2] == galleryArray[i].asset_id) {
					currentPhoto = i+1;
				}
			}
	 	}
	
		if (document.getElementById(thumbContainer) && currentPhoto <= 1) {
			writeThumbs();
		}
		
		if (is_list) {
			slideshowClass = 'slideshow-list-single';
			lastslideClass = 'slideshow-list-lastslide';
		} else {
			slideshowClass = 'slideshow-single';
			lastslideClass = 'slideshow-lastslide';
		}
		if (currentPhoto > 0) {
			writePhotos(currentPhoto);
		} else if (document.location.href.match(/#end-slideshow/)) {
			endSlideshow();
		}
	}
}

function writePhotos(num) {

	if (typeof galleryData.photos === "undefined" || !NYM.ss){
		NYM.ss.fn.checkHash();
		
	} else {

		launchSlideshow();
		window.nymag.dcads.reloadAds();
		if (document.getElementById(galleryTotal)) document.getElementById(galleryTotal).innerHTML = numPhotos;
		if ((typeof num).toLowerCase() == 'object' || num == undefined || num == '') {
			num = (currentPhoto>numPhotos)?numPhotos:currentPhoto;
			num = (num < 1)?1:num;
		}
		num = parseInt(num);
		photoTags = false;
		if(!isNaN(num)) photoTags = num - 1;
		if(typeof nymag_pageViewSlide == "function") nymag_pageViewSlide(photoTags);
		if (num > numPhotos) {
			endSlideshow();
		} else {
			galleryNext = num+1;
			galleryPrev = num-1;
			if (document.getElementById(imageNumber)) {
				document.getElementById(imageNumber).innerHTML = num;
			}
			if (is_list) {
				if (document.getElementById(imageNumber).className.match(/no-\d+/)) {
					if (is_countdown) {
						document.getElementById(imageNumber).className = document.getElementById(imageNumber).className.replace(/no-\d+/, 'no-' + Math.abs(numPhotos-(num-1)));
						} else {
							document.getElementById(imageNumber).className = document.getElementById(imageNumber).className.replace(/no-\d+/, 'no-' + num);
						}
				} else {
					if (is_countdown) {
						document.getElementById(imageNumber).className += " no-" + Math.abs(numPhotos-(num-1));
					} else {
						document.getElementById(imageNumber).className += " no-" + num;
					}
				}
			}
			num--; // subtract one to get the array index
			// populate data
			document.getElementById(mainImage).innerHTML = '';
			if (!galleryArray[num].type || galleryArray[num].type == 'image') {
				i = document.createElement('img');
				i.src = galleryArray[num].photo;
				document.getElementById(mainImage).appendChild(i);
				document.getElementById(previousButtonBottom).style.display = 'block';
				document.getElementById(nextButtonBottom).style.display = 'block';
				$('#nav_bottom').show();
			} else {
				div = document.createElement('div');
				div.id="tempDIV";
				document.getElementById(mainImage).appendChild(div);
				swfobject.embedSWF(galleryArray[num].photo, "tempDIV", 425, 344, "8.0.0");
				document.getElementById(previousButtonBottom).style.display = 'none';
				document.getElementById(nextButtonBottom).style.display = 'none';
				$('#nav_bottom').hide();
			}
			document.getElementById(headlineContainer).innerHTML = galleryArray[num].title;
			document.getElementById(captionContainer).innerHTML = galleryArray[num].caption;
			document.getElementById(creditContainer).innerHTML = galleryArray[num].credit;
			
			
			// populate next/prev
			document.getElementById(nextButtonTop).onclick = function() {
				if(0<=document.getElementById(nextButtonTop).parentNode.className.search('inactive')) return;
				writePhotos(galleryNext);
			}
			document.getElementById(previousButtonTop).onclick = function() {
				if(galleryPrev <= 0) return; 
				writePhotos(galleryPrev);
			}
			document.getElementById(nextButtonBottom).onclick = function() {
				writePhotos(galleryNext);
			}
			document.getElementById(previousButtonBottom).onclick = function() {
				if(galleryPrev <= 0) return; 
				writePhotos(galleryPrev);
			}
			setTimeout(function() {
				if (parseInt(galleryNext) <= numPhotos) {
					document.getElementById(nextButtonTop).innerHTML = galleryArray[parseInt(galleryNext)-1].title;
					document.getElementById(nextButtonBottom).innerHTML= galleryArray[parseInt(galleryNext)-1].title;
					if (is_countdown) {
						document.getElementById(nextButtonTop).href = "#photo=" + (parseInt(Math.abs(numPhotos-(parseInt(galleryNext)))+1));
						document.getElementById(nextButtonBottom).href = "#photo=" + (parseInt(Math.abs(numPhotos-(parseInt(galleryNext)))+1));
					} else {
						document.getElementById(nextButtonTop).href = "#photo=" + parseInt(galleryNext);
						document.getElementById(nextButtonBottom).href = "#photo=" + parseInt(galleryNext);
					}				
				} else {
					document.getElementById(nextButtonTop).innerHTML = '';
					document.getElementById(nextButtonBottom).innerHTML= '';
					document.getElementById(nextButtonTop).href = "#end-slideshow";
					document.getElementById(nextButtonBottom).href = "#end-slideshow";
				}
				document.getElementById(nextButtonTop).parentNode.className = document.getElementById(nextButtonTop).parentNode.className.replace(/inactive/g, '');
				
				if (parseInt(galleryPrev) > 0) {
					document.getElementById(previousButtonTop).innerHTML = galleryArray[parseInt(galleryPrev)-1].title;
					document.getElementById(previousButtonBottom).innerHTML = galleryArray[parseInt(galleryPrev)-1].title;
					if (is_countdown) {
						document.getElementById(previousButtonTop).href = "#photo=" + (parseInt(Math.abs(numPhotos-(parseInt(galleryPrev)))+1));
						document.getElementById(previousButtonBottom).href = "#photo=" + (parseInt(Math.abs(numPhotos-(parseInt(galleryPrev)))+1));
					} else {
						document.getElementById(previousButtonTop).href = "#photo=" + parseInt(galleryPrev);
						document.getElementById(previousButtonBottom).href = "#photo=" + parseInt(galleryPrev);
					}
					document.getElementById(previousButtonTop).parentNode.className = document.getElementById(previousButtonTop).parentNode.className.replace(/inactive/g, '');
					document.getElementById(previousButtonBottom).parentNode.className = document.getElementById(previousButtonBottom).parentNode.className.replace(/inactive/g, '');
				
				} else {
					document.getElementById(previousButtonTop).parentNode.className += " inactive";
					document.getElementById(previousButtonBottom).parentNode.className += " inactive";
				}
				if ((!(document.location.href.match(/#photo=(\d+)x(\d+)/))) && document.location.href.match(/#photo/)) 
					document.location = document.location + 'x'+galleryArray[num].asset_id;
			}, 100);
		}
	}
	
}

function writeThumbs(num) {
	if (thumbsLoaded) return 0;
	galleryArray = galleryData.photos
	thumbs = document.getElementById(thumbContainer);
	thumbsLoaded = 1;
	for (x=0;x<galleryArray.length;x++) {
		var img = document.createElement('img');
		thumbs.appendChild(img);
		img.src = galleryArray[x].thumb;
		img.className = 'gallery_thumbnail';
		img.setAttribute('num', x+1);
		img.setAttribute('id',thumbContainer + '_' + (x+1));
		img.onclick = function() {
			r = new RegExp(thumbContainer + '_(\\d+)');
			writePhotos(parseInt(this.id.match(r)[1]));
		}
		if (x == num) {
			img.className += ' selected';
		}
	}
}

function launchSlideshow() {
	if (currentPhoto == 0) currentPhoto = 1;
	if (document.getElementById('blog').className.match(new RegExp(lastslideClass))) {
		document.getElementById('blog').className = document.getElementById('blog').className.replace(new RegExp(lastslideClass), ' ' + slideshowClass);
	} else {
		if (!document.getElementById('blog').className.match(new RegExp(slideshowClass))) document.getElementById('blog').className += ' ' + slideshowClass;
	}
	document.getElementById('entry_content').style.display = 'none';
	document.getElementById('gallery_finish').style.display = 'none';
	document.getElementById('gallery_content').style.display = 'block';
	document.getElementById('gallery_main').style.display = 'block';
	document.getElementById('nav_top').style.display = 'block';
	document.getElementById('nav_bottom').style.display = 'block';
	document.getElementById('kicker').style.visibility = 'visible';
	if (is_list) {
		document.getElementById('gallery_num').style.display = 'block';
	} else {
		document.getElementById('gallery_num').style.display = 'inline';
	}
	
	
	
}

function hideSlideshow() {
	if (typeof galleryData.photos === "undefined" || !NYM.ss){
		NYM.ss.fn.showHide("hide");
	} else {

		if (document.getElementById('blog').className.match(new RegExp(lastslideClass))) {
			document.getElementById('blog').className = document.getElementById('blog').className.replace(new RegExp(lastslideClass), '');
		} else {
			document.getElementById('blog').className = document.getElementById('blog').className.replace(new RegExp(' ' + slideshowClass), '');
		}
		document.getElementById('entry_content').style.display = 'block';
		document.getElementById('gallery_content').style.display = 'none';
	
	}
	
	
}


function endSlideshow() {
	if (document.getElementById('blog').className.match(new RegExp(slideshowClass))) {
		document.getElementById('blog').className = document.getElementById('blog').className.replace(new RegExp(slideshowClass), lastslideClass);
	} else {
		document.getElementById('blog').className += " " + lastslideClass;
	}
	
	document.getElementById('entry_content').style.display = 'none';
	document.getElementById('gallery_finish').style.display = 'block';
	document.getElementById('gallery_content').style.display = 'block';
	document.getElementById('gallery_main').style.display = 'none';
	document.getElementById('nav_top').style.display = 'block';
	document.getElementById('nav_bottom').style.display = 'none';
	document.getElementById('kicker').style.visibility = 'hidden';
	document.getElementById('gallery_num').style.display = 'none';

	document.getElementById(previousButtonTop).parentNode.className = document.getElementById(previousButtonTop).parentNode.className.replace(/inactive/g, '');	
	document.getElementById(nextButtonTop).parentNode.className += " inactive";
	document.getElementById(previousButtonTop).onclick = function() {
		writePhotos(numPhotos);
	}
	if (is_countdown) {
		document.getElementById(previousButtonTop).href = "#photo=" + (parseInt(Math.abs(numPhotos-(parseInt(numPhotos)))+1));
	} else {
		document.getElementById(previousButtonTop).href = "#photo=" + parseInt(numPhotos);
	}

	currentPhoto = 0;
}

//Gallery Init function call
$(document).ready(function() {
	galleryInit();
});

