//      --------------------------------------------------------------------------
//      Javascript functions for www.young.ch
//      --------------------------------------------------------------------------
//      Image functions for the thumbnail/enlargements on the Image Gallery page
//      jset/funcs_gallpics_d.js
//      08-Sept-2010
            
//  	------------------------------------------------------------
//  	Image Set Menu and Thumbnails for ../gallery/index.htm
//  	------------------------------------------------------------
//  	re/writes the Set Menu
//  	makes the thumbnail set
//		first thumbnail chosen at random
//		but first get the no. pics in the new set!
//		the rest follow consecutively 
//  	data is stored in gallpics_data.js

//		-------------------------------------------
//		global variables
//		-------------------------------------------
		var SetID; var Thumb1; var ThumbID; var ThumbOffset;

//		-------------------------------------------
//		basic / setup functions
//		-------------------------------------------
		function GetSet() {
			var kk = Math.floor(Math.random()*NoSets + 1);
			SetID = kk;
			var np = eval("NoPics_" + SetID);
	        Thumb1 = Math.floor(Math.random()*np + 1);	
		}
		function DoMenu_D() {
			MakeMenuDiv();WriteMenuSet_D();
		}		
		function DoThumbnails_D() {
			MakeThumbDiv();GetThumbnails_D();
		}			
		function DoSubtitle_D() {
			MakeSubtitleDiv();WriteSubtitle_D();
		}
		function DoBigPic_D() {
			MakeBigPicDiv();GetBigPic_D();
		}			
		function DoFootnote_D() {
			MakeFootnoteDiv(); WriteFootnote_D();
		}
		function ChangeMenuAndThumbs_D() {
			WriteMenuSet_D(SetID);
			WriteSubtitle_D(SetID);
			GetThumbnails_D(SetID);
			GetBigPic_D(SetID);
			WriteFootnote_D(SetID);
		}
		function SwitchTo_1_D() {
			SetID = 1;
			var np = eval("NoPics_" + SetID);
	        Thumb1 = Math.floor(Math.random()*np + 1);
			ChangeMenuAndThumbs_D();
			}
		function SwitchTo_2_D() {
			SetID = 2;
			var np = eval("NoPics_" + SetID);
	        Thumb1 = Math.floor(Math.random()*np + 1);
			ChangeMenuAndThumbs_D();
			}
		function SwitchTo_3_D() {
			SetID = 3;
			var np = eval("NoPics_" + SetID);
	        Thumb1 = Math.floor(Math.random()*np + 1);
			ChangeMenuAndThumbs_D();
			}
		function SwitchTo_4_D() {
			SetID = 4;
			var np = eval("NoPics_" + SetID);
	        Thumb1 = Math.floor(Math.random()*np + 1);
			ChangeMenuAndThumbs_D();
			}
		function SwitchTo_5_D() {
			SetID = 5;
			var np = eval("NoPics_" + SetID);
	        Thumb1 = Math.floor(Math.random()*np + 1);
			ChangeMenuAndThumbs_D();
			}
        function MakeMenuDiv() {
            var theTD; var theDiv;
            theTD = document.getElementById("gallMenuTD");
                theDiv = document.createElement("div");
                theDiv.id = "menuset";
				theDiv.className = "gallMenuSub";  
            theTD.appendChild(theDiv);      // creates empty DIV
        }		
        function MakeThumbDiv() {
            var theTD; var theDiv;
            theTD = document.getElementById("gallThumbsTD");
                theDiv = document.createElement("div");
                theDiv.id = "thumbset";
            	theDiv.style.textAlign = "center";     
            	theDiv.style.width = ThumbDivX;       
            	theDiv.style.height = ThumbDivY;             
            theTD.appendChild(theDiv);      // creates empty DIV
        }
        function MakeSubtitleDiv() {
            var theTD; var theDiv;
            theTD = document.getElementById("gallSetSubtitleTD");
                theDiv = document.createElement("div");
                theDiv.id = "subtitle";
				theDiv.className = "gallSubtitle";  
            theTD.appendChild(theDiv);      // creates empty DIV
        }              
        function MakeBigPicDiv() {
            var theTD; var theDiv;
            theTD = document.getElementById("gallBigPicTD");
                theDiv = document.createElement("div");
                theDiv.id = "bigpic";
            theTD.appendChild(theDiv);      // creates empty DIV
        }		
        function MakeFootnoteDiv() {
            var theTD; var theDiv;
            theTD = document.getElementById("gallFootnoteTD");
                theDiv = document.createElement("div");
                theDiv.id = "footnote";
            theTD.appendChild(theDiv);      // creates empty DIV
        }
		function StepBack() {
			var NoPics = eval("NoPics_" + SetID);
			Thumb1 = Thumb1 - 1;
			if (Thumb1 < 1) Thumb1 = NoPics;
			GetThumbnails_D();
		}		
		function StepFwd() {
			var NoPics = eval("NoPics_" + SetID);
			Thumb1 = Thumb1 + 1;
			if (Thumb1 == NoPics) Thumb1 = 1;
			GetThumbnails_D();		
		}		
        function WhichThumb () {
            var ThumbIs = 1.0 * this.id + Thumb1;
			var np = eval("NoPics_" + SetID);
			if (ThumbIs > np) ThumbIs = ThumbIs - np;
            ShowBigPic_D(ThumbIs);
        }
