
<!-- ************************************************** -->

var photo_nr 						= 0;
var photoset_nr;
var menu_nr;

var gallery_count_rows			= 5;
var gallery_count_lines		= 3;

var slideshow 						= null;
var slideshow_secs				= 6;

var lang 							= 0;
var show_foto 						= false;


<!-- ************************************************** -->

function InitPage()
{
	menu_nr				= 0;
	photoset_nr 		= 0;
	var page_url 		= document.location.href;
	var show_photo		= false;
	
	
	//......................................check parameters
	var with_anchor	= (page_url.indexOf ("#") != -1);
	if (with_anchor)
	{
		var page_param 	= page_url.substr (page_url.lastIndexOf ("#") + 1);
		var page_anchor	= page_param.substr (2);
		if (page_param.charAt (0) == "m")
		{
			page_anchor 	= parseInt (page_anchor);
			if (page_anchor >= 0 && page_anchor < text_main_menu.length)
			{
				photoset_nr 	= page_anchor;
				menu_nr			= page_anchor;
			}
		}
		else if (page_param == "about")
		{
			menu_nr = text_main_menu.length;
		}
		else
		{
			show_photo = SearchPhoto (page_anchor);

		}
	}
	
	//..............................................init gui
	InitGUI();
	MenuSelect (menu_nr);

	if (show_photo)
	{
		ShowPhoto(-1);
	}
	
	
	document.onkeyup = OnKeyPress;
}

<!-- ************************************************** -->

function OnKeyPress (event)
{
	if (!event) event = window.event;
	switch (event.keyCode)
	{
		case 37: // left
			if (show_foto) ChangePhoto (-1); 
			else ChangeGallery (-1);	
			break;
		case 39: // right
			if (show_foto) ChangePhoto (1); 	
			else ChangeGallery (1);	
			break;
		case 38: // up
			MenuUp(); 
			break;
		case 40: // down
			if (!show_foto) ShowPhoto ("link_" + photo_nr);
			break;
		case 32: // blank
			ToggleSlideshow();	
			joFIND ("button_slideshow").src='images/button_slideshow' + (slideshow ? '_active' : '') + '.png';
			break;
		case 13:
			return false;
	}
	
//	alert (event.keyCode);
}

<!-- ************************************************** -->

function InitGUI()
{
	var menu_node, a_node, img_node;
	menu_node = joFIND ("small_menu");
	joDOM.RemoveChildNodes (menu_node);

	for (var i = 0; i < text_main_menu.length; i++)
	{
		a_node 									= joAddHTMLChildNode (menu_node, "A", "", "menu_" + i);
			a_node.href 						= "#m-" + i;
			a_node.onclick						= function () { MenuSelect (this.id.substr (5)) };
			a_node.onmouseover				= function () { ShowMenuTitle (this.id) };
			a_node.onmouseout					= function () { ShowMenuTitle ("") };
			a_node.title						= text_main_menu[i][lang];
			img_node								= joAddHTMLChildNode (a_node, "IMG", "", "menu_img_" + i);
				img_node.src					= "images/menu_" + text_main_menu[i][0] + "_sm.jpg";
				img_node.onmouseover		= function () { if (this.className != "active") HiliteImg (this) };
				img_node.onmouseout			= function () { if (this.className != "active") HiliteImg (this) };

		// joAddHTMLChildNode 	(menu_node, "<br />");
	}
	joFIND ("small_menu_title").innerHTML = text_main_menu[photoset_nr][lang];
}

<!-- ************************************************** -->

function ChangeGallery (shift)
{
	menu_nr = menu_nr + shift;
	if (menu_nr < 0) menu_nr = photos.length - 1;
	else if (menu_nr >= photos.length) menu_nr = 0;
	window.location.href = "#m-" + menu_nr;
	MenuSelect (menu_nr);
}

<!-- ************************************************** -->

function MenuSelect (nr)
{
	menu_nr = nr;

	if (menu_nr < photos.length)
	{
		FillGallery (menu_nr); 
		ShowGallery();
		HideAbout();
	}
	else
	{
		HideGallery();
		HidePhoto();
		ShowAbout();
	}
	
	RefreshMainMenu();
}

<!-- ************************************************** -->

function ShowAbout()
{
	joFIND ("container_about").style.display = "block";
	joFIND ("small_menu_title").innerHTML = "&#160;";
}

<!-- ************************************************** -->

function HideAbout()
{
		joFIND ("container_about").style.display = "none";
}

<!-- ************************************************** -->

