var styleBgColor = "#FFFCF4";
var nbPhotoStyles = 4;
var nbStyles = 3;
var randomStyle;

function embedFlash(movieLocation,width,height,backgroundColor,targetDiv) {
	var codeInsere = "";
	codeInsere += "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" width=\"" +width+ "\" height=\""+ height +"\">\n";
	codeInsere += "<param name=\"movie\" value=\"" + movieLocation +"\" />\n";
	codeInsere += "<param name=\"quality\" value=\"high\" />\n";
	codeInsere += "<param name=\"bgcolor\" value=\"" + styleBgColor +"\" />\n";
	codeInsere += "<embed src=\"" + movieLocation +"\" quality=\"high\" bgcolor=\"" + styleBgColor +"\" width=\"" +width+ "\" height=\""+ height +"\" name=\"holder\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />\n";
	codeInsere += "</object>\n";
	document.getElementById(targetDiv).innerHTML = codeInsere;
}

function detectLanguage() {
	var cookieLang = readCookie("nausica-lang");
	if (cookieLang != "") {
		switch (cookieLang) {
			case "EN" :
				window.top.location = "en/index.html";
				break;
			default :
		}
	}
	else if (navigator.userLanguage) {
		if(navigator.userLanguage.indexOf("en") != -1 ) {
			window.top.location = "en/index.html";
			createCookie("nausica-lang", "EN", 8760);
		}
		if(navigator.userLanguage.indexOf("fr") != -1 ) {
			createCookie("nausica-lang", "FR", 8760);
		}
	}	
	else if (navigator.language) {
		if(navigator.language.indexOf("en") != -1 ) {
			window.top.location = "en/index.html";
			createCookie("nausica-lang", "EN", 8760);
		}
		if(navigator.language.indexOf("fr") != -1 ) {
			createCookie("nausica-lang", "FR", 8760);
		}
	}
}

function switchLanguage(langue) {
	createCookie("nausica-lang", langue, 8760);
}

// This stylesheet switching script based on Paul Snowden's work described on A List Apart
//  <http://www.alistapart.com/stories/alternate/>