//		--------------------------------------
//		Write the Menu
//		--------------------------------------
		function WriteMenuSet_D() {
            var theTD = document.getElementById("gallMenuTD");
            var theDiv = document.getElementById("menuset"); 
            theTD.removeChild(theDiv);      // clears previous thumbnails            
            MakeMenuDiv();            
            theDiv = document.getElementById("menuset"); 
			theDiv.className = "gallMenuSub";
			var theSet; var theMenuName; var aMenuItem; var aText; var br;
			for (var i = 0; i < NoSets; i++) {
				theSet = i+1;
				theMenuName = SetMenuNames_D[theSet];
				if (theSet == SetID) {	// make a span not an anchor
            		aMenuItem = document.createElement("span");   
            		aMenuItem.className = "gallMenuSubIs";					
            		aText = document.createTextNode("" + theMenuName +"");					
                	aMenuItem.appendChild(aText);
            		theDiv.appendChild(aMenuItem); 
				}
				else {
            		aMenuItem = document.createElement("a");
					aMenuItem.href = "#";
            		aMenuItem.onclick = eval("SwitchTo_" + theSet + "_D");					
            		aText = document.createTextNode("" + theMenuName +"");					
                	aMenuItem.appendChild(aText);
            		theDiv.appendChild(aMenuItem); 
				}		
				if (i < (NoSets-1)) {		
            		br = document.createElement("br");  
            		theDiv.appendChild(br); 
				}
			}
		}
//		--------------------------------------
//		Get the thumbnails 
//		--------------------------------------
        function GetThumbnails_D() {
            var theSet = SetID;
			var NoPics = eval("NoPics_" + theSet);
			var theFilenameSet = eval("Filename_" + theSet);
			var thePicTitleSet = eval("PicTitle_" + theSet + "_D");
	        var thePxSet = eval("px_" + theSet);
   			var thePySet = eval("py_" + theSet);       
            var theTD = document.getElementById("gallThumbsTD");
            var theDiv = document.getElementById("thumbset"); 
            theTD.removeChild(theDiv);      // clears previous thumbnails            
            MakeThumbDiv();            
            theDiv = document.getElementById("thumbset"); 
            var aLink; var imgThumb; var np; var px; var py; var hs; var vs; var i; var k;
			np = eval("NoPics_" + SetID);
			k = Thumb1; hs = 0; vs =0;			
            for (i = 0; i < NoThumbs; i++) {	// total the thumbnail widths
				if (k > np) k = 1;
				hs = hs + 0.2*thePxSet[k];
				k = k + 1;
			}
			hs = Math.floor(0.5*(ThumbDivX - hs)/NoThumbs);
			k = Thumb1;
            for (i = 0; i < NoThumbs; i++) {	// get the thumbnails      
				if (k > np) k = 1;
                aLink = document.createElement("a");
				aLink.id = "" + i + "";
				aLink.className = "imglink";
				aLink.style.cursor = "pointer";
				aLink.onclick = WhichThumb;
				aLink.title = "" + thePicTitleSet[k] + "";
                	imgThumb = document.createElement("img");
					ThumbOffset = k - 1;
					imgThumb.id = "" + ThumbOffset + "";
					imgThumb.src = "../../gifs/gallgifs/" + theFilenameSet[k] + ".gif";
                	imgThumb.alt = "" + thePicTitleSet[k] + "";
					px = 0.2*thePxSet[k];
					py = 0.2*thePySet[k];
					vs = 0.5*(ThumbDivY - py);
					imgThumb.width = "" + px + "";
					imgThumb.height = "" + py + "";
					imgThumb.hspace = "" + hs + "";
					imgThumb.vspace = "" + vs + "";
					imgThumb.style.padding = "0";
					aLink.appendChild(imgThumb);
				theDiv.appendChild(aLink);  
				k = k + 1;            
			}
        }
