// shanthic.js
	nColumnsPerPage = 2;
	nRowsPerPage = 2;
	nImagesPerPage = nRowsPerPage * nColumnsPerPage;
	imgHeight = 200;

	// Function used by all image pages to initialize the next and prev
	// page numbers based upon the current pages number passed by the
	// URL arg pageNum
	function getCurPageNum() {
	  	strSearch = document.URL;
//	  	alert(document.forms[0].curPage);
//	  	alert(strSearch);
	  	nCurPage = 1;
		retStr = getURLSearchArg("pageNum");
//		alert("retStr->" + retStr);
		if (retStr != null && retStr.length > 0) {
			nCurPage = parseInt(retStr);
			if (isNaN(nCurPage)) {
				nCurPage = 1;
			}
		}
		
		if (nCurPage < nTotalPages) {
			nNextPage = nCurPage + 1;
		}
		else {
			nNextPage = nCurPage;
		}

		if (nCurPage > 1) {
			nPrevPage = nCurPage - 1;
		}
		else {
			nPrevPage = 1;
		}
	}	

	// Generic function to extract 		
	function getURLSearchArg(strArgName) {
		strSearch = document.location.search;
//		alert("Serach String->" + strSearch + "->" + strArgName);
		if (strSearch == null || strSearch.length <=0 ) {
//			alert("strSearch is null");
			return(null);
		}
		searchStIndex = strSearch.search("/?" + strArgName + "=");
//		alert("serachStIndex->" + searchStIndex);
		if (searchStIndex <= 0) {
			searchStIndex = strSearch.search("/&" + strArgName + "=");
		}
		if (searchStIndex <= 0) {
//			alert("findArg returns null");
			return null;
		}
		searchEndIndex = strSearch.indexOf("&", searchStIndex);
		if (searchEndIndex < 0) { // Last item in the search string
			argValue = strSearch.slice(searchStIndex + 2 + strArgName.length - 1);
		}
		else {
			argValue = strSearch.slice(searchStIndex + 2 + strArgName.length - 1, searchEndIndex);
		}
//		alert("findArg returns ->" + argValue);		
		return(argValue);
	}
	
	
	function getTargetSize(strImg, imageHeight) {
//		alert("getTargetSize(strImg, height)-> " + strImg + "," + imageHeight);
		curImage = new Image();
		curImage.src = strImg;
		alert(curImage.src + "-Image size->" + curImage.width  + "," + curImage.height + ","+ ((curImage.width/curImage.height) * imageHeight));
		return((curImage.width/curImage.height) * imageHeight);
	}
	
	function showImage(urlLink)
	{
		if (!window.focus){
			return true;
		}
//		alert(typeof(urlLink) == 'string' ? urlLink : urlLink.href);
		window.open(typeof(urlLink) == 'string' ? urlLink : urlLink.href,
				"ImageViewer", 'resizable=yes,dependant=yes,scrollbars=yes width=700 height=700');
		return false;
	}
	
	// Function that displays images in the screen
	function layoutImages() {
		if (nCurPage <= 1) {
			nCurPage = 1;
			curImageIndex = 0;
		}
		else {
			curImageIndex = ((nCurPage - 1) * nImagesPerPage);
		}
/*		
		if (nCurPage == 1) {
			window.document.write("<TABLE border='0'> <TBODY> <COL='550'> <COL='150'>");
			window.document.write("<TR><TD colspan='1'><P>");
			window.document.write(pageDescription + "<BR>");
			window.document.write("</P></TD><TD colspa='1'></TD>");
			window.document.write("</TR><TBODY></TABLE>");
		}
*/
		if (nCurPage == 1) {
			window.document.write("<TABLE border='0'> <TBODY> <COL='550'> <COL='150'>");
			window.document.write("<TR><TD colspan='1'><FONT color='black' size='3' face='Arial Narrow'><P>");
			window.document.write(pageDescription + "<BR>");
			window.document.write("</FONT></P></TD><TD colspa='1'><BR></TD>");
			window.document.write("</TR><TBODY></TABLE>");
		}
		window.document.write("<TABLE border='0'> <TBODY>");
		for (var i = 0; i < nImagesPerPage; i++) {
			window.document.write("<TR >");
			for (var j = 0; j < nColumnsPerPage && (curImageIndex + j) < imageArray.length; j++) {
				window.document.write("<TD width='" + imgHeight + "' height='" + imgHeight +
					"' align='center'>");
				strTemp = "<A HREF='./imageDetails.html?imageIndex=" + (curImageIndex + j) + "' TARGET='_top'  onClick='return showImage(this)'>";
				window.document.write(strTemp);
//				alert("siteimages/" + imageArray[curImageIndex + j][0]);
				window.document.write("<IMG border='1'	src='siteimages/" + imageArray[curImageIndex + j][0] +
//						"' width='" + getTargetSize("siteimages/" + imageArray[curImageIndex + j][0], imgHeight) + "' height='" + 
						"' Height ='" + imgHeight +
						"' align='middle' alt='" + imageArray[curImageIndex + j][1] + "'>");
				window.document.write("</A><BR>");
				window.document.write("</TD>");
			}
			window.document.write("</TR>");
					
			// Write attribute row
			window.document.write("<TR HEIGHT='50'>");
/*
			for (var j = 0; j < nColumnsPerPage && (curImageIndex + j) < imageArray.length; j++) {
				window.document.write("<TD width='" + imgHeight + "' align='center' valign='top'>");
				window.document.write(imageArray[curImageIndex + j][1] + "<BR>" + 
					imageArray[curImageIndex + j][2] + "<BR><BR></TD>");
			}
*/
			for (var j = 0; j < nColumnsPerPage && (curImageIndex + j) < imageArray.length; j++) {
				window.document.write("<TD width='" + imgHeight + "' align='center' valign='top'>");
				window.document.write("<FONT color='black' size='2' face='Arial Narow'><I>");
				window.document.write(imageArray[curImageIndex + j][1] + "<BR>" + 
					imageArray[curImageIndex + j][2] + "<BR><BR></I></FONT></TD>");
			}										
			window.document.write("</TR>");
			curImageIndex += nColumnsPerPage;
			i += nColumnsPerPage;
		}
		window.document.write("</TBODY>");
		window.document.write("</TABLE>");
	}
	
	// Displays Left Hand Side navigator
	function displayLNav() {
		window.document.write("<FONT size='2' face='Arial'>");


		window.document.write("<UL>");
		window.document.write("<LI><A href='index.html'>Home</A></LI>");
		window.document.write("<LI><A href='akshara.html'>Akshara</A></LI>");
		window.document.write("<LI><A href='chakra.html'>Chakra</A></LI>");
		window.document.write("<LI><A href='tanjore.html'>Tanjore Style Paintings</A></LI>");
		window.document.write("<LI><A href='kolam.html'>Kolam</A></LI>");
		window.document.write("<LI><A href='maya.html'>Maya</A></LI>");
		window.document.write("<LI><A href='music.html'>Music</A></LI>");
		window.document.write("<LI><A href='panchaBhu.html'>Pancha-bhudhe-indriyam</A></LI>");
		window.document.write("<LI><A href='pilliyar.html'>Pilliyar</A></LI>");
		window.document.write("<LI><A href='redDots.html'>Red Dots</A></LI>");
		window.document.write("<LI><A href='shakthi.html'>Shakthi</A></LI>");
		window.document.write("<LI><A href='sloka.html'>Sloka</A></LI>");
		window.document.write("<LI><A href='unityInDiversity.html'>Unity In Diversity</A></LI>");
		window.document.write("<LI><A href='NewPaintings.html'>New Paintings</A></LI>");
		window.document.write("<LI><A href='dolls.html'>Handmade Dolls</A></LI>");
		window.document.write("</UL");
/*
		window.document.write("&nbsp;- <A href='home.html'>Home</A><BR>");
		window.document.write("&nbsp;- <A href='kolam.html'>Kolam</A><BR>");
		window.document.write("&nbsp;- <A href='music.html'>Music</A><BR>");
		window.document.write("&nbsp;- <A href='panchaBhu.html'>Pancha-bhudhe-indriyam</A><BR>");
		window.document.write("&nbsp;- <A href='pilliyar.html'>Pilliyar</A><BR>");
		window.document.write("&nbsp;- <A href='redDots.html'>Red Dots</A><BR>");
		window.document.write("&nbsp;- <A href='shakthi.html'>Shakthi</A><BR>");
		window.document.write("&nbsp;- <A href='sloka.html'>Sloka</A><BR>");
		window.document.write("&nbsp;- <A href='unityInDiversity.html'>Unity In Diversity</A><BR>");
*/
		window.document.write("</FONT>");
	}
	
	function displayPageNav() {
		if (nTotalPages > 1) {
			window.document.write("<input type='button'" + "onClick='pageTurner(1);'" + "value='|&lt&lt'" + "title='First'>");
			window.document.write("<input type='button'" + "onClick='pageTurner(" + nPrevPage + ");'" + "value='&lt&lt'" + "title='Previous'>");
			window.document.write("<input type='button'" + "onClick='pageTurner(" + nNextPage + ");'" + "value='>>'" + "title='Next'>");
			window.document.write("<input type='button'" + "onClick='pageTurner(" + nTotalPages + ");'" + "value='>>|'" + "title='Last'>");
//			window.document.write("<input type='button'" + "onClick='slideShow(" + (nCurPage -1) + ");'" + "value='SlideShow'" + "title='SlideShow'>");
		}
	}
	
	// This script ASSUMES single argument that is only pageNum
	// Wont work if multiple arguments are passed using URL
	function pageTurner(pageNum) {
		//document.URL = window.name + ".html" + "?pageNum=" + pageNum; 
		window.location = window.name + ".html" + "?pageNum=" + pageNum;
	}
	// Slide show related functions
	gCurSlide = 0;
	gSlideDelay = 4000; // Delay time can be set by the user in later version.
	function slideShow(nCurrentPage)
	{
		if (!window.focus){
			return true;
		}
		
		if (nCurPage <= 1) {
			nCurPage = 1;
			nTemp = 0;
		}
		else {
			nTemp = ((nCurPage - 1) * nImagesPerPage);
		}
		window.open("imageDetails.html?imageIndex=" + nTemp + "&SlideShow=yes", 
				"ImageViewer", "resizable=yes,dependant=yes,scrollbars=yes width=650 height=850");
	}
	function showFirstSlide() {
		gCurSlide = 0;
		showSlide();
	}

	function showNextSlide() {
		gCurSlide = ((gCurSlide + 1) % slideImages.length); // Loop thru the slides
		showSlide();
	}
	
	function showPrevSlide() {
		gCurSlide = gCurSlide == 0 ? (slideImages.length - 1) : --gCurSlide;
		showSlide();
	}

	function showLastSlide() {
		gCurSlide = slideImages.length - 1;
		showSlide();
	}
	
	function showSlide() { // helper function
		/*
		document.slide.src = "siteimages/" + slideImages[gCurSlide][0];
//		alert("SRC->" + document.slide.src + "->"  + slideImages[gCur//Slide]);
		document.getElementById('attribute1').firstChild.nodeValue = slideImages[gCurSlide][1];
		document.getElementById('attribute2').firstChild.nodeValue = slideImages[gCurSlide][2];
		*/
	}
	
	function toggleAutoSlide() {
		document.slideShow.autoshow.value = (document.slideShow.autoshow.value == "Stop") ? "Start" : "Stop";
//		rotateSlide();
		showSlide();
		nTemp = parseInt(document.slideShow.delayTime.value);
//		alert ("NTemp->" + nTemp);
		if (isNaN(nTemp) || (nTemp < 1 && nTemp > 240)) {
			alert("Delay value should be between 1 and 240 seconds");
			document.slideShow.delayTime.value = gSlideDelay / 1000;
		}
		else {
			gSlideDelay = nTemp * 1000;
		}
//		alert("Delay value->" + document.slideShow.delayTime.value + "->" + gSlideDelay);
		window.setTimeout("rotateSlide()", gSlideDelay);
	}
	
	function rotateSlide() {
		if (document.slideShow.autoshow.value == "Stop") {
			showNextSlide();
		nTemp = parseInt(document.slideShow.delayTime.value);
//		alert ("NTemp->" + nTemp);
		if (isNaN(nTemp) || (nTemp < 1 && nTemp > 240)) {
			alert("Delay value should be between 1 and 240 seconds");
			document.slideShow.delayTime.value = gSlideDelay / 1000;
		}
		else {
			gSlideDelay = nTemp * 1000;
		}

			window.setTimeout("rotateSlide()", gSlideDelay);
		}
   }
   	function startSlideShow() {
		toggleAutoSlide();
	}

	
	