var cookie = readCookie("nausica-style");
if (cookie) {
  var title = cookie ? cookie : 'Orange';
  setActiveStyleSheet(title);
}

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
  createCookie("nausica-style", title, 8760);
  if ((document.getElementById('lienOrange'))&&(document.getElementById('lienGris'))) {
    showStyleLink();
  } 
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,hours) {
  if (hours) {
    var date = new Date();
    date.setTime(date.getTime()+(hours*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

/* style link display function - Sophie G */

function showStyleLink() {
  var styleChoisi = getActiveStyleSheet();
  if(styleChoisi=="Gris"){
    document.getElementById('lienGris').style.display = "none";
    document.getElementById('lienOrange').style.display = "block";
	styleBgColor = "#404044";
  }
  else if (document.getElementById('lienGris')){
    document.getElementById('lienGris').style.display = "block";
    document.getElementById('lienOrange').style.display = "none";
	styleBgColor = "#FFFCF4";
  }
}

/* body appearance randomization - sophie g */

function randomizeBody() {
  var setRandom = readCookie("nausica-random");
  if (setRandom) {
  	randomStyle = setRandom;
  }
  else {
  	randomStyle = Math.floor(Math.random()*nbStyles);
  }
//  randomStyle = 1;
  if(randomStyle==0) {
    document.body.className = "hautNoir";
  }
  else if(randomStyle==1) {
    document.body.className = "hautBleu";
  }
  createCookie("nausica-random", randomStyle, 1);
}

function randomizeBanner() {
  var randomBanner = Math.floor(Math.random()*nbPhotoStyles);
  var nomStyle = "style0" + randomBanner;
  document.getElementById('flashContent').className = nomStyle;
}

/* summary stats function */
function whenReady() { 
  ls="/log____image.gif?summarylog&je="+navigator.javaEnabled()+ "&sw="+screen.width+"&sh="+screen.height;
  if (screen.pixelDepth) ls+="&sd="+screen.pixelDepth; 
  else if (screen.colorDepth) ls+="&sd="+screen.colorDepth; 
  if (navigator.language) ls+="&la="+navigator.language; 
  else if (navigator.userLanguage) ls+="&la="+navigator.userLanguage; 
  if (!document.all) { 
    document.cookie="log____cc=1"; 
    ls+="&co="+(document.cookie?true:false); 
  }
  else ls+="&co="+navigator.cookieEnabled; 
  if (window.innerWidth) { 
    ls+="&ww="+window.innerWidth; 
    ls+="&wh="+window.innerHeight; 
  } 
  else if (document.documentElement && document.documentElement.clientWidth) { 
    ls+="&ww="+document.documentElement.clientWidth; ls+="&wh="+document.documentElement.clientHeight; 
  } 
  else if (document.body && document.body.clientWidth) { 
    ls+="&ww="+document.body.clientWidth; 
    ls+="&wh="+document.body.clientHeight; 
  }
  np=navigator.plugins; 
  if (np) { 
    for (i=np.length-1;i>=0;--i) ls+="&p="+escape(np[i].name); 
  } 
  li=new Image(); 
  li.src=ls; 
}

/* date display */
FRdayName = new Array ("dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi", "dimanche");
ENdayName = new Array ("sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday");
	
FRmonName = new Array ("janvier", "f&eacute;vrier", "mars", "avril", "mai", "juin", "juillet", "ao&ucirc;t", "septembre", "octobre", "novembre", "d&eacute;cembre");
ENmonName = new Array ("january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december");

var now = new Date;

var yearValue = now.getYear();

if (yearValue < 2000) {
	if (yearValue > 100) {
		yearValue = 2000 - 100 + yearValue;
	}
	else {
	yearValue = 2000 + yearValue;
	}
}

/* websites page */
var currentSite = 0;
var previousSite;
var increment = 20;
var previousHeight = 380;
var nextHeight = 0;

function hideWebsites() {
	if (!document.getElementById||!document.getElementsByTagName) {return;}
	var titles = document.getElementsByTagName('h4');
	if (!titles[0].id) {
		for (var i=0; i<titles.length; i++) {
			titles[i].id = "site" + i;
			titles[i].className = "reduced";
			var titleLinks = titles[i].getElementsByTagName('a');
			for (var j=0; j<titleLinks.length; j++) {
				if (titleLinks[j].className=='site') {
					titleLinks[j].id = "siteLink"+i;
				}
				else {
					titleLinks[j].onclick=showWebsite;
				}
			}
		}
	}
	websiteNumber = currentSite; 
	previousSite = websiteNumber; 
	titles[websiteNumber].className = "";
}
function showWebsite(evnt) {
	if (!document.getElementById) {return;}
	evnt = evnt ? evnt : window.event;
	var evntTarget = (evnt.target) ? evnt.target : evnt.srcElement;
	var detectLink = evntTarget.parentNode;
	var parentTitle = detectLink.parentNode;
	var parentID = parentTitle.id.substring(4);
	parentID = eval(parentID);
	if ((previousSite>=0)&&(previousSite!=parentID)) {
		document.getElementById("siteLink" + parentID).style.height = nextHeight;
		document.getElementById("site" + parentID).className = "";
		expandWebsite(previousSite,parentID);
		currentSite = parentID;
	}
	return false;
}
function expandWebsite(previousLink,nextLink) {
	previousHeight = previousHeight - increment;
	document.getElementById("siteLink" + previousLink).style.height = previousHeight + "px";
	nextHeight = nextHeight + increment;
	document.getElementById("siteLink" + nextLink).style.height = nextHeight + "px";
	if (nextHeight < 380) {
		var func = "expandWebsite("+previousLink+","+nextLink+")";
		setTimeout(func,2);
	}
	else {
		document.getElementById("site" + previousLink).className = "reduced";
		nextHeight = 0;
		previousHeight = 380;
		previousSite = nextLink;
	}
}