//  	---------------------------------------------------------
//  	Get the big picture, ie. of the first thumbnail
//  	---------------------------------------------------------
        function GetBigPic_D() {
			var theFilenameSet = eval("Filename_" + SetID);
			var thePicTitleSet = eval("PicTitle_" + SetID + "_D");
			var theArtistNameSet = eval("ArtistName_" + SetID);
			var theMediumSet = eval("Medium_" + SetID + "_D");
			var theLinkTextSet = eval("PicLinkText_" + SetID + "_D");
			var theLinkAddressSet = eval("PicLinkAddress_" + SetID);
			var theLinkURLSet = eval("PicLinkURL_" + SetID + "_D");			
			var thePicThankTextSet = eval("PicThankText_" + SetID + "_D");
	        var thePxSet = eval("px_" + SetID);
   			var thePySet = eval("py_" + SetID);       
            var theTD; var theDiv; var imgPic; var pTitle; var pName;  var pLink; var pLinkText; var pThankText; var pText; var k;
            theTD = document.getElementById("gallBigPicTD");
                theDiv = document.getElementById("bigpic"); 
            theTD.removeChild(theDiv);      // clears previous picture
            MakeBigPicDiv();
            theDiv = document.getElementById("bigpic");
                imgPic = document.createElement("img");
                imgPic.id = "bigpic";
                imgPic.src = "../../jpgs/galljpgs/" + theFilenameSet[Thumb1] + ".jpg";
                imgPic.alt = "" + thePicTitleSet[Thumb1] + "";
                imgPic.title = "" + thePicTitleSet[Thumb1] + "";
				px = thePxSet[Thumb1];
				py = thePySet[Thumb1];
				hs = 0.5*(BigPicDivX - px);
				vs = 0.5*(BigPicDivY - py);
				imgPic.width = "" + px + "";
				imgPic.height = "" + py + "";
				imgPic.hspace = "" + hs + "";
				imgPic.vspace = "" + vs + "";
				imgPic.style.padding = "0";
            theDiv.appendChild(imgPic);					
				pTitle = document.createElement("p");
            	pTitle.style.textAlign = "center";     
            	pTitle.style.margin = "30px 0 0 0";
				pTitle.style.fontSize = "16px";
				pTitle.style.fontWeight = "bold";
                   pText = document.createTextNode("" + thePicTitleSet[Thumb1]+  "");
                pTitle.appendChild(pText);
            theDiv.appendChild(pTitle);
				pName = document.createElement("p");
            	pName.style.textAlign = "center";     
            	pName.style.margin = "10px 0 5px 0";
				pName.style.fontSize = "14px";
				pName.style.fontWeight = "normal";
                   pText = document.createTextNode("" + theMediumSet[Thumb1] + " von " + theArtistNameSet[Thumb1] + "");
                pName.appendChild(pText);
            theDiv.appendChild(pName);			
                pLink = document.createElement("p");  
            	pName.style.margin = "10px"; 
              	pLink.style.textAlign = "center";
				pLink.style.fontSize = "11px";
				pLink.style.fontWeight = "normal";
                	pLinkText = document.createTextNode("" + theLinkTextSet[Thumb1] + "");
				pLink.appendChild(pLinkText);
                    aLink = document.createElement("a");
                    aLink.href = "" + theLinkURLSet[Thumb1] + "";
                    aLink.title = "";
                    aLink.target = "_blank";
            		aLink.style.margin = "10px"; 
            		aLink.style.padding = "3px"; 
					aLink.style.fontSize = "11px";
					aLink.style.fontWeight = "bold";
					aLink.style.textDecoration = "underline";
                        pText = document.createTextNode("" + theLinkAddressSet[Thumb1] + "");
                    aLink.appendChild(pText);
                pLink.appendChild(aLink);
            theDiv.appendChild(pLink);
				pThankText = document.createElement("p");
            	pThankText.style.textAlign = "center";     
            	pThankText.style.margin = "5px";
				pThankText.style.fontSize = "11px";
				pThankText.style.fontWeight = "normal";
                   pText = document.createTextNode("" + thePicThankTextSet[Thumb1] + "");
                pThankText.appendChild(pText);
            theDiv.appendChild(pThankText);
        }
		
