/* ---------------------------------------------------------------------------*/
/* Author: Myriam Beauchemin                                                  */
/* Revision Date: Aug, 11 Thu 2005 00:00:00 EDT                               */
/* ---------------------------------------------------------------------------*/

var sensHoriz = "h";
var sensVert = "v";

var minDim = 320;
var maxDim = 400; 
var bandeNoire = 60;

var winLien = null;
var winUrl = "";
var winTarget = "winPopup";
var winPopup = null;

var previousWidth = 0;
var previousHeight = 0;

var trans = 1;
var mouvement = 1;
var objet = null;

var timer1 = null;
var timer2 = null;
var timer3 = null;

/* ---------------------------------------------------------------------------*/

function ouvrirLien(adresse) {
	var winHeight = 500;
	var winWidth = 788;

	var winTop = 0;
	var winLeft = 0;

	var winUrl = "http://" + adresse;
	var winTarget = "winLien";
	var winSettings = null;

	// Ouverture de la nouvelle fenêtre de navigation:
	winSettings = "height=" + winHeight + ",width=" + winWidth + ",top=" + winTop + ",left=" + winLeft + ",resizable=yes" + ",scrollbars=yes" + ",toolbar=yes" + ",location=yes" + ",directories=no" + ",status=yes" + ",menubar=yes" + ",dependent=no";
	winLien = window.open(winUrl, winTarget, winSettings);
}

/* ---------------------------------------------------------------------------*/

function ouvrirImage(source,titre,sens) {
	var sou = "Images/" + source + ".gif";
	var ttr = titre;
	var sns = sens;
	ouvrirPopup(sou,ttr,sns);
}


function ouvrirPhoto(source,titre,sens) {
	var sou = "Photos/" + source + ".jpg";
	var ttr = titre;
	var sns = sens;
	ouvrirPopup(sou,ttr,sns);
}


function ouvrirPopup(source,titre,sens) {
	var winWidth;
	var winHeight;

	// Déterminer la taille de la fenêtre selon l'orientation
	if (sens == sensHoriz) { 
		winWidth = maxDim;
		winHeight = minDim + bandeNoire;
	}
	else if (sens == sensVert) {
		winWidth = minDim;
		winHeight = maxDim + bandeNoire;
	}
	else {
		winWidth = maxDim;
		winHeight = maxDim + bandeNoire;
	}

	if ((winPopup == null) || (winPopup.closed)) {
	// Déterminer les coordonnées pour centrer la fenêtre sur l'écran:
		var winTop = (screen.availHeight - winHeight) / 2;
		var winLeft = (screen.availWidth - winWidth) / 2;

		// Ouverture de la fenêtre
		var winSettings = "height=" + winHeight + ",width=" + winWidth + ",top=" + winTop + ",left=" + winLeft + ",resizable=no" + ",scrollbars=no" + ",toolbar=no" + ",location=no" + ",directories=no" + ",status=no" + ",menubar=no";
		winPopup = window.open(winUrl, winTarget, winSettings);
	}
	else {
	// Réutilisation de la fenêtre
		var deltaX = winWidth - previousWidth;
		var deltaY = winHeight - previousHeight;
		winPopup.resizeBy(deltaX, deltaY);
	}

	// Fichier HTML source de la fenêtre
	winPopup.document.writeln('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"');
	winPopup.document.writeln('		"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">');
	winPopup.document.writeln('');
	winPopup.document.writeln('<html>');
	winPopup.document.writeln('');
	winPopup.document.writeln('<head>');
	winPopup.document.writeln('<title>' + titre + '</title>');
	winPopup.document.writeln('<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />');
	winPopup.document.writeln('<meta name="author" lang="fr" content="Myriam Beauchemin" />');
	winPopup.document.writeln('<meta name="description" lang="fr" content="Image ou photo aggrandie." />');
	winPopup.document.writeln('<meta name="revised" content="Fri, 23 Jul 2004 00:00:00 EDT" />');
	winPopup.document.writeln('<style type="text/css">');
	winPopup.document.writeln('	body { background: #000000; color: #99cccc; margin: 0; text-align: center; }');
	winPopup.document.writeln('	button { background: #000000; border-color: #666666; cursor: pointer; margin-top: 14px; padding-bottom: 1px; padding-top: 3px; width: 120px; }');
	winPopup.document.writeln('	img { border: 0; }');
	winPopup.document.writeln('</style>');
	winPopup.document.writeln('</head>');
	winPopup.document.writeln('');
	winPopup.document.writeln('<body>');
	winPopup.document.writeln('<div>');
	winPopup.document.writeln('<img src="' + source + '" alt="' + titre + '" /><br>');
	winPopup.document.writeln('<button onclick="self.close()"><img src="Images/fermer.gif" alt="Fermeture" /></button>');
	winPopup.document.writeln('</div>');
	winPopup.document.writeln('</body>');
	winPopup.document.writeln('');
	winPopup.document.writeln('</html>');
	winPopup.document.close();

	winPopup.focus();

	// Sauvegarde des dimensions pour ajustement futur de la
	// fenêtre lorsque réutilisée pour une nouvelle image/photo:
	previousWidth = winWidth;
	previousHeight = winHeight;
}


