// Language and cookies Functions: Copyright Sébastien Routier 
var langCookieName = "wawaL10n"; // Customize this to a unique string. Ex: "WawaL10n".
var defaultLang    = "fr";         // Set the default language. Ex: "en" or "fr".
var jsl10nKey      = "_jsl10n-";   // The key substring to use for the id of your DIVs. No need to change it.

function fnJsl10n() {
    var lang = fnGetL10nLang();
    fnShowLang(document.body, lang);
}

function fnShowLang(elem, lang) {
    var aChildren = elem.childNodes;
	 var i = 0;
    for (i = 0; i < aChildren.length; i++) {
        var sChildId = aChildren[i].id;
		  if ( sChildId && '' != sChildId ) {
				if (-1 != sChildId.indexOf(jsl10nKey + lang)) {
					 aChildren[i].style.display= "block";
				}
				else if (-1 != sChildId.indexOf(jsl10nKey)) {
					 aChildren[i].style.display = "none";          
				}
				fnShowLang(aChildren[i], lang);
		  }
    }
}

function fnGetL10nLang() {
    var lang = fnGetCookie(langCookieName);
//     alert("Cookie: (" + langCookieName + "):[" + lang + "]");
	 if ( !lang || '' == lang ) {
		  lang = defaultLang;
	 }
//     alert("Cookie: (" + langCookieName + "):[" + lang + "]");
	return (lang);
}

function fnSetL10nLang(lang) {
    var nextYear = new Date();
    nextYear.setFullYear(nextYear.getFullYear() + 1); // Cookie will expire in one year!
    fnSetCookie(langCookieName, lang, nextYear);
    fnShowLang(document.body, lang);
}

// [Cookie] Clears a cookie
function fnClearCookie(cookieName) {
   var now = new Date();
   var yesterday = new Date(now.getTime() - 1000 * 60 * 60 * 24);
   fnSetCookie(cookieName, 'DummyCookieValue', yesterday);
}

// [Cookie] Sets value in a cookie
function fnSetCookie(cookieName, cookieValue, expires, path, domain, secure) {
   document.cookie =
      escape(cookieName) + '=' + escape(cookieValue)
      + (expires ? '; expires=' + expires.toGMTString() : '')
      + (path ? '; path=' + path : '')
      + (domain ? '; domain=' + domain : '')
      + (secure ? '; secure' : '');
}

// [Cookie] Gets a value from a cookie
function fnGetCookie(cookieName) {
   var cookieValue = '';
   var posName = document.cookie.indexOf(escape(cookieName) + '=');
   if (posName != -1) {
      var posValue = posName + (escape(cookieName) + '=').length;
      var endPos = document.cookie.indexOf(';', posValue);
      if (endPos != -1) cookieValue = unescape(document.cookie.substring(posValue, endPos));
      else cookieValue = unescape(document.cookie.substring(posValue));
   }
   return (cookieValue);
}


// WAWA Design specific functions 
function DOMCall(name) {
	if (document.layers) 
		return document.layers[name];
	else if (document.all)
		return document.all[name];
	else if (document.getElementById)
		return document.getElementById(name);
}

function showPic (whichpic) {
	DOMCall('placeholder').src = whichpic.href;
	if (whichpic.title) {
		DOMCall('imageCaption').innerHTML = whichpic.title;
		DOMCall('imageCaption').className = "";
	} else {
		DOMCall('imageCaption').className = "hidden";
	}
 	return false;
}

function clickedImage (whichpic) {
	imageUrl = whichpic.src;  // grab the url of the medium image.
	/*imageUrl = imageUrl.replace(/images/gi, "images/large"); // add in the "large" dir so we can display the big picture
	imageWindow = window.open("popup.php?z="+imageUrl,'imageWin','width=640,height=480');  // popup the image in a new window set width and height to your max values*/
}


function switchIcons(iconId) {
DOMCall('mini1').className = "invisible";
DOMCall('mini2').className = "invisible";
DOMCall('mini3').className = "invisible";

DOMCall(iconId).className = "visible"; //"asdasd" set the current page to junk so it becomes visible
}


var lastID = "t0";
function SelectImg(id) {
if (lastID !="t0" ) {
document.getElementById(lastID).className = "thumbnail";
}
document.getElementById(id).className = "thumbSelect";
//document.getElementById(0).src = document.getElementById(id).src;
lastID = id;
}

function LoadTrigger() {
SelectImg('t1');
}
function InitLanguages() {
fnJsl10n();
}

// Menu Functions: Copyright Sébastien Routier 
function highlightPage(menuno) {
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false;
  if (!document.getElementById(menuno)) return false;
  var nav = document.getElementById(menuno);
  var links = nav.getElementsByTagName("a");
  var currenturl = window.location.href;
  for (var i=0; i<links.length; i++) {
    var linkurl = links[i].getAttribute("href");
    if (currenturl.indexOf(linkurl) != -1) {
      links[i].className = "current";
      var linktext = links[i].lastChild.nodeValue.toLowerCase();
      document.body.setAttribute("id",linktext);
		//break;
    }
  }
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}
/*function fnSetL10nLang( sLang ) {
	 true;
}*/
