// JavaScript Document
var currentPic = 0;
	var PicWin;
	var playid;
	
	function LoadGallery(pic_id, picNo)
	// load pic array number
	{
		currentPic=picNo;
		
		
		var splitted = new Array();
		switch (pic_id) {
			case "pg1" :
				splitted = picArray[picNo].split('|');
				break;
			case "pg2" :
				splitted = picArray2[picNo].split('|');
				break;
			default :
				break;
		}
		
		var pic = new Image();
		pic.src = splitted[0];
		var picWidth = pic.width;
		var picHeight = pic.height; 
		if (picWidth >= picHeight)
		{
			picHeight = picHeight * (picSq/picWidth);
			picWidth = picSq;
		} else {
			picWidth = picWidth * (picSq/picHeight);
			picHeight = picSq;
		}
		
		document.getElementById(pic_id).src = splitted[0];
		document.getElementById(pic_id).width = picWidth;
		var caption_id = pic_id + "caption";
		document.getElementById(caption_id).innerHTML=splitted[1];
		
		}
	function nextPrev (pic_id, move)
	{
		if (move=='next')
		{
			if (currentPic < (NoOfPics-1))
			{
				currentPic++;
			} else { 
				currentPic = 0;
			}
			LoadGallery(pic_id, currentPic);	
		}
		if (move=='prev')
		{
			if (currentPic > 0)
			{
				currentPic--;
			} else { 
				currentPic = (NoOfPics-1);
			}
			LoadGallery(pic_id, currentPic);
		}
	
	LoadGallery(pic_id, currentPic);
	}
	
	function play(pic_id, play)
	{
		var play_id = pic_id + 'playing';
		if (play == 1)
		{
			var tempplaystr = "javascript:play('" + pic_id + "', 0)";
			document.getElementById(play_id).innerHTML='pause';
			document.getElementById(play_id).href= tempplaystr;
			nextPrev(pic_id, 'next')
			playid = setTimeout(("play('" + pic_id + "', 1)"), (playSeconds *1000));
		}
		if (play == 0)
		{
			var tempplaystr = "javascript:play('" + pic_id + "', 1)";
			document.getElementById(play_id).innerHTML='play';
			document.getElementById(play_id).href=tempplaystr;
			clearTimeout(playid);
		}
	}
		
	function PopUpImage ()
	//this is to change the popup image window function
	{
		var getImage = document.getElementById(pic_id).src;
		var pic = new Image();
		pic.src = getImage;
		var picWidth = pic.width;
		var picHeight = pic.height; 
		PicWin = window.open (getImage,'','width=700,height=500,menubar=no');
		//PicWin = window.open (getImage,'','width='+(pic.width+20)+',height='+(pic.height+28)+',menubar=no');
	}
