﻿// JavaScript Document

/* This script and many more are available free online at
The JavaScript Source :: http://javascript.internet.com
Created by: Solomon, the Sleuth :: http://www.freewebs.com/thesleuth/scripts/ 

Modified by George Shabataev [Pixel Square].

*/

function initGallery()
{	
	if( document.getElementById('imgSrc') )
	{
		// List image names without extension
		myImg = new Array();
			myImg[0] = "pic1";
			myImg[1] = "pic2";
			myImg[2] = "pic3";
			myImg[3] = "pic4";
			myImg[4] = "pic5";
			myImg[5] = "pic6";
			myImg[6] = "pic7";
			myImg[7] = "pic8";
			myImg[8] = "pic9";
			myImg[9] = "pic10";
			myImg[10] = "pic11";
			myImg[11] = "pic12";
			myImg[12] = "pic13";
			myImg[13] = "pic14";
			myImg[14] = "pic15";
			myImg[15] = "pic16";
			myImg[16] = "pic17";
			myImg[17] = "pic18";
			myImg[18] = "pic19";
//			myImg[19] = "pic20";
//			myImg[20] = "pic21";
//			myImg[21] = "pic22";
//			myImg[22] = "pic23";
//			myImg[23] = "pic24";
//			myImg[24] = "pic25";
//			myImg[25] = "pic26";
//			myImg[26] = "pic27";
//			myImg[27] = "pic28";
//			myImg[28] = "pic29";
//			myImg[29] = "pic30";
//			myImg[30] = "pic31";
//			myImg[31] = "pic32";
//			myImg[32] = "pic33";
//			myImg[33] = "pic34";
//			myImg[34] = "pic35";
//			myImg[35] = "pic36";
//			myImg[36] = "pic37";
//			myImg[37] = "pic38";
//			myImg[38] = "pic39";
//			myImg[39] = "pic40";
//		 
		// List image titles and description seperated by (|)
		myImgDesc = new Array();
			myImgDesc[0] = "|Dialogue Between Chimneys";
			myImgDesc[1] = "|The End of the Road 1999 (29x41) Etching";
			myImgDesc[2] = "|Fluid Dance (serie), 1995";
			myImgDesc[3] = "|Fluid Dance (serie), 1995";
			myImgDesc[4] = "|Hope 2000 (41x28 ) Etching";
			myImgDesc[5] = "|Kitten on a basket";
			myImgDesc[6] = "|Life Cycle";
			myImgDesc[7] = "|Pines";
			myImgDesc[8] = "|Palace of Thorns";
			myImgDesc[9] = "|Reflections in River Dan";
			myImgDesc[10] = "|Revelation";
			myImgDesc[11] = "|Simply Bee-ing 2000 (58x42) Etching";
			myImgDesc[12] = "|So Close, So Far… 1999 (37x27) Etching";
			myImgDesc[13] = "|Take Off I , Etching";
			myImgDesc[14] = "|The Leader Etching";
			myImgDesc[15] = "|The Window of W.B.Yeats";
			myImgDesc[16] = "|Thicket";
			myImgDesc[17] = "|Trees Die Tall and Straight 2000 (31x20)";
			myImgDesc[18] = "|Tree Birds..";
//			myImgDesc[23] = "|Pic24 Desc Pic24 DescPic24 Desc";
//			myImgDesc[24] = "|Pic25 Desc Pic25 DescPic25 Desc";
//			myImgDesc[25] = "|Pic26 Desc Pic26 DescPic26 Desc";
//			myImgDesc[26] = "|Pic27 Desc Pic27 DescPic27 Desc";
//			myImgDesc[27] = "|Pic28 Desc Pic28 DescPic28 Desc";
//			myImgDesc[28] = "|Pic29 Desc Pic29 DescPic29 Desc";
//			myImgDesc[29] = "|Pic30 Desc Pic30 DescPic30 Desc";
//			myImgDesc[30] = "|Pic31 Desc Pic31 DescPic31 Desc";
//			myImgDesc[31] = "|Pic32 Desc Pic32 DescPic32 Desc";
//			myImgDesc[32] = "|Pic33 Desc Pic33 DescPic33 Desc";
////			myImgDesc[33] = "Pic34 Title|Pic34 Desc Pic34 DescPic34 Desc";
//			myImgDesc[34] = "Pic35 Title|Pic35 Desc Pic35 DescPic35 Desc";
//			myImgDesc[35] = "Pic36 Title|Pic36 Desc Pic36 DescPic36 Desc";
//			myImgDesc[36] = "Pic37 Title|Pic37 Desc Pic37 DescPic37 Desc";
//			myImgDesc[37] = "Pic38 Title|Pic38 Desc Pic38 DescPic38 Desc";
//			myImgDesc[38] = "Pic39 Title|Pic39 Desc Pic39 DescPic39 Desc";
//			myImgDesc[39] = "Pic40 Title|Pic40 Desc Pic40 DescPic40 Desc";
//		  
		// Count number of images
		imagesSum = myImg.length;
		
		// Tell browser where to find the image
		myImgSrc = "../../Content/gallery/Etchings/";
		
		// Tell browser the type of file
		myImgEnd = ".jpg";
		
		// Load the title and description
		imagesDesc = prepDesc(myImgDesc);
		
		i = 0;
		
		loadImg(myImg);
	}

}

// Create function to load image
function loadImg(){
	document.imgSrc.src = myImgSrc + myImg[i] + myImgEnd;
	
	document.getElementById('image_title').innerHTML = imagesDesc[i][0];
	document.getElementById('image_desc').innerHTML = imagesDesc[i][1];
}

//Prepare the title and description
function prepDesc()
{	
	var imagesDesc = new Array();
	for( var j = 0; j < imagesSum; j++ )
	{
		if( myImgDesc[j] == "" )
		{
			imagesDesc[j] = new Array();
			imagesDesc[j][0] = "";
			imagesDesc[j][1] = "";
		}
		else if( myImgDesc[j].indexOf('|') == -1 )
		{
			imagesDesc[j] = new Array();
			imagesDesc[j] = myImgDesc[j].split('|');
			imagesDesc[j][1] = "";
		}
		else
		{
			imagesDesc[j] = myImgDesc[j].split('|');
		}
	}	
	return imagesDesc;
}

// Create link function to switch image backward
function prev()
{
	if( i < 1 )
	{
		var l = i = imagesSum - 1;
	}
	else
	{
		var l = i-=1;
	}
	document.imgSrc.src = myImgSrc + myImg[l] + myImgEnd;
	
	document.getElementById('image_title').innerHTML = imagesDesc[l][0];
	document.getElementById('image_desc').innerHTML = imagesDesc[l][1];
}

// Create link function to switch image forward
function next()
{
	if( i > (imagesSum - 2) )
	{
		var l = i = 0;
	}
	else
	{
		var l = i+=1;
	}
	document.imgSrc.src = myImgSrc + myImg[l] + myImgEnd;
	
	document.getElementById('image_title').innerHTML = imagesDesc[l][0];
	document.getElementById('image_desc').innerHTML = imagesDesc[l][1];
}

// Load function after page loads
window.onload = initGallery;