//  	---------------------------------------------------------
//  	show the big picture of the thumbnail which was clicked
//  	---------------------------------------------------------
        function ShowBigPic_D(ThumbID) {
			var theFilenameSet = eval("Filename_" + SetID);
			var thePicTitleSet = eval("PicTitle_" + SetID + "_D");
			var theArtistNameSet = eval("ArtistName_" + SetID);
			var theMediumSet = eval("Medium_" + SetID + "_D");
			var theLinkTextSet = eval("PicLinkText_" + SetID + "_D");
			var theLinkAddressSet = eval("PicLinkAddress_" + SetID);
			var theLinkURLSet = eval("PicLinkURL_" + SetID + "_D");			
			var thePicThankTextSet = eval("PicThankText_" + SetID + "_D");
	        var thePxSet = eval("px_" + SetID);
   			var thePySet = eval("py_" + SetID);      
            var theTD; var theDiv; var imgPic; var pTitle; var pName; var pComment; var pText; var k;
            theTD = document.getElementById("gallBigPicTD");
                theDiv = document.getElementById("bigpic"); 
            theTD.removeChild(theDiv);      // clears previous picture
            MakeBigPicDiv();
            theDiv = document.getElementById("bigpic");
                imgPic = document.createElement("img");
                imgPic.id = "bigpic";
                imgPic.src = "../../jpgs/galljpgs/" + theFilenameSet[ThumbID] + ".jpg";
                imgPic.alt = "" + thePicTitleSet[ThumbID] + "";
                imgPic.title = "" + thePicTitleSet[ThumbID] + "";
				px = thePxSet[ThumbID];
				py = thePySet[ThumbID];
				hs = 0.5*(BigPicDivX - px);
				vs = 0.5*(BigPicDivY - py);
				imgPic.width = "" + px + "";
				imgPic.height = "" + py + "";
				imgPic.hspace = "" + hs + "";
				imgPic.vspace = "" + vs + "";
				imgPic.style.padding = "0";
            theDiv.appendChild(imgPic);					
				pTitle = document.createElement("p");
            	pTitle.style.textAlign = "center";     
            	pTitle.style.marginTop = "30px";
				pTitle.style.fontSize = "16px";
				pTitle.style.fontWeight = "bold";
                   pText = document.createTextNode("" + thePicTitleSet[ThumbID]+  "");
                pTitle.appendChild(pText);
            theDiv.appendChild(pTitle);
				pName = document.createElement("p");
            	pName.style.textAlign = "center";     
            	pName.style.margin = "10px 0 5px 0";
				pName.style.fontSize = "14px";
				pName.style.fontWeight = "normal";
                   pText = document.createTextNode("" + theMediumSet[ThumbID] + " von " + theArtistNameSet[ThumbID] + "");
                pName.appendChild(pText);
            theDiv.appendChild(pName);		
                pLink = document.createElement("p");  
            	pName.style.margin = "10px"; 
              	pLink.style.textAlign = "center";
				pLink.style.fontSize = "11px";
				pLink.style.fontWeight = "normal";
                	pLinkText = document.createTextNode("" + theLinkTextSet[ThumbID] + "");
				pLink.appendChild(pLinkText);
                    aLink = document.createElement("a");
                    aLink.href = "" + theLinkURLSet[ThumbID] + "";
                    aLink.title = "";
                    aLink.target = "_blank";
            		aLink.style.margin = "10px"; 
            		aLink.style.padding = "3px"; 
					aLink.style.fontSize = "11px";
					aLink.style.fontWeight = "bold";
					aLink.style.textDecoration = "underline";
                        pText = document.createTextNode("" + theLinkAddressSet[ThumbID] + "");
                    aLink.appendChild(pText);
                pLink.appendChild(aLink);
            theDiv.appendChild(pLink);
				pThankText = document.createElement("p");
            	pThankText.style.textAlign = "center";     
            	pThankText.style.margin = "5px";
				pThankText.style.fontSize = "11px";
				pThankText.style.fontWeight = "normal";
                   pText = document.createTextNode("" + thePicThankTextSet[ThumbID] + "");
                pThankText.appendChild(pText);
            theDiv.appendChild(pThankText);
        }
		
//		--------------------------------------
//		Write the Set Subtitle
//		--------------------------------------
		function WriteSubtitle_D() {
            theTD = document.getElementById("gallSetSubtitleTD");
            theDiv = document.getElementById("subtitle"); 
            theTD.removeChild(theDiv);      // clears previous subtitle            
            MakeSubtitleDiv();            
            theDiv = document.getElementById("subtitle");
			var theSubtitle; var pItem; var pText;
			theSubtitle = SetSubtitles_D[SetID];
            	pItem = document.createElement("p");  
            	pText = document.createTextNode("" + theSubtitle +"");					
            	pItem.appendChild(pText);
            theDiv.appendChild(pItem);			
		}
//		--------------------------------------
//		Write the Set Footnote
//		--------------------------------------
		function WriteFootnote_D() {
            theTD = document.getElementById("gallFootnoteTD");
            theDiv = document.getElementById("footnote"); 
            theTD.removeChild(theDiv);      // clears previous subtitle            
            MakeFootnoteDiv();            
            theDiv = document.getElementById("footnote");
			var theFootnote; var pItem; var pText;
			theFootnote = SetFootnotes_D[SetID];
            	pItem = document.createElement("p"); 
            	pText = document.createTextNode("" + theFootnote +"");					
            	pItem.appendChild(pText);
            theDiv.appendChild(pItem);			
		}
		 
        
// ---------------- End
