/**
 * Javascript for The Lomographic
 *      - Random lomowall generator
 *      - Dynamic popup image viewer
 *
 * Author : Edward Jung
 * version 0.1 : 06 November 2002
 * version 0.2 : 12 November 2002
 **/

var browserVer = parseInt(navigator.appVersion);
var lomoInfo = new Array();
var lomowallArray = new Array(16);

/**
 * Sets up the array of lomoimages
 **/
function variableSetup() {
	lomoInfo[0] = new lomoimage(0, "Untitled", "Again another abstract one. Almost like seeing everything up close through a drizzly rain.");
	lomoInfo[1] = new lomoimage(1, "Hotel California", "Taken early evening somewhere near Heathrow Airport. I really like the colours in this photo.");
	lomoInfo[2] = new lomoimage(2, "Fingathing", "A clay mask that my brother made in his art class. Still hangs proudly in his bedroom.");
	lomoInfo[3] = new lomoimage(3, "Me Me", "This is one of my all time favourite lomographs, a close up of my grandma's dog. It looks almost like a painting.");
	lomoInfo[4] = new lomoimage(4, "Eight state", "From the eighth floor of Bridgewater House you get nice views onto the back of this collection of office buildings.");
	lomoInfo[5] = new lomoimage(5, "Going underground", "The tunnel underneath the train lines at Piccadilly Station in Manchester. I really like the concrete arching");
	lomoInfo[6] = new lomoimage(6, "Recorded image", "I was numbering the latest record release on my label on the floor of my bedroom and thought it would make a nice bit of wallpaper.");
	lomoInfo[7] = new lomoimage(7, "Another late night", "Taken on a late evening on my way home from work, walking along the tramlines past the crown courts in Manchester.");
	lomoInfo[8] = new lomoimage(8, "Stairwell", "Looking down in Manchester Central Library onto the wooden stairs. Each step creaks a lot for a library.");
	lomoInfo[9] = new lomoimage(9, "Chorlton", "The original clay model of Chorlton as used in the classic children's series Chorlton and The Wheelies made by Cosgrove Hall.");
	lomoInfo[10] = new lomoimage(10, "Seeya Nitin", "A former work colleague of mine and friend. This was from his leaving party after work. Nice tunneling effect here.");
	lomoInfo[11] = new lomoimage(11, "Red vinyl", "A shot of one of the records I released on Emma's House Recordings. ehr004 had two great tracks by Angel Corpus Christi. Pressed in Nashville Tennessee.");
	lomoInfo[12] = new lomoimage(12, "Palm Beach", "A view from out of my window where I used to live in Manchester. It had become very quiet all of a sudden on the usually busy main road.");
	lomoInfo[13] = new lomoimage(13, "Moon in the doorway", "Another abstract one, I thinks shot just outside a doorway with the brightness of moon.");
	lomoInfo[14] = new lomoimage(14, "Kevin", "I sat next to Kevin on my flight to New York in 2001. He had been flying from the Middle East with his family. He was especially interested in the Swatch Beat watch I had on.");
	lomoInfo[15] = new lomoimage(15, "Just Gershwin", "The first floor of the Gershwin Hotel in Manhattan. Each floor has been decorated in a different style. On this floor there are a lot of cuttings of model magazines. The foyer contains a signed Campbells tomato soup can by Andy Warhol.");
	lomoInfo[16] = new lomoimage(16, "Red sky in morning", "Really early one morning I took this shot from my Gran's backyard. Not sure how the star formation in the sky came about.");
	lomoInfo[17] = new lomoimage(17, "Late night at the office", "A night shot of out from the eighth floor of the building I used to work in. The reverse of Lomograph 4.");
	lomoInfo[18] = new lomoimage(18, "Anybody home?", "A perfect example of the Lomo lens absorbing the light in low light conditions. The light of the house wasn't actually that bright. The long exposure emphasised it.");
	lomoInfo[19] = new lomoimage(19, "Lift ride", "Lomo self portrait taken in the swish lifts of my former workplace.");
	lomoInfo[20] = new lomoimage(20, "Ancoats Street car park", "A chance shot as I was walking through the run down streets of Ancoats. The sign was lying on the floor and so I took a picture of it.");
	lomoInfo[21] = new lomoimage(21, "Path to the suns", "A mural on the walls of one of the galleries at the Lowry in Salford. ");
	lomoInfo[22] = new lomoimage(22, "Guest worship", "A church in New York. Just one of many. I like the repeating structure.");
	lomoInfo[23] = new lomoimage(23, "Guggenheim", "My Lomo was having a few problems and so the exposure was quite correct. This resulted in this grainy picture of the Guggenheim Museum.");
	lomoInfo[24] = new lomoimage(24, "Dark clouds are looming", "The entrance of the outdoor sculpture park in Queens, New York. The reflective dark clouds on a bright day makes this one of my favourite Lomographs.");
	lomoInfo[25] = new lomoimage(25, "Subway guide", "The lighting from a subway station in downtown New York just after nine o'clock.");
	lomoInfo[26] = new lomoimage(26, "High rise", "These high rise blocks fascinated me not just the height but the generic feel of them.");
	lomoInfo[27] = new lomoimage(27, "Empire State", "The Empire State Building with it's green lit top and a patriotic American flag on the sidewalk.");
	lomoInfo[28] = new lomoimage(28, "Pipes and light", "These unusual pipes and lighting is in the toilets at the university I currently attend. It's amazing what you discover if you look up or down sometimes.");
	lomoInfo[29] = new lomoimage(29, "Love kills", "In many ways this is the truth. It's quite an elegant bit of graffiti taken in a cramped toilet of an Internet cafe in Manchester.");
	lomoInfo[30] = new lomoimage(30, "Junk room", "The back room of my parents shop. The morning sun brings an aged feel to it all.");
	lomoInfo[31] = new lomoimage(31, "UMIST", "The urge to take pictures with my Lomo on the way home from when I worked was immense after a long day. This if the side of the UMIST building. ");
	lomoInfo[32] = new lomoimage(32, "What's that about?", "Me Me again, always curious as to what the black box I am holding is. Maybe it's food? She doesn't like the click of the shutter and runs away.");
	lomoInfo[33] = new lomoimage(33, "Library light", "Again some nice lighting in the local library. The green is quite typical of a library. I wonder why.");
	lomoInfo[34] = new lomoimage(34, "Glass snowman", "A picture of a glass blown snowman that I brought for a present.");
	lomoInfo[35] = new lomoimage(35, "Cheat", "Serious close up of a tense Mah Jong game during a family get together.");
	lomoInfo[36] = new lomoimage(36, "Oh Mr Dark Sky", "An emerging sun rise taken from the skies. The emerging colours are wonderful.");
	lomoInfo[37] = new lomoimage(37, "Shakened", "Can't really remember what this was, it might have been the backlit display of the hi-fi. Anyway with a long exposure you can paint with your Lomo.");
	lomoInfo[38] = new lomoimage(38, "Deutsch morning", "Taken around 5am in the morning in Weisbaden Germany. I was waiting to catch a train to the airport.");
	lomoInfo[39] = new lomoimage(39, "Orange block", "I don't know what this building was originally, it might have been a chemists of a butchers. I think it's brilliant to have a building like this on the corner of the street. Full of unique character.");
	lomoInfo[40] = new lomoimage(40, "Look out", "I think I caught my Sister as she was about to launch into a long debate on something.");
	lomoInfo[41] = new lomoimage(41, "Glasgow houses night", "A night shot of the same Glaswegian housing block I took during the day. Light fantastic effects.");
	lomoInfo[42] = new lomoimage(42, "Kitchen light", "A weird picture of outside the kitchen window. An eerie feel as the light shines onto the plants outside.");
	lomoInfo[43] = new lomoimage(43, "Unsure", "Not too sure of where this was taken. Seems to be a scene of some sort. Sometimes I just can't remember.");
	lomoInfo[44] = new lomoimage(44, "Rhonda", "The daughter of Duglas Stewart. Lead singer of the BMX Bandits(my favourite band of all time). She is one of the most adorable kids I have ever met.");
	lomoInfo[45] = new lomoimage(45, "Abstract landscape", "What you get when you have really long exposures. The shakes of your hand are translated as part of the Lomograph.");
	lomoInfo[46] = new lomoimage(46, "Petrol station shaky walk", "Another shaken image. I think I was walking past the petrol station at night and took this.");
	lomoInfo[47] = new lomoimage(47, "Last one", "I take my Lomo most places and I really like this picture. Just the way the light shone from the back window.");
	lomoInfo[48] = new lomoimage(48, "Waiting for the bus", "A Lomo keeps you occupied. and you will start to take Lomographs of everything.");
	lomoInfo[49] = new lomoimage(49, "This way for the sky", "A window in central London around the back of Carnaby Street. What points up must point down.");
	lomoInfo[50] = new lomoimage(50, "Glasgow Houses", "Taken from the spare room ofmy friends house in Glasgow. The simplicity is beauty.");
	return lomoInfo;
} // end variableSetup

