 var $jquery = jQuery.noConflict();
	$jquery(document).ready(function() {
		
		var thumbIndex = 0;
		//$("#flickr-gallery ul.thumbs").css({"width" : rowWidth + "px"});

		$jquery(".image-window a").bind("click", function(event) { 
			event.preventDefault();
		});
		
		$jquery(".flickr-photo").bind("click", function(event) { 
		
			event.preventDefault();
			thumbIndex = $jquery("#flickr-gallery ul.thumbs li a").index(this);
			
			$jquery("#image-placeholder").html("<img src="+$jquery(this).attr('href')+" alt="+$jquery(this).children('img').attr('alt')+" />");
			$jquery("#image-placeholder img").attr("alt",$jquery(this).children("img").attr("alt"));
			$jquery("#flickr-gallery .photo-title").html($jquery(this).children("img").attr("alt"));
			
			var standardSize = $jquery("#flickr-gallery ul.thumbs li a:eq("+thumbIndex+")").attr("href");
			var newUrl = standardSize.split(".jpg");
			//$(".image-window a").attr("href",newUrl[0]+"_b.jpg");
			//$(".image-window a").attr("title",$(this).children("img").attr("alt"));
			
			$jquery(".zoom-link").attr("href",newUrl[0]+"_b.jpg");
			$jquery(".zoom-link").attr("title",$jquery(this).children("img").attr("alt"));
			
			$jquery("#flickr-gallery ul.thumbs li img.active").animate({opacity: 0.5}, 200 );
			$jquery("#flickr-gallery ul.thumbs li img.active").removeClass("active");
			
			$jquery(this).children("img").animate({opacity: 1.0}, 200);
			$jquery(this).children("img").addClass("active");
			
		});
		
		// initially hide next if pages = 1
		if(pages == 1) {
			$jquery("#next").hide();
		}
		
		// initially hide prev page nav
		$jquery("#prev").hide();
		
		// function for fading thumbs
		$jquery("#flickr-gallery ul.thumbs li img").animate({ opacity: 0.5 }, 200 );
		$jquery("#flickr-gallery ul.thumbs li img.active").animate({ opacity: 1.0 }, 1000 );
		
		// change opacity onmouse over
		$jquery("#flickr-gallery ul.thumbs li img").hover(function(){
				$jquery(this).animate({
					opacity: 1.0
				}, 200 );
		});
		
		// change opacity onmouse out
		$jquery("#flickr-gallery ul.thumbs li img").mouseout(function(){
			if (!$jquery(this).hasClass("active")) { 
					$jquery(this).animate({opacity: 0.5}, 200 );
				}
		});
		
		//slidefunction thumbnails
		//var countItems = #numberItems#;
		//var pages = #ceiling(ceiling(rowItems) / 6)#;
		var step = 1;
		var itemsOnPage = 12;
		// space for thumbnails on last page
		// var sideMargin = ((#rowItems# - ((pages-1)*6)) * 85) + 10;
		var restItems = countItems - ((pages-1)*itemsOnPage);
		var itemsFirstRow = Math.round((((pages-1) * (itemsOnPage / 2)) + (restItems/2)));
		
		function gotoNextPage() {
		
			$jquery("#next").hide();
			$jquery("#prev").hide();
			var initialMargin = $jquery("#flickr-gallery ul.thumbs").css("margin-left").split("px");
			
			if((step) == pages) {
				
				$jquery('#flickr-gallery ul.thumbs').animate({ 
			        //marginLeft: (initialMargin[0]-(sideMargin-10))
			        marginLeft: (initialMargin[0]-510)
			      }, 1000, function() {
			      		$jquery("#prev").show();
			      	  });
			   	}
			else {
				$jquery('#flickr-gallery ul.thumbs').animate({ 
			        marginLeft: (initialMargin[0]-510)
			      }, 1000, function() { 
			      		$jquery("#next").show();  
			      		$jquery("#prev").show();  
			      		} );
				}
		
		}
		
		function gotoPrevPage() {
			
			$jquery("#next").hide();
			$jquery("#prev").hide();			
			
			var initialMargin = $jquery("#flickr-gallery ul.thumbs").css("margin-left").split("px");

			if((step+1) == pages) {
				$jquery('#flickr-gallery ul.thumbs').animate({ 
		        	//marginLeft: (initialMargin[0]-(-sideMargin+10))
		        	marginLeft: (initialMargin[0]-(-510))
		      	}, 1000, function() { 
		      		$jquery("#next").show();
		      		if (step == 1) {
						$jquery("#prev").hide();
					}
					else { 
		      			$jquery("#prev").show();
		      		} 
		      	});
			}
			else {
				$jquery('#flickr-gallery ul.thumbs').animate({ 
		        	marginLeft: (initialMargin[0]-(-510))
		      	}, 1000, function() {
		      		
		      		$jquery("#next").show();
		      		if (step == 1) {
						$jquery("#prev").hide();
					}
					else { 
						$jquery("#prev").show(); 
					}
		      		
		      	 });
			}
		
		}
		
		$jquery("#next").click(function(event) {
				step += 1;
				gotoNextPage();
				event.preventDefault();
				
		});
		
		$jquery("#prev").click(function(event) {
			step -= 1;
			gotoPrevPage();
			event.preventDefault();
				
		});
		
		$jquery("#nextphoto").click(function(event) {
			event.preventDefault();
			
			// if not last item
			if (((thumbIndex+1) != itemsFirstRow) && ((thumbIndex+1) != countItems))  { 	 	
				// remove style on last active
				$jquery("#flickr-gallery ul.thumbs li img.active").animate({opacity: 0.5}, 200 );
				$jquery("#flickr-gallery ul.thumbs li img.active").removeClass("active");
				
				if (((thumbIndex + 1) / ((itemsOnPage / 2) * step)) == 1) {
					//laatste bovenste rij
					thumbIndex = (Math.round((itemsFirstRow + ((itemsOnPage/2) * (step-1)))));
				}
				
				else if((Math.round((itemsFirstRow + ((itemsOnPage/2) * step)))) == (thumbIndex+1)){
					//laaste onderste rij
					if(step != pages) {
						step += 1;
						gotoNextPage();
						thumbIndex = ((step-1) * (itemsOnPage/2));
					}
				}
				
				else { 
					thumbIndex += 1;
				}
				
				$jquery("#flickr-gallery ul.thumbs li img:eq("+thumbIndex+")").animate({opacity: 1.0}, 200 );
				$jquery("#flickr-gallery ul.thumbs li img:eq("+thumbIndex+")").addClass("active");
				
			}
			
			else if ((thumbIndex+1) == itemsFirstRow) { 
				
				if(restItems != 1) { 
					// remove style on last active
					$jquery("#flickr-gallery ul.thumbs li img.active").animate({opacity: 0.5}, 200 );
					$jquery("#flickr-gallery ul.thumbs li img.active").removeClass("active");
					
					thumbIndex = (Math.round((itemsFirstRow + ((itemsOnPage/2) * (step-1)))));
					
					$jquery("#flickr-gallery ul.thumbs li img:eq("+thumbIndex+")").animate({opacity: 1.0}, 200 );
					$jquery("#flickr-gallery ul.thumbs li img:eq("+thumbIndex+")").addClass("active");
				}
				
			}
			
			else if ((itemsFirstRow != (countItems / 2)) && ((thumbIndex+1) == countItems)) { 
				
				if(step != pages) {
					step += 1;
					gotoNextPage();
					thumbIndex = ((step-1) * (itemsOnPage/2));
					
					// remove style on last active
					$jquery("#flickr-gallery ul.thumbs li img.active").animate({opacity: 0.5}, 200 );
					$jquery("#flickr-gallery ul.thumbs li img.active").removeClass("active");
				}
				
								
				$jquery("#flickr-gallery ul.thumbs li img:eq("+thumbIndex+")").animate({opacity: 1.0}, 200 );
				$jquery("#flickr-gallery ul.thumbs li img:eq("+thumbIndex+")").addClass("active");
			}
			
			//load larger image in placeholder
			$jquery("#image-placeholder").html("<img src="+$jquery('#flickr-gallery ul.thumbs li a:eq('+thumbIndex+')').attr('href')+" alt="+$jquery('#flickr-gallery ul.thumbs li a:eq('+thumbIndex+') img').attr('alt')+" />");
			
			var standardSize = $jquery("#flickr-gallery ul.thumbs li a:eq("+thumbIndex+")").attr("href");
			var newUrl = standardSize.split(".jpg");
			var linkTitle = $jquery("#flickr-gallery ul.thumbs li a:eq("+thumbIndex+")").children("img").attr("alt");
			//$(".image-window a").attr("href",newUrl[0]+"_b.jpg");
			$jquery(".zoom-link").attr("href",newUrl[0]+"_b.jpg");
			$jquery(".zoom-link").attr("title",linkTitle);
			$jquery("#flickr-gallery .photo-title").html(linkTitle);
			
		});
		
		$jquery("#prevphoto").click(function(event) {
			event.preventDefault();
			
			// if not first item
			if (thumbIndex != 0)  { 			
			
				// remove style on last active
				$jquery("#flickr-gallery ul.thumbs li img.active").animate({opacity: 0.5}, 200 );
				$jquery("#flickr-gallery ul.thumbs li img.active").removeClass("active");
				
				if ((((step-1) * (itemsOnPage/2)) == thumbIndex) && (((step-1) * (itemsOnPage/2)) <= itemsFirstRow)) {
					//eerste bovenste rij
					step -= 1;
					gotoPrevPage();
					thumbIndex = (Math.round((itemsFirstRow + ((itemsOnPage/2) * step))))-1;
				}
				
				else if((Math.round((itemsFirstRow + ((itemsOnPage/2) * (step-1))))) == (thumbIndex)){
					//eerste onderste rij
					if(step == pages) {
						thumbIndex = (itemsFirstRow-1);
					}
					else {
						thumbIndex = (step * (itemsOnPage/2))-1;
					}
				}
						
				else { 
					thumbIndex -= 1;
				}
				
				$jquery("#flickr-gallery ul.thumbs li img:eq("+thumbIndex+")").animate({opacity: 1.0}, 200 );
				$jquery("#flickr-gallery ul.thumbs li img:eq("+thumbIndex+")").addClass("active");
				
			}
			
			//load larger image in placeholder
			$jquery("#image-placeholder").html("<img src="+$jquery('#flickr-gallery ul.thumbs li a:eq('+thumbIndex+')').attr('href')+" alt="+$('#flickr-gallery ul.thumbs li a:eq('+thumbIndex+') img').attr('alt')+" />");
			
			var standardSize = $jquery("#flickr-gallery ul.thumbs li a:eq("+thumbIndex+")").attr("href");
			var newUrl = standardSize.split(".jpg");
			var linkTitle = $jquery("#flickr-gallery ul.thumbs li a:eq("+thumbIndex+")").children("img").attr("alt");
			//$(".image-window a").attr("href",newUrl[0]+"_b.jpg");
			$jquery(".zoom-link").attr("href",newUrl[0]+"_b.jpg");
			$jquery(".zoom-link").attr("title",linkTitle);
			$jquery("#flickr-gallery .photo-title").html(linkTitle);
			
		});
		
		$jquery(".zoom-link").colorbox({}, function(){
			//calback
		});
		
		// preload images after document ready
		preloadImages();
	});