function RefreshMainMenu()
{
	for (var i = 0; i < text_main_menu.length; i++)
	{
		var menu_img_node 			= joFIND ("menu_img_" + i);
		menu_img_node.className 	= (i == menu_nr ? "active" : "");
		menu_img_node.src				= "images/menu_" + text_main_menu[i][0] + (i == menu_nr ? "_sm_active" : "_sm") + ".jpg";
	}
}

<!-- ************************************************** -->

function OpenWindow (win_href, win_title, win_width, win_height, win_center, with_scrollbars, win_resizable, with_bar)
{

	if (win_height > screen.availHeight - 50)
		win_height = screen.availHeight - 50;

	win_width = win_width - 0;
	if (with_scrollbars == 'true')
	{
		win_width += 20;
	}
	
	var win_flags = "width=" + win_width + ",height=" + win_height;
	win_flags += ",resizable=yes,dependent=yes";
	
	if (with_scrollbars == 'true')
	{
		win_flags += ",scrollbars=yes";
	}
	
	if (win_center)
	{
		var win_left = Math.ceil ((screen.availWidth - win_width) / 2);
		var win_top  = Math.ceil ((screen.availHeight - win_height) / 3);
		win_flags	+= ",left=" + win_left + ",top=" + win_top;
	}
	
	win_flags += ",resizable=" + ((win_resizable != "false") ? "yes" : "no");
	win_flags += ",location=" + ((with_bar == "true") ? "yes" : "no");
	win_flags += ",menubar=" + ((with_bar == "true") ? "yes" : "no");
	win_flags += ",toolbar=" + ((with_bar == "true") ? "yes" : "no");

	window.open (win_href, win_title, win_flags);
}

<!-- ************************************************** -->

function ShowDivExclusively (div_name, div_category)
{
	var allObjects = document.getElementsByTagName ('div');
	var ObjClass;

	for (i = 0; i < allObjects.length; i++)
	{
		ObjClass = allObjects[i].className + "";
		if (ObjClass.indexOf (div_category) != -1)
		{
			if (allObjects[i].id == div_name)	ShowDiv (allObjects[i].id);
			else 											HideDiv (allObjects[i].id);
		}
	}
}

<!-- ************************************************** -->

function ShowDiv (div_name)
{
	var obj_div = joFIND (div_name);
	if (obj_div)
	{
		obj_div.style.visibility = "visible";
	}
}

<!-- ************************************************** -->

function HideDiv (div_name)
{
	var obj_div = joFIND (div_name);
	if (obj_div)
	{
		obj_div.style.visibility = "hidden";
	}
}

<!-- ************************************************** -->

function ToggleMenuTitle (menu_nr, on_off)
{
	(on_off ? ShowDiv ("menu_title_" + menu_nr) : HideDiv ("menu_title_" + menu_nr));
}

<!-- ************************************************** -->

function GetPhotoNr (pnr, shift)
{
	var result = pnr + shift;
	
	if (result >= photos [photoset_nr].length) result = 0;
	if (result < 0) result = photos [photoset_nr].length - 1;
	
	return result;
}

<!-- ************************************************** -->

function ChangePhoto (shift)
{
	photo_nr = GetPhotoNr (photo_nr, shift);
	
	DisplayPhoto (shift);

	if (slideshow)
	{
		slideshow = window.setTimeout ("ChangePhoto (1)", 1000 * slideshow_secs);
	}
}

<!-- ************************************************** -->

function DisplayPhoto (shift)
{
	joFIND ("photo").src = "images/s.gif";
	joFIND ("photo").src = "photos/" + photos [photoset_nr] [photo_nr][0];
	
//	joFIND ("next_photo_slideshow").src = "photos/" + photos [photoset_nr] [GetPhotoNr (photo_nr, shift)][0];
	
	joFIND ("photo_title").innerHTML = photos [photoset_nr] [photo_nr][0];
//	joFIND ("photo_title").innerHTML = (photos [photoset_nr] [photo_nr].length > 1 ? photos [photoset_nr] [photo_nr][1] : "");
	joFIND ("photo_nr").innerHTML = (photo_nr + 1) + " / " + photos [photoset_nr].length;
	
	joFIND ("link_back").href = "#p-" + photos [photoset_nr] [GetPhotoNr (photo_nr, 0)][0];
	joFIND ("link_next").href = "#p-" + photos [photoset_nr] [GetPhotoNr (photo_nr, 0)][0];
	window.location.href = "#p-" + photos [photoset_nr] [GetPhotoNr (photo_nr, 0)][0];
}

<!-- ************************************************** -->

function HideGallery()
{
	joFIND ("container_gallery").style.display = "none";
}