/**
 * Loads the images required for the lomowall
 **/
function loadImages(thisLomowall) {
	if (document.images) {
		for (i = 0; i < thisLomowall.length; i++) {
			thisImage = new Image();
			thisImage.src = "images/photos/m_lomo" + thisLomowall[i] + ".jpg";
			eval("document ['lw" + i + "'].src =  thisImage.src");
		}
	}
} // end loadImages

/**
 * Generate a random selection of lomos for display in the wall
 **/
function getRandomLomowall() {
	var lastNum = 0;
	var thisNum = 0;
	for (i = 0; i < lomowallArray.length; i++) {
		while (thisNum == lastNum) {
			thisNum = Math.floor(lomoInfo.length * Math.random());
		}
		lastNum = thisNum;
		lomowallArray[i] = thisNum;
	}
} // end getRandomLomowall

/**
 * Loads the images into the lomowall page dynamically, problems in Phoenix
 **/
function setupLomowalls(page) {
	variableSetup();
	if (page == "1") {
		lomowallArray = new Array(14, 3, 14, 10, 3, 14, 10, 40, 14, 3, 40, 10, 2, 40, 2, 40);
	} else if (page == "2") {
		lomowallArray = new Array(37, 38, 0, 36, 38, 37, 36, 0, 38, 36, 37, 0, 36, 38, 0, 37);
	} else if (page == "3") {
		lomowallArray = new Array(26, 23, 4, 1, 23, 26, 1, 4, 26, 23, 4, 1, 23, 26, 1, 4);
	} else if (page == "4") {
		lomowallArray = new Array(8, 29, 20, 11, 29, 8, 11, 20, 8, 9, 33, 11, 9, 33, 9, 33);
	} else if (page == "random") {
		getRandomLomowall();
	} else {
		lomowallArray = new Array(6, 7, 12, 32, 7, 6, 32, 12, 6, 7, 5, 32, 7, 5, 7, 5);
	}
	// load the images in now the array has been set up
	loadImages(lomowallArray);
} // end setupLomowalls

