
///////////////////////////////////////////////////
// Menu
///////////////////////////////////////////////////

//Cookie
var oldObCookieName = "_menu_selection_oldObCookieName_EDALGO_project_";

//Adauga un cookie
function addCookie(name,value,time){
	str=name+"="+value+"; path=/; ";
	if (time){
		
		var expire = new Date();
     	//expire.setTime (expire.getTime() + (time * 24 * 60 * 60 * 1000));
     	expire.setTime (expire.getTime() + (time * 1000));
     	expire = expire.toGMTString();
		
		str+="expires="+expire;
	}
	
	document.cookie=str;
}

//Sterge un cookie
function delCookie(name){
	addCookie(name,"",-1);
}

//Citeste un cookie
function readCookie(name){
	var ca=document.cookie.split(";");
	var i=0;
	name+="=";
	while (i<ca.length){
		var pos=ca[i].indexOf(name);
		if (pos>=0) return ca[i].substring(pos+name.length);
		i++;
	}
	return "";
}


//Menu functionality
//Init menu

var selectedItemSize = "10pt";
var unselectedItemSize = "8pt";
//var timeoutCookie = 1000000000;
var timeoutCookie = 0;

var oldObId = "menuKey1";

function buildURL(obId)
{
	return obId + ".html";
}

function initMenu(bInitial)
{
	/*if (readCookie(oldObCookieName) == "") 
		addCookie(oldObCookieName, "menuKey1", timeoutCookie);

	var obId = readCookie(oldObCookieName);*/
	
	/*if (oldObId == null) 
		oldObId = "menuKey1";*/

	
	var obId = oldObId;
		
	document.getElementById(obId).style.fontSize = selectedItemSize;
	document.getElementById(obId).style.textDecoration = "underline";
	
	
	if (bInitial) execMenuCommand(buildURL(obId));
	
}

//Change selection
function changeSel(obId)
{
	//var idOldOb = readCookie(oldObCookieName);
	
	var idOldOb = oldObId;

	document.getElementById(idOldOb).style.fontSize = unselectedItemSize;
	document.getElementById(idOldOb).style.textDecoration="none";

	document.getElementById(obId).style.fontSize = selectedItemSize;
	document.getElementById(obId).style.textDecoration="underline";

	/*delCookie(oldObCookieName);
	addCookie(oldObCookieName, obId, timeoutCookie);*/
	
	oldObId = obId;

	execMenuCommand(buildURL(obId));
	
}

//Exec a menu command
function execMenuCommand(url)
{
	document.location.href = url;
}


//PHOTOS section

function buildPhotoPath(directory, path, currentPhotoNumber)
{
	return directory + "/" + path + currentPhotoNumber + ".JPG";
}

function getURLParameter(param)
{
	var params = document.location.href.split('?')[1];
	var aParams = params.split('&');
	for (i = 0; i < aParams.length; i++)
	{
		var aQuery = aParams[i].split('=');
		if (aQuery[0] == param) return aQuery[1];
	}
	return "";
}

function buildPhotoPageURL(directory, path, currentPhotoNumber, maxPhotoNumber)
{
	return 'photos.html?directory=' + directory + "&path=" + path + "&currentPhotoNumber=" + currentPhotoNumber + "&maxPhotoNumber=" + maxPhotoNumber;
}

function showPhotos(directory, path, currentPhotoNumber, maxPhotoNumber)
{
	var win = window.open(buildPhotoPageURL(directory, path, currentPhotoNumber, maxPhotoNumber), 'photos_windows', 'height=600,width=800', false);
}

function createPhotoMenu(directory, path, currentPhotoNumber, maxPhotoNumber)
{
	document.writeln("<center>");
					
	if (currentPhotoNumber > 1)
	{
		document.writeln("<a href=\"" + buildPhotoPageURL(directory, path, parseInt(currentPhotoNumber) - 1, maxPhotoNumber) + "\"><<-</a>");
	}
					
	for (i = 1; i <= maxPhotoNumber; i++)
	{
		if (i == currentPhotoNumber)
		{
			document.writeln("&nbsp;");
			document.writeln("<b>" + i + "</b>");
			document.writeln("&nbsp;");
		}
		else
		{
			document.writeln("&nbsp;");
			document.writeln("<a href=\"" + buildPhotoPageURL(directory, path, i, maxPhotoNumber) + "\">" + i + "</a>");
			document.writeln("&nbsp;");
		}
	}
					
	if (currentPhotoNumber < maxPhotoNumber)
	{
		document.writeln("<a href=\"" + buildPhotoPageURL(directory, path, parseInt(currentPhotoNumber) + 1, maxPhotoNumber) + "\">->></a>");
	}
					
	document.writeln("</center>");
}