function fermerPopup() {
	if ((winPopup != null) && (winPopup.location)) {
		winPopup.close();
	}
}

/* ---------------------------------------------------------------------------*/

function defiler(divId,add) {
	var layer = document.getElementById(divId);
	var layerLeft = layer.style.pixelLeft;
	var largeur = 620 - layer.clientWidth;

	if (add > 0) {
 	// De gauche à droite
		if (layerLeft < (largeur - add)) {
			layer.style.pixelLeft = layerLeft + add;
			i = divId;
			a = add;
			timer1 = setTimeout('defiler(i,a)',100);
		}
		else {
			clearTimeout(timer1);
			clearTimeout(timer2);
		}
	}
	else if (add < 0 ) {
	// De droite à gauche
	}
}


function shakeUp(divId) {
	document.getElementById(divId).style.top = 0;
	i = divId;
	timer2 = setTimeout('shakeDown(i)',1000);
}


function shakeDown(divId) {
	document.getElementById(divId).style.top = 3;
	i = divId;
	timer2 = setTimeout('shakeUp(i)',200);
}

/* ---------------------------------------------------------------------------*/



function initTrembler(obj) {
	mouvement = 1;
	obj.style.left = 0;
	obj.style.top = 0;
	objet = obj;
	trembler();
}


function trembler() {
	if (mouvement == 1) {
		objet.style.left = parseInt(objet.style.left) - trans;
	}
	else if (mouvement == 3) {
		objet.style.left = parseInt(objet.style.left) + trans;
	}
	else {
		objet.style.top = 0;
		objet.style.left = 0;
	}

	if (mouvement < 4) {
		mouvement++;
	}
	else {
		mouvement = 1;
	}
	
	timer3 = setTimeout('trembler()',25);
}


function stopTrembler(obj) {
	obj.style.left = 0;
	obj.style.top = 0;
	clearTimeout(timer3);
}

/* ---------------------------------------------------------------------------*/

function allContent(obj) {
	alert('DEBUG: allContent((' + typeof(obj) + ') ' + obj + ')');

	if (typeof(obj) == 'undefined') {
		return;
	}

	var count = 0;
	var content = '';

	for (var el in obj) {
		if (el == "fullScreen") continue;

		if (typeof(obj[el]) != 'function') {
			count++;
			content += 'obj["' + el + '"] = "' + obj[el] + '".' + "\n";

			if ((count % 15) == 0) {
				alert("DEBUG:\n" + content);
				count = 1;
				content = '';
			}
		}
	}

	if (content.length != 0) {
		alert("DEBUG:\n" + content);
	}
}

