﻿	// 
	// 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: 12/14/04 ------------------------------------------------------
	
	//var photoId = 0;
	var photoDir = "photos/002/";
	var borderSize = 20
	
	// 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 i=1
	photoId = (!photoId)? 0:photoId;
	
	// List of photos in this gallery
	photoArray = new Array("01.jpg","02.jpg","03.jpg","04.jpg","05.jpg","06.jpg","07.jpg","08.jpg","09.jpg");
	
	var photoNum = photoArray.length;
	
	// Pixel width of each photo in this gallery
	photoWidthArray = new Array("600","550","600","450","600","600","600","500","600");
	
	// Pixel height of each photo in this gallery
	photoHeightArray = new Array("450","733","450","600","450","450","450","667","450");
	
	// Captions for photos
	captionArray = new Array("Verkstedet landskapet","Verkstedet arbeidsplassene","Hvilerommet","Ole ligger på golvet for å ta et fordelaktig bilde fra plassen til Petter","Spiserom - Møterom", "Spiserom - Møterom","Spiserom - Møterom","Verkstedet - humm... en ledig plass for deg?","Spiserom - Møterom");
	
	// Create access to 'Detect' object and a place to put instances of 'HTMLobj'
	API = new Detect();
	
	// CREATE INSTANCES & LOAD
	loadAPI = function(){
		// Instantiate HTMLobj
		API.Container = new HTMLobj('Container');
		API.PhotoContainer = new HTMLobj('PhotoContainer');
		API.Photo = new HTMLobj('Photo');
		
		nextPhoto();
	}
	onload = loadAPI;
	
	// Fade in photo when it is loaded from the server
	// Called by the image.onload event
	initFade = function(){
		// Be certain the tween is complete before fading, too
		var fade_timer = setInterval('startFade()', 1000);
		
		// Fade photo in when ready and clear listener
		startFade = function(){
			if(API.Container._tweenRunning == false){
				clearInterval(fade_timer);
				API.PhotoContainer.fadeIn(0,15,33);
			} else {
				return;
			}
		}
	}
	
	// Advance Photo ID by one
	advancePhoto = function(){
		// Cycle through to end, then repeat
		if(photoId == (photoArray.length - 1)){
			photoId = 0;
		} else {
			photoId++;
		}
		return photoId;
	}
	
	// Function to load subsequent photos in gallery
	nextPhoto = function(){		
		// Hide photo container temporarily
		API.PhotoContainer.hide();
		API.PhotoContainer.setOpacity(0);
				
		// Get dimensions of photo
		var wNew = photoWidthArray[photoId];
		var hNew = photoHeightArray[photoId];
		
		// Start tween on a delay
		setTimeout('API.Container.tweenTo(easeInQuad, [API.Container.getWidth()-borderSize, API.Container.getHeight()-borderSize], ['+wNew+','+hNew+'], 7)',500);
		
		// Set source, width, and height of new photo
		document.getElementById('Photo').src = photoDir + photoArray[photoId];
		document.getElementById('Photo').width = wNew;
		document.getElementById('Photo').height = hNew;
		document.getElementById('NextLink').href = "#" + (photoId+1);
		document.getElementById('Caption').innerHTML = captionArray[photoId];
		document.getElementById('Counter').innerHTML = (photoId+1)+' av '+photoNum;
		
		// Advance counter to next photo
		advancePhoto();
	}