<!-- ************************************************** -->

function ShowPhoto (idx)
{
	show_foto = true;
	HideGallery();

	if (idx != -1)
		photo_nr = parseInt (idx.substr (idx.lastIndexOf ("_") + 1));
	
	DisplayPhoto (0);
	
	joFIND ("container_photo").style.display = "block";
	joFIND ("link_up").href = "#m-" + photoset_nr;
	joFIND ("menu_photo").style.visibility = "visible";
}

<!-- ************************************************** -->

function ShowGallery()
{
	HidePhoto();
	joFIND ("container_gallery").style.display = "block";
	photo_nr = 0;
}

<!-- ************************************************** -->

function HidePhoto()
{
	show_foto = false;
	ToggleSlideshow (true);
	
	joFIND ("container_photo").style.display = "none";
	joFIND ("menu_photo").style.visibility = "hidden";
}

<!-- ************************************************** -->

function SearchPhoto (photoname)
{
	var result = false;
	var i, j;
	
	for (i = 0; !result && i < photos.length; i++)
	{
		for (j = 0; !result && j < photos[i].length; j++)
		{
			if (photos[i][j][0] == photoname)
			{
				result 			= true;
				photoset_nr		= i;
				menu_nr			= i;
				photo_nr			= j;
			}
		}
	}
	
	return result;
}

<!-- ************************************************** -->

function FillGallery (phnr)
{
	var line, row, table_node, tbody_node, tr_node, td_node, a_node, img_node, i, j, count;
	
	photoset_nr = phnr;

	table_node 											= joFIND ("gallery");
		joDOM.RemoveChildNodes 					(table_node);
		tbody_node 										= joAddHTMLChildNode (table_node, "TBODY");

			for (j = 0, count = 0; count < photos [photoset_nr].length; j++)
			{
				tr_node 									= joAddHTMLChildNode (tbody_node, "TR");
				for (i = 0; count < photos [photoset_nr].length && i < gallery_count_rows; i++, count++)
				{
					td_node 								= joAddHTMLChildNode (tr_node, "TD");
						td_node.id 						= "thumb_" + j + "_" + i;
						td_node.innerHTML 			= "";

							a_node 						= joAddHTMLChildNode (td_node, "A", "", "link_" + count);
								a_node.href 			= "#p-" + photos [photoset_nr] [count][0];
								a_node.onclick			= function () { ShowPhoto (this.id) };
								img_node					= joAddHTMLChildNode (a_node, "IMG");
									img_node.src		= "thumbnails/" + photos [photoset_nr] [count][0];
				}
			}

}

<!-- ************************************************** -->

function ToggleSlideshow (slideshow_off)
{
	if (!slideshow && !slideshow_off)
	{
		slideshow = window.setTimeout ("ChangePhoto (1)", 1000 * slideshow_secs);	
		ShowPhoto (-1);
		
		joFIND ("container_photo").style.display = "block";
	}
	else
	{
		if (slideshow_off) joFIND ("button_slideshow").src = "images/button_slideshow.png";
		if (slideshow) window.clearTimeout (slideshow);
		slideshow = null;
	}
}

<!-- ************************************************** -->

function HiliteImg (img_node)
{
	var imgsrc			= img_node.src;
	var node_class 	= img_node.className;
	
	if (node_class == "hilite")
	{
		imgsrc = imgsrc.replace ("_active", "");
		img_node.className = "";
	}
	else
	{
		imgsrc = imgsrc.substr (0, imgsrc.lastIndexOf (".")) + "_active" + imgsrc.substr (imgsrc.lastIndexOf ("."));
		img_node.className = "hilite";
	}

	img_node.src = imgsrc;
}

<!-- ************************************************** -->

function ShowMenuTitle (menu_nr)
{
	if (menu_nr == "") 
				menu_nr = photoset_nr;
	else		menu_nr = parseInt (menu_nr.substr (menu_nr.lastIndexOf ("_") + 1));
	if (menu_nr != -1 && menu_nr < text_main_menu.length)
	{
		joFIND ("small_menu_title").innerHTML = text_main_menu[menu_nr][lang];
	}
	else
	{
		joFIND ("small_menu_title").innerHTML = "&#160;";
	}
}

<!-- ************************************************** -->

function MenuUp (menu_nr)
{
	if (joFIND ("container_photo").style.display != "block")
	{
		joFIND ("link_up").href = "index.html";
		document.location.href = "index.html";
		return false;
	}
	else
	{
		document.location.href = "#m-" + photoset_nr;
		ShowGallery(); 
	}
}
