
window.onload = function () {
	genererMenuIE();
	genererLiensExternes();
	classerHoraire("schedules");
	initGalerie();
	
	if ( document.getElementsByTagName && document.getElementById ) {
			activerMenuCourant();
		}
}




/********************************************
genererMenuIE

Ajoute une classe 'survol' à chacun des éléments LI survolés d'un menu pour Internet Explorer
*********************************************/

function genererMenuIE() {
	if ( document.all && document.getElementById ) {
		var oMenu;
		
		if ( oMenu = document.getElementById("ctl00_menu") ) {
			for ( compteurLI = 0; compteurLI < oMenu.getElementsByTagName("LI").length; compteurLI++ ) {
				eLI = oMenu.getElementsByTagName("LI")[compteurLI];
				eLI.getElementsByTagName("ul").length ? eLI.survol = "isOpenSurvol" : eLI.survol = "survol";
				
				eLI.onmouseover = function () { this.className = this.className + " " + this.survol; };            // Ajoute la classe lorsque le LI est survolé
				eLI.onmouseout = function () { this.className = this.className.replace(" " + this.survol, ""); };  // Enlève la classe lorsque le LI n'est plus survolé
			}
		}
	}
}


/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* Ouvre les liens de la page qui ne pointent pas au domaine actuel dans une nouvelle page */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
function genererLiensExternes() {
	var aAncres = document.getElementsByTagName("a");
	var eAncre;
	
	// Parcourt chacune des ancres de la page
	for ( var cAncres = 0; cAncres < aAncres.length; cAncres++ ) {
		eAncre = aAncres[cAncres];
		
		// L'URI de l'ancre ne comporte pas le domaine actuel (et n'est pas un lien de courriel), on l'ouvre donc dans une nouvelle page
		if ( eAncre.href.indexOf(document.domain) == -1 && eAncre.href.indexOf("javascript:") == -1 && eAncre.href.indexOf("mailto:") != 0 && !eAncre.onclick)
			eAncre.onclick = function () { window.open(this.href); return false; };
	}
}

// ---- Open browser window        ----
// Parameter(s):
//   - winPath    (string)
//   - winName    (string)
//   - winWidth   (int)
//   - winHeight  (int)
//   - Scrollable (int)

function OpenNewWindow(winPath, winName, winWidth, winHeight, winScrollable){
  var winLeft = (screen.width - winWidth) / 2;
  var winTop = (screen.height - winHeight ) / 2;
  var theWindow = window.open(winPath, winName, 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars='+winScrollable+',resizable=0,width='+winWidth+',height='+winHeight+',screenX='+winLeft+',screenY='+winTop+',left='+winLeft+',top='+winTop+'');
  theWindow.opener = self;
  theWindow.focus();
  return theWindow;
}

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
function activerMenuCourant () {
	var identifiant = document.URL.substring(document.URL.lastIndexOf("/") + 1, document.URL.lastIndexOf("."));
	var menu;
	var sousMenu;
	
	if ( sousMenu = document.getElementById("smn_" + identifiant) ) {
		menu = sousMenu.parentNode.parentNode;
		menu.className += " actif";
		sousMenu.className += " actif";
	} else if ( menu = document.getElementById("mn_" + identifiant) ) {
		menu.className += " actif";
	} else if ( menu = document.getElementById("ctl00_mn_" + identifiant) ) {
		menu.className += " actif";
	}
}

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* Affiche un contenu caché de la page                             */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
var contenuAffiche;
function afficherContenu ( eAncre ) {
	if ( contenuAffiche ) {
		document.getElementById("a_" + contenuAffiche).className = "";
		document.getElementById("b_" + contenuAffiche).style.display = "none";
	}
	
	var identifiant = eAncre.id.substring(eAncre.id.indexOf("_") + 1);
	contenuAffiche = identifiant;
	
	var monDisplay = "block";
	//document.all ? monDisplay = "block" : monDisplay = "table";
	
	document.getElementById("a_" + identifiant).className = "actif";
	document.getElementById("b_" + identifiant).style.display = monDisplay;
}




function initGalerie() {
	var eDiv, aIMG;
	if ( eDiv = document.getElementById("ctl00_phZone_tblImages") ) {
		aIMG = eDiv.getElementsByTagName("img");
		for ( var cImages = 0; cImages < aIMG.length; cImages++ ) {
			var img = aIMG[cImages];
			
			img.id = "g_photo_" + cImages;
			img.style.cursor = "pointer";
			img.onclick = function () {
					afficherPhoto(this);
					return false;
				};
		}
	}
}


// Affiche une photo de la galerie sens:String["h", "v"] DEFAULT "h"
function afficherPhoto( eIMG ) {
	// Dimensions photos horizontales
	var largeur_h = 520;
	var hauteur_h = 392;
	// Dimensions photos verticales
	var largeur_v = 362;
	var hauteur_v = 550;
	
	var sens = new String();
	eIMG.width > eIMG.height ? sens = "h" : sens = "v";
	
	var largeurAffiche = eval("largeur_" + sens);
	var hauteurAffiche = eval("hauteur_" + sens);
	
	var posX           = (screen.availWidth / 2) - (largeurAffiche / 2);
	var posY           = (screen.availHeight / 2) - (hauteurAffiche / 2);
	
	var uriPhoto = eIMG.src.substring(0, eIMG.src.lastIndexOf("/") + 1) + "b_" + eIMG.src.substring(eIMG.src.lastIndexOf("/") + 1);
	
	var fenetre = window.open(
							  	"../galerie.html?src=" + uriPhoto,
								"Galerie" + String(eIMG.id),
								"width=" + largeurAffiche + "," +
								"height=" + hauteurAffiche + "," +
								"left=" + posX + "," +
								"top=" + posY + "," +
								"location=no,scrollbars=no,toolbar=no,statusbar=no,resizable=no"
							);
	fenetre.focus();
}




function classerHoraire(nomClasse) {
	if ( document.getElementsByTagName ) {
		var aTables = document.getElementsByTagName("table");
		
		for (var cTables = 0; cTables < aTables.length; cTables++) {
			var eTable = aTables[cTables];
			
			if (eTable.className == nomClasse) {
				var eThead = eTable.getElementsByTagName("thead")[0];
				var aTheadTH = eThead.getElementsByTagName("th");
				
				aTheadTH[0].className = "vessel";
				aTheadTH[1].className = "voyage";
				aTheadTH[2].className = "destination";
				aTheadTH[3].className = "arrival";
				aTheadTH[4].className = "departure";
				aTheadTH[5].className = "date";
				aTheadTH[6].className = "code";
					
				
				var eTbody = eTable.getElementsByTagName("tbody")[0];
				var aTbodyTR = eTbody.getElementsByTagName("tr");
				
				for ( var cTR = 0; cTR < aTbodyTR.length; cTR++ ) {
					var eTR = aTbodyTR[cTR];
					cTR % 2 == 0 ? eTR.className = "impair" : eTR.className = "pair";
					
					var aTD = eTR.getElementsByTagName("td");
					
					aTD[0].className = "vessel";
					aTD[1].className = "voyage";
					aTD[2].className = "destination";
					aTD[3].className = "arrival";
					aTD[4].className = "departure";
					aTD[5].className = "date";
					aTD[6].className = "code";
				}
			}
		}
	}
}