/**
 * Clear the window of all HTML
 **/
function windowCleaner(whatWin) {
	whatWin.document.clear()
	whatWin.document.close()
} // end windowCleaner

/**
 * Returns the HTML header for the pop up window
 **/
function getWindowHeader(imgNum) {
	var HTMLText = "<html><title>The Lomographic - " + lomoInfo[imgNum].getName() + "</title>\n";
	HTMLText += "<link rel=\"stylesheet\" type=\"text/css\" href=\"includes/lomoimage.css\" />\n";
	HTMLText += "<script type=\"text/javascript\" language=\"Javascript\" src=\"includes/lomoimage.js\"></script>\n";
	HTMLText += "<script type=\"text/javascript\" language=\"Javascript\" src=\"includes/lomo.js\"></script>\n";
	HTMLText += "</head>\n";
	return HTMLText;
} // end getWindowHeader

/**
 * function to dynamically generate the next HTML page if already inside the window
 **/
function viewImageInside(imgNum) {
	// this needs to be called and reassigned for some reason on Mozilla platforms
	var lomoInfo = variableSetup();
	if (document.images) {
		lomowallArray[imgNum] = imgNum;
		imgWin = null;
		imgWin = window.open("","window","height=420,width=360,scrollbars=no,resizable=yes");
		windowCleaner(this);
		imgWin.focus();
		if (imgWin != null) {
			document.writeln(getWindowHeader(lomowallArray[imgNum]));
			document.writeln(lomoInfo[imgNum].displayInfo());
			document.writeln("</body></html>");
			document.close();
		}
	}
} // end viewImageInside

/**
 * Same function as viewImageInside but opens a window outside the Lomowall pages
 **/
function viewImageExt(imgNum) {
	var lomoInfo = variableSetup();
	if (document.images) {
		lomowallArray[imgNum] = imgNum;
		imgWin = null;
		imgWin = window.open("","window","height=420,width=360,scrollbars=no,resizable=yes");
		windowCleaner(imgWin);
		imgWin.focus();
		if (imgWin != null) {
			imgWin.document.writeln(getWindowHeader(lomowallArray[imgNum]));
			imgWin.document.writeln(lomoInfo[imgNum].displayInfo());
			imgWin.document.writeln("</body></html>");
			imgWin.document.close();
		}
	}
} // end viewImageExt

/**
 * dynamically creates the content for the pop window for the image
 **/
function ViewImage(imgNum){
	if (document.images) {
		imgWin = null;
		imgWin = window.open("","window","height=400,width=350,scrollbars=no,resizable=yes");
		windowCleaner(imgWin);
		imgWin.focus();

		if (imgWin != null) {
			imgWin.document.writeln(getWindowHeader(lomowallArray[imgNum]));
			imgWin.document.writeln(lomoInfo[lomowallArray[imgNum]].displayInfo());
			imgWin.document.writeln("</body></html>");
			imgWin.document.close();
		}
	}
} // end viewImage
