	// <![CDATA[
	
	// -----------------------------------------------------------------------------------
	// 
	// This page coded by Scott Upton
	// http://www.uptonic.com | http://www.couloir.org
	//
	// This work is licensed under a Creative Commons License
	// Attribution-ShareAlike 2.0
	// http://creativecommons.org/licenses/by-sa/2.0/
	//
	// Associated API copyright 2002, Travis Beckham (www.squidfingers.com)
	//
	// -----------------------------------------------------------------------------------
	// --- version date: 04/30/05 ------------------------------------------------------
	
	var photoDir = "../malerier/"; // Location of photos for gallery
	var borderSize = 6;	 // = 2x CSS border size
	
	// get current photo id from URL
	var thisURL = document.location.href;
	var splitURL = thisURL.split("#");
	var photoId = splitURL[1] - 1;
	
	// if no id in query string then set to 0
	photoId = (!photoId)? 0:photoId;
		
	// Define each photo's name, height, width, and caption
	
	var photoArray = [];
	/**	// Source, Width, Height, Caption
	new Array("admin/pic_6f4.jpg", "250", "135", "Door 3 - Click on the image to view previous or next image")
	);**/
	
	// Number of photos in this gallery
	var photoNum = photoArray.length;
	
	// Create access to 'Detect' object and a place to put instances of 'HTMLobj'
	API = new Detect();
	
	// CREATE INSTANCES & LOAD
	loadAPI = function(){
		Slideshow.initImages();
		genPages.generate();
		setPgButtons();
		
		// Instantiate HTMLobj
		API.Container		= new HTMLobj('slideshow_Container');
		API.Photo			= new HTMLobj('slideshow_Photo');
		API.PhotoContainer	= new HTMLobj('slideshow_PhotoContainer');
		API.PrevLink		= new HTMLobj('slideshow_PrevLink');
		API.NextLink		= new HTMLobj('slideshow_NextLink');
		API.CaptionBlock	= new HTMLobj('slideshow_CaptionBlock');
		API.Counter			= new HTMLobj('slideshow_Counter');
		API.Caption			= new HTMLobj('slideshow_Caption');
		API.LoadImg			= new HTMLobj('slideshow_LoadImg');
				
		slideSpeed.showspeed();
		
		// Show initial photo
		setTimeout(function(){photoId = -1; Slideshow.setSlideshow(true);},1000);
	};
	
	if(document.getElementById("slideshow_Container"))
		onload = loadAPI;
	
	// Fade in photo when it is loaded from the server
	initFade = function(){
		//Wainting until the image is loaded before executing the fading effect
		if(!document.getElementById('slideshow_Photo').complete){
			window.setTimeout('initFade()',300);
			return;
		}
		
		// Show PhotoContainer again
		API.PhotoContainer.show();
		// Be certain the tween is complete before fading, too
		var fade_timer = window.setTimeout("startFade()", 1000);
						
		// Fade photo in when ready and clear listener
		startFade = function(){
			if(API.Container._tweenRunning == false){
				// Be certain fade is done running before allowing next/previous links to work
				// This avoids rapid fade-in when users click next/previous links in quick succession
				var adv_timer = window.setTimeout('permitNextPrev()', 500);
				
				// Permit next/previous links to function normally when fade is completed
				permitNextPrev = function(){
					if(API.Photo._fadeRunning == false){
						Slideshow.setOccupied(false);
						
						
						// Only show links if there is more than one photo in array
						if(photoNum > 1){
							//API.LinkContainer.displayShow();
							document.getElementById('slideshow_NextLink').onclick = function(){nextPhoto();Slideshow.setSlideshow(false)};
							document.getElementById('slideshow_PrevLink').onclick = function(){prevPhoto();Slideshow.setSlideshow(false)};
							
							if(!(genPages.noPages == 0)){
								genPages.prevPage(genPages.current,true);
								genPages.nextPage(genPages.current,true);
							}
							
						}
					} else {
						return;
					}
				}
				// Swap out loading animation to spare CPU cycles when hidden anyway
				API.LoadImg.setSrc("design/images/slideshow/start.gif");
				
				// Show caption again
				API.CaptionBlock.show();
				
				// Fade photo in
				API.Photo.fadeIn(0,15,33);
			} else {
				window.setTimeout("startFade()", 1000);
			}
		}
	}
	
	// Prevent next/previous
	falsify = function(){
		return false;
	}
	
	// Go to next photo
	nextPhoto = function(){
		// Go to next photo
		if((photoId == (photoArray.length - 1)) && (genPages.noPages > 0)){
			genPages.nextPage(0);
		} else {
			if((photoId == genPages.pageEnd) && (genPages.noPages > 0)){
				genPages.nextPage(genPages.current + 1);
			}
			else{
				if(photoId == genPages.pageEnd){
					jumpto(genPages.pageStart);
				}
				else{
					photoId++;
					cyclePhoto(photoId);
				}
			}
		}
		
		
	}
	
	// Go to previous photo
	prevPhoto = function(){
		// If at start, go back to end
		if((photoId == 0) && (genPages.noPages > 0)){
			genPages.prevPage(genPages.noPages);
		} else {
			if((photoId == genPages.pageStart) && (genPages.noPages > 0)){
				genPages.prevPage(genPages.current - 1);
			}
			else {
				if(photoId == genPages.pageStart){
					jumpto(genPages.pageEnd);
				}
				else{
					photoId--;
					cyclePhoto(photoId);
				}
			}
		}
		
		
	}
	
	// Alter class of elements
	changeElementClass = function(objId,setClass) {
		document.getElementById(objId).className = setClass;
	}
	
	// Function to load subsequent photos in gallery
	cyclePhoto = function(photoId){
	
		Slideshow.setOccupied(true);
			
		// Swap in loading animation
		API.LoadImg.setSrc("design/images/malerier/loading.gif");
		
		// Hide link container if it is not already hidden
		//API.LinkContainer.displayHide();
		
		// Hide photo container and caption temporarily
		API.Photo.hide();
		API.Photo.setOpacity(0);
		API.CaptionBlock.hide();
		
		// Get dimensions of photo
		var wNew = photoArray[photoId][1];
		var hNew = photoArray[photoId][2];
		
		//resizing to max 300px
		var PhotoSize = 300;
		if(wNew > hNew && wNew > PhotoSize){
			hNew = parseInt((PhotoSize*(hNew/wNew)));
			wNew = PhotoSize;
		}
		else if(hNew >= wNew && hNew > PhotoSize){
			wNew = parseInt((PhotoSize*(wNew/hNew)));
			hNew = PhotoSize;
		}
		// Start tween on a delay
		var wCur = API.Container.getWidth() - borderSize;
		var hCur = API.Container.getHeight() - borderSize;
		
		
		// Begin tweening on a short timer
		setTimeout('API.Container.tweenTo(easeInQuad, ['+wCur+', '+hCur+'], ['+wNew+','+hNew+'], 7)',500);
		
	
		// Get new photo source
		var newPhoto = photoDir + photoArray[photoId][0];
		// Set source, width, and height of new photo
		API.Photo.setSrc(newPhoto);		
		API.Photo.sizeTo(wNew,hNew);
		
		API.Counter.setInnerHtml((photoId+1)+" / "+photoNum+" |");
		API.Caption.setInnerHtml(photoArray[photoId][3]);
		
		
		// Event listeners for onload and onclick events
		initFade();
		
		// Block next/previous links until permitNextPrev() has fired
		document.getElementById('slideshow_NextLink').onclick = falsify;
		document.getElementById('slideshow_PrevLink').onclick = falsify;
		
		document.getElementById('slideshow_nextpage').onclick = falsify;
		document.getElementById('slideshow_prevpage').onclick = falsify;
		
		//Goer alle photo rammer sorte og saet saa farven for
		//nye foto som roedt
		nulstil();
		setny(photoId);
	}
	// ]]>
	
	
	Slideshow = {
		Slideshow:false,
		timeout:false,
		occupied:false,
		setSlideshow: function(bool){
				this.Slideshow = bool;
				elm = document.getElementById("slideshow_Slideshow");
				bool ? elm.innerHTML = "<p>Pause</p>" : elm.innerHTML = "<p>Start</p>";
				if(bool)
					this.doSlideshow();
		},
		doSlideshow: function(){
			
			clearTimeout(this.timeout);
			if(this.Slideshow){		
				nextPhoto();
				this.startTimeout();
			}
		},
		getSlideshow: function(){
			return this.Slideshow;
		},
		setOccupied: function(bool){
		
		this.occupied = bool;

		
		},
		getOccupied: function(){
		
		return this.occupied;
				
		},
		startTimeout: function(){
			if(!this.getOccupied()){
				this.timeout = window.setTimeout('Slideshow.doSlideshow();',(slideSpeed.speed * 1000));
			}				
			else{
			
				window.setTimeout('Slideshow.startTimeout();',50);
			}
		},
		
		initImages: function(){
			photoArray = new Array();
			for(i=0; document.getElementById("slideshow_image_"+i); i++){
				elm = document.getElementById("slideshow_image_"+i).elements;
				photoArray.push(new Array(elm["filnavn"].value, elm["b"].value, elm["h"].value, elm["titel"].value, elm["id"].value));
			}
			photoNum = photoArray.length;
		},
		
		linkBuy: function(){
			YAHOO.util.Connect.asyncGetRequest('../kurv/kurv.php?kob=true&ajax=true&id='+photoArray[photoId][4],'kurvHTML','');
			DialogBox.paintAddBasketBox();
		},
		
		linkFavorit: function(){
			List.add(photoArray[photoId][4],"../malerier/"+photoArray[photoId][0]);alert('Maleriet er tilføjet din favoritliste');
		}
	}	
	
	function nulstil(){

	
		for(i= genPages.pageStart; (i < photoNum) && (i <= genPages.pageEnd); i++){
		
			document.getElementById("slideshow_image" + i).style.borderColor= "black";
		
		}
	
	}
	
	function setny(ny){

		document.getElementById("slideshow_image"+ny).style.borderColor = "#ffffff";

	}
	var picsWide = 10;
	function GenThumbs(page){
		var widthwatch = 0;
		var output = "<table cellspacing='0px' cellpadding='0px'><tr>";
		var firsttPic = page * genPages.perPage;
		var lastPic = (((page + 1 )* genPages.perPage))-1;
		var hoejde = 3;
		var yposition;
		for(i=firsttPic; (i < photoNum) && (i <= lastPic); i++){
			
			if(widthwatch == picsWide){
			output += "</tr><tr>"
			widthwatch = 0;
			}
			
			yposition = Math.floor(i/picsWide);
			if(yposition > (hoejde - 1)){
				yposition = yposition%hoejde;
			}		
						
			output += "<td valign='middle' id='slideshow_image"+ i +"'><a onmouseover='largethumb("+ i+","+(i%picsWide) +","+ yposition + ");' href='#nogo'><img  alt='" + photoArray[i][0] + "' src='./" + photoDir + photoArray[i][0] + "' " + fit(photoArray[i][1], photoArray[i][2],32,32) + " /></a></td>";
			
			widthwatch++;
		} 
		output += "</tr></table>"
		document.getElementById("slideshow_page" + page).innerHTML = output;
		
	}
	
	function fit(x,y,picb,pich){
	
		var divider = 1;
		
		while( ((x/divider) > picb) || ((y/divider) > pich) ){
		
			divider++;
		
		}
		
		var width = Math.round(x/divider);
		var height = Math.round(y/divider);
		
		return "style='width:"+ width +"px; height:" + height + "px;'";
		
	
	}
	var boxsize = 40;
	var cssoffset = 10;
	function largethumb(i,x,y){
	document.getElementById("slideshow_preview").style.visibility = "visible";
	document.getElementById("slideshow_preview").style.top = (boxsize*y)-cssoffset +"px";
	document.getElementById("slideshow_preview").style.left = (boxsize*x)-cssoffset+ "px";
	
	
	document.getElementById("slideshow_preview").innerHTML = "<table cellspacing='0px' cellpadding='0px'><tr><td><a href='#nogo' onclick='jumpto("+ i +");'><img id='slideshow_previewpic'   alt='preview' src='./" + photoDir + photoArray[i][0] + "' " + fit(photoArray[i][1], photoArray[i][2],64,64) + " /></a></td></tr></table>"
	
	}
	
	
	function hide(id){
		document.getElementById(id).style.visibility = "hidden";
	}
	
	function jumpto(id,repeat,pageChange){
		if((photoId!= id) || repeat){
			if(!pageChange){
				Slideshow.setSlideshow(false);
			}
			photoId = id;
			if(API.Photo._fadeRunning != false){
			
				setTimeout("jumpto("+id+",true);",50);
			} 
			else {
				cyclePhoto(id);
			}
		}
	}
	
	slideSpeed = {
		speed:3,
		increase: function(){
			if (this.speed < 10){
				this.speed++;
				this.showspeed();
			}
		},
		decrease: function(){
			if (this.speed > 1){
				this.speed--;
				this.showspeed();
			}
		},
		showspeed: function(){
			document.getElementById("slideshow_sspeed").innerHTML = this.speed;
		}
	}
	
	genPages = {
		perPage:30,
		noPages:0,
		current:0,
		pageStart:0,
		pageEnd:29,
		generate:function(){
			this.noPages = Math.ceil(photoNum/this.perPage)-1;
			var output = "";
			for(i=0; i <= this.noPages; i++){
				if(i == 0){
					output += "<div id='slideshow_page"+ i + "' ></div>";
				}
				else
				{
					output += "<div id='slideshow_page"+ i + "' style='display:none;'></div>";
				}
				
			}
			document.getElementById("slideshow_pages").innerHTML=output;
			GenThumbs(0);
			if(this.noPages>0){
				GenThumbs(1);
				
			}
			this.updatePgNum(0);
			
		},
		nextPage:function(i,activateButtons){
			
			var next = i + 1;
			
			if(!activateButtons){
				var prev = this.current;
				this.gotoPage(i, false);
			}
			if(next <= this.noPages){
				document.getElementById('slideshow_nextpage').onclick = function(){genPages.nextPage(next);Slideshow.setSlideshow(false)};
				if(!activateButtons){
					GenThumbs(next);
				}
				
			}
			else
			{
				document.getElementById('slideshow_nextpage').onclick = function(){genPages.nextPage(0);Slideshow.setSlideshow(false)};
			}
			if(!activateButtons){
				document.getElementById('slideshow_prevpage').onclick = function(){genPages.prevPage(prev);Slideshow.setSlideshow(false)};
			}
		},
		prevPage:function(i, activateButtons){
			
			var prev = i - 1;
			
			if(!activateButtons){
				var next = this.current;
				this.gotoPage(i, true);
			}

	
			if(0 <= prev){
				document.getElementById('slideshow_prevpage').onclick = function(){genPages.prevPage(prev);Slideshow.setSlideshow(false)};
				if(!activateButtons){
					GenThumbs(prev);alert("fyha!");
				}
			}
			else
			{
				document.getElementById('slideshow_prevpage').onclick = function(){genPages.prevPage(genPages.noPages);Slideshow.setSlideshow(false)};
			}
			if(!activateButtons){
				document.getElementById('slideshow_nextpage').onclick = function(){genPages.nextPage(next);Slideshow.setSlideshow(false)};
			}
			
		},
		gotoPage:function(newpage, isPrev){
			document.getElementById("slideshow_page" + this.current).style.display="none";
			document.getElementById("slideshow_page" + newpage).style.display="block";
			this.updatePgNum(newpage);
			if(!isPrev){
				jumpto(this.pageStart, false, true);
			}
			else{
				jumpto(this.pageEnd, false, true);
			}
		},
		updatePgNum: function(nu){
		
			document.getElementById('slideshow_side').innerHTML = (nu + 1);
			document.getElementById('slideshow_udaf').innerHTML = (this.noPages +1);
			this.current = nu;
			this.pageEnd = ((this.current+1)*this.perPage)-1;
			this.pageStart = this.pageEnd - (this.perPage-1);
			if((photoNum -1) < this.pageEnd){
			
			this.pageEnd = (photoNum -1);
			
			}
		
		}	
	}
	
	setPgButtons = function(){
		if(genPages.noPages == 0)
		{
			document.getElementById('slideshow_nextpage').onclick = falsify;
			document.getElementById('slideshow_prevpage').onclick = falsify;
		}
		else
		{
			if(genPages.noPages > 1)
			{
				GenThumbs(genPages.noPages);
			}
			document.getElementById('slideshow_nextpage').onclick = function(){genPages.nextPage(1);Slideshow.setSlideshow(false)};
			document.getElementById('slideshow_prevpage').onclick = function(){genPages.prevPage(genPages.noPages);Slideshow.setSlideshow(false)};
		}
	
	}

	SlideshowLoader = {
		sizeDiv: "slideshow_number_of_images",
		imagesDiv: "slideshow_image_",
		paintDiv: "slideshow_image_loader",
		length: 0,
		imageNumber: 0,
		increaseNumber: 1,
		
		load: function(query){
			YAHOO.util.Connect.asyncGetRequest("includes/slideshow_loading_paintings.php"+query,'loading_paintings','');
			this.start();
		},
		
		start: function(){
			if(document.getElementById(this.sizeDiv)){
				this.length = parseInt(document.getElementById(this.sizeDiv).value);
				this.increaseNumber = (this.length>100)? Math.ceil(this.length/25): 4;
				this.imageNumber = 0;
				document.getElementById(this.paintDiv).style.visibility = "visible";
				this.wait();
			}
			else
				window.setTimeout(function(){SlideshowLoader.start()},100);
		},
		
		wait: function(){
			if(this.imageNumber < this.length){
				if(document.getElementById(this.imagesDiv+this.imageNumber)){
					this.imageNumber+= this.increaseNumber;
					document.getElementById(this.paintDiv).innerHTML = "Henter: "+Math.ceil(((this.imageNumber/(this.length-1))*100))+"%";
						
					window.setTimeout(function(){SlideshowLoader.wait()}, 20);
				}
				else
					window.setTimeout(function(){SlideshowLoader.wait()}, 100);
			}
			else{
				document.getElementById(this.paintDiv).innerHTML = "Indsætter...";
				window.setTimeout(function(){SlideshowLoader.stop()}, 50);
			}
		},
		
		stop: function(){
			loadAPI();
			document.getElementById(this.paintDiv).style.visibility = "hidden";
		}
	}

