// -----------------------------------------------------------------------------------
// 
// This page coded by Scott Upton
// http://www.uptonic.com | http://www.couloir.org
//
// This work is licensed under a Creative Commons License
// Attribution-ShareAlike 2.0
// http://creativecommons.org/licenses/by-sa/2.0/
//
// Associated APIs copyright their respective owners
//
// -----------------------------------------------------------------------------------
// --- version date: 11/28/05 --------------------------------------------------------


// Define each photo's name, width, height and caption
var photoArray = new Array(
	// Source, Width, Height, Caption
new Array("fairy_tales.jpg", "350", "320", "<br>Couverture du catalogue promotionel de Three in a Box sur le th\u00E8me des contes de f\u00E9es.","<br>Cover for the promotional catalog, Three in a box, fairy tale theme."),
new Array("goldilocks.jpg", "350", "320", "<br>Boucles d'Or: image pour le catalogue promotionel de Three in a Box sur le th\u00E8me des contes de f\u00E9es.","<br>Goldilocks: inside image for the promotional catalog, Three in a box, fairy tale theme."),
new Array("hoax.jpg", "350", "320", "<br>Canular: les chiens peuvent-ils sentir avant tout le monde que leur matre est atteint d'une maladie grave?. Grand Prix LUX pice promotionelle","<br>Hoax: can dogs really detect that their master has an illness before anyone else? LUX Grand Prize promotional piece"),
new Array("savings_children.jpg", "350", "320", "<br>Comment transmettre la valeur de l'argent aux enfants, l'Actualit\u00E9.","<br>How to teach the value of money to our children, l'Actualit\u00E9."),
new Array("hospital_system.jpg", "350", "320", "<br>Le syst\u00E8me de sant\u00E9 public du Qubec: on le garde cote que cote, l'Actualit\u00E9.","<br>Public Health System in Quebec: we're keeping it going no matter what, l'Actualit\u00E9."),
new Array("alcohol.jpg", "350", "320", "<br>Article sur les effets des habitudes lies notre consommation d'alcool sur les enfants, Financial Times de Londres.","<br>The effects of our alcohol consumption on our children, Financial Times of London."),
new Array("mirror_cancer.jpg", "350", "320", "<br>Une femme raconte le jour o le m\u00E9decin lui annonce son diagnostique de cancer, et qu'elle se trouve propuls\u00E9e de l'autre ct\u00EA du mirroir, Globe and Mail.","<br>A woman tells the story of the day her doctor diagonosed  a cancer, she felt propelled to the other side of the mirror, Globe and Mail."),
new Array("mole.jpg", "350", "320", "<br>Les cliniques sp\u00E9cialis\u00E9es dans le traitement dermatologique sont-elles toutes fiables? Financial Times de Londres.","<br>Are all dermatology clinics equal? Financial Times of London."),
new Array("savings_squirrel.jpg", "350", "320", "<br>Comment viter les piges du march\u00E9 de l'\u00E9pargne, l'Actualit\u00E9.","<br>How to avoid the traps in the savings market, l'Actualit\u00E9."),
new Array("pregnancy.jpg", "350", "320", "<br>Les infirmi\u00E8res d'Angeleterre aimeraient trouver un test qui saurait d\u00E9tecter la consommation d'alcool chez la femme enceinte, Financial Times de Londres.","<br>Nurses in Great Britain would like to find a test that would detect how much pregnant woman are actually drinking, Financial Times de Londres."),
new Array("fertility.jpg", "350", "320", "<br>L'industrie pharmaceutique mise sur l'espoir des couples avec des probl\u00E8mes de fertilit\u00EA, Financial Times de Londres.","<br>Pharmaceutical industry tables on the hope of couples with fertility issues, Financial Times of London."),
new Array("virginity.jpg", "350", "320", "<br>La virginit\u00E9: arme de domination massive, Chtelaine. Prix d'Excellence: Communication Arts, Illustration West 47, 3x3 Proshow No.6,  Applied Arts.","<br>Male dominance on women's virginity, Chatelaine magazine. Excellence Awards: Communication Arts, Illustration West 47, 3x3 Proshow No.6, Applied Arts."),new Array("bird.jpg", "350", "320", "<br>Une m\u00E8re raconte le dpart du nid familial de sa fille atteinte dĠune d\u00E9ficence intellectuelle, Globe and Mail.","<br>A mom tells the story of her disabled daughter leaving home, Globe and Mail."),
new Array("prof.jpg", "350", "320", "<br>Le d\u00E9crochage chez les jeunes enseignants du syst\u00E8me public, magazine Inter.","<br>Young teachers massively leaving the profession, Inter magazine."),
new Array("fish.jpg", "350", "320", "<br>Des promesses d'assurance-vie abusive, Businessweek.","<br>Abusive life insurance promises made to the elderly, Businessweek."),
new Array("horses.jpg", "350", "320", "<br>Les cheffes d'entreprises sembleraient manquer de vision d'avenir en comparaison  leur coll\u00E8gues masculins, magazine Canadian Business,","<br>Women leaders may lack of vision if compared to their male counterparts, Canadian Business magazine."),
new Array("allaitement.jpg", "350", "320", "<br>Monte de lait contre l'allaitement, texte d'lise Gravel, Chtelaine.","<br>I hate breastfeeding, article in Chtelaine."),
new Array("infrastructure.jpg", "350", "320", "<br>L'infrastructure canadienne manque dramatiquement d'investissement, magazine Canadian Business.","<br>Canadian infrastructure in need of massive investment, Canadian Business magazine."),
new Array("videogames_men.jpg", "350", "320", "<br>Pour devenir un homme il faut s'interesser  autre chose que son look et les jeux vid\u00E9os, article sign\u00E9 Benot Dutrizac, sept 2008, magazine Chtelaine. Prix: Illustration West 47.","<br>To be a man, you have to have other interests besides your looks and videogames, Chatelaine, Sept 2008 issue. Awarded: Illustration West 47."),new Array("nurse.jpg", "350", "320", "<br>Une bonne utilisation des cinq sens permet  l'infirmire de d\u00E9passer les technologies, Registered Nurse Journal .","<br>Nurses must rely on their senses rather than depend on technology, Registered Nurse Journal."),new Array("time_9to5.jpg", "350", "320", "<br>Le 9  5 r\u00E9invent\u00E9, Report on Business, Globe and Mail.","<br>Has 9 to 5 met its' match? Report on Business, Globe and Mail."),new Array("baby_girls.jpg", "350", "320", "<br>L o il ne fait pas bon natre fille, nov 2008, Chtelaine.","<br>Not a good place to be born a girl, Chatelaine magazine, Nov 2008 issue."),new Array("tarzan.jpg", "350", "320", "<br>Un mari sauve son couple du naufrage l'ann\u00E9e o sa femme a termin\u00E9 son MBA, Globe and Mail.","<br>Husband saving his relationship the year his wife finished her MBA, Globe and Mail."),new Array("good_evil.jpg", "350", "320", "<br>Illustration pour deux articles, un sur la m\u00E9fiance g\u00E9n\u00E9rale  l'\u00E9gard de la bont\u00E9, l'autre pronant les b\u00E9n\u00E9fices de la m\u00E9chancet\u00E9 , Chtelaine, oct 2008.","<br>Illustration for two articles: one on how we tend to be suspicious of other peoples' goodness, the second stating the benefits of being mean, Chatelaine magazine, oct 2008 issue."),new Array("heart.jpg", "350", "320", "<br>Interpr\u00E9tation d'un article relatant l'\u00E9xperience d'un journaliste apr\u00E8s une chirurgie cardiaque et son soudain attachement aux traditions catholiques, Chtelaine, nov 2008.","<br>Interpretation of an article about a journalist's experience after heart surgery and his sudden attachement to his christian tradition, Chatelaine magazine, oct 2008 issue."),new Array("reading.jpg", "350", "320", "<br>Comment les jeunes lecteurs apprennent \u00E8 lire, Qu\u00E9bec Sciences.","<br>How children learn  to read, Quebec Science."),
new Array("umbrella_legal_counselling.jpg", "350", "320", "<br>Services l\u00E9gaux disponibles pour le regroupement du personel enseignant et administratif de l'Ontario, Ontario Principal Council.","<br>Legal advice services available for the administrative and teaching personel of Ontario, Ontario Principal Council."),
new Array("paradise_house.jpg", "350", "320", "<br>Question spirituelle de mon fils, the Globe and Mail, d.a. Cinders McLeod.","<br>My son's questions on paradise, the Globe and Mail, a.d. Cinders McLeod."),
new Array("valentines_angel.jpg", "350", "320", "<br>Carte pour la St-Valentin.","<br>Valentine's day card."),
new Array("green_marketing.jpg", "350", "320", "<br>Cr\u00E9dits d'impots pour les entreprises qui prennent un virage vert, Canadian Business ","<br>Tax credits for companies going green, Canadian Business."),
new Array("identity.jpg", "350", "320", "<br>Illustration pour le congrs de l'ACELF 2008: le Franais au coeur de notre identit\u00E9.","<br>Illustration for the ACELF congress 2008."),
new Array("mourning_2.jpg", "350", "320", "<br>Une femme raconte l'admiration qu'elle a pour son pre en deuil, the Globe and Mail, d.a. Cinders Mcleod.","<br>A woman writes about her admiration for her father in mourning, the Globe and Mail, a.d. Cinders Mcleod."),
new Array("mouth_doctor.jpg", "350", "320", "<br>Une seconde opinion m\u00E9dicale obligatoire, Businessweek, d.a. Laura Renga.","<br>Getting a second opinion of what ails you, Businessweek, a.d. Laura Renga."),
new Array("pinup_quebec.jpg", "350", "320", "<br>Illustration pour l'affiche de l'\u00E9vnement Ooh l l Illustration Show,  Toronto en 2008, Prix LUX 2008","<br>Illustration for the poster of the Ooh l l illustration show  held in Toronto, spring 2008, LUX prize 2008."),
new Array("jobhunting_bicycle.jpg", "350", "320", "<br>Gestion de carrire: avez-vous les outils n\u00E9c\u00E9ssaires pour faire les bons choix? ","<br>Personal carreer management: what tools do you need to make the right choices?"),
new Array("angel_urban.jpg", "350", "320", "<br>Illustration pour la couverture du recueil de po\u00E9sie de Pierre Labrie, Le vent tout autour, \u00E9ditions La Bagnole .","<br>Illustration for the cover of a poetry book by Pierre Labrie, Le vent tout autour, La Bagnole publisher."),
new Array("boxer.jpg", "350", "320", "<br>Essai sur notre rapport  la langue, magazine LĠActualit\u00E9.","<br>Essay on our relationship with the French language, LĠActualit\u00E9 magazine."),
new Array("mourning.jpg", "350", "320", "<br>Travail personel sur le deuil, Grand Prix, LUX 2008","<br>Personal work on mourning, Grand Prize, LUX 2008."),
new Array("wasp_secret.jpg", "350", "320", "<br>Le poids et les cons\u00E9quences du secret en milieu de travail.","<br>Secrets and the workplace."),
new Array("responsible_investment.jpg", "350", "320", "<br>Est-ce que votre \u00E9pargne est r\u00E9investi dans des investissements \u00E9cologiques?","<br>Are your savings invested in environmentaly friendly investments?"),
new Array("high_heel_shoe_woman_work.jpg", "350", "320", "<br>Article qui constate la lente \u00E9volution de lĠ\u00E9quit\u00E9 salariale pour les femmes sur le march\u00E9 du travail, et ce que doivent faire les femmes pour changer la donne.","<br>Article reporting the slow evolution of salary-equity for women on the marketplace, and what is in their power to change the situation.")
	);

// Number of photos in this gallery
var photoNum = photoArray.length;

// get current photo id from URL
var thisURL = document.location.href;
var splitURL = thisURL.split("#");
var photoId = splitURL[1] - 1;

// if no photoId supplied or if request out of range then set default
var photoId = (!photoId)? 0 : photoId;
var photoId = (photoId<0)? 0 : photoId;
var photoId = (photoId>photoNum-1)? 0 : photoId;



// Photo directory for this gallery
var photoDir = "portfolio/casson/";

// Icon directory for this gallery
var iconDir = "portfolio/casson/";


// Icon prefix Note that icons must be gifs
var iconPrefix = "thumb_";


var iconsHTML = "&nbsp;"

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

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

var Slideshow = Class.create();

Slideshow.prototype = {
	initialize: function(photoId) {
		this.photoId = photoId;
		this.photo = 'Photo';
		this.photoBox = 'ImageContainer';
		this.photoContainer = 'OuterContainer';
		this.linkContainer = 'LinkContainer'
		this.prevLink = 'PrevLink';
		this.nextLink = 'NextLink';
		this.captionBox = 'CaptionContainer';
		this.captionFr = 'CaptionFr';
		this.captionEng = 'CaptionEng';
		this.counter = 'Counter';
		this.loader = 'Loading';
		this.iconsBox = 'IconContainer';
		this.icons = 'Icons';
	},
	getCurrentSize: function() {
		// Get current height and width, subtracting CSS border size
		this.wCur = Element.getWidth(this.photoBox) - borderSize;
		this.hCur = Element.getHeight(this.photoBox) - borderSize;
	},
/*	getNewSize: function() {
		// Get current height and width
		this.wNew = photoArray[photoId][1];
		this.hNew = photoArray[photoId][2];
	},
	getScaleFactor: function() {
		this.getCurrentSize();
		this.getNewSize();
		// Scalars based on change from old to new
		this.xScale = (this.wNew / this.wCur) * 100;
		this.yScale = (this.hNew / this.hCur) * 100;
	},
	*/
	setNewPhotoParams: function() {
		// Set source of new image    
		
		

		Element.setSrc(this.photo,photoDir + photoArray[photoId][0]);
		// Set anchor for bookmarking
		Element.setHref(this.prevLink, "#" + (photoId+1));
		Element.setHref(this.nextLink, "#" + (photoId+1));
	},
	setPhotoCaption: function() {
		// Add caption from gallery array
		Element.setInnerHTML(this.counter,((photoId+1)+'/'+photoNum));
		Element.setInnerHTML(this.captionFr,photoArray[photoId][3]);
		Element.setInnerHTML(this.captionEng,photoArray[photoId][4]);
	},

	showPhoto: function(){
		new Effect.Fade(this.loader, {delay: 0.5, duration: 0.5});
		// Workaround for problems calling object method "afterFinish"
		new Effect.Appear(this.photo, {duration: 1.0, queue: 'end', afterFinish: function(){ new Effect.Appear('CaptionContainer', {delay: 0.0, duration: 0.5}); new Effect.Appear('LinkContainer', {delay: 0.0, duration: 0.5});}});
	},
	nextPhoto: function(){
		// Figure out which photo is next
		(photoId == (photoArray.length - 1)) ? photoId = 0 : photoId++;
		this.initSwap();
	},
	prevPhoto: function(){
		// Figure out which photo is previous
		(photoId == 0) ? photoId = photoArray.length - 1 : photoId--;
		this.initSwap();
	},	

	
	goToPhoto: function(newId){
		// Set go to photo
		
		var tempId = newId;
		var splitTempId = tempId.split("_");
		var Id = splitTempId[1] - 1;   
		if(photoId != Id){
			photoId = Id;
			this.initSwap();
		}
	},
	
	
	initSwap: function() {
		// Begin by hiding main elements
		
		Element.hide(this.photo);
		Element.show(this.loader);
		Element.hide(this.captionBox);
		Element.hide(this.linkContainer);
		// Set new dimensions and source, then resize
		this.setNewPhotoParams();
		this.setPhotoCaption();
	},
	
	initIcons: function() {
	    // 
	    
		
		for (var i = 0; i < photoNum; i++) {
			tempName = photoArray[i][0].split(".");
			iconFileName = tempName[0] + ".gif"
			iconURL = (iconDir+iconPrefix+iconFileName);
			iconsHTML = iconsHTML + "<a href='#"+(i+1)+"'><img class='iconImages' id='ic_"+(i+1)+"' src='"+(iconURL)+"' alt='icon' width='41' height='41' /></a>";
		}
		Element.setInnerHTML('icons', iconsHTML);
		
		//Calculate the total width of all the icons including borders and margins
		var totalIconWidth = (Number(Element.getStyle('ic_1', 'margin-left').replace('px',''))+Number(Element.getStyle('ic_1', 'margin-right').replace('px',''))+Number(Element.getStyle('ic_1', 'border-left-width').replace('px',''))+Number(Element.getStyle('ic_1', 'border-right-width').replace('px',''))+Number(Element.getStyle('ic_1', 'width').replace('px','')))*photoNum + 5
		Element.setWidth('icons', totalIconWidth);
		
		//Scroll to current page
		
		var iconPageNumber=Math.ceil((photoId)/9)-1
		
		if (iconPageNumber>0) {
			scrollForward('IconFrame', 'icons', '531', iconPageNumber);
		}
		
	
		
		//debug(totalIconWidth);		
	},
	
	initCaption: function() {
		Element.setWidth(this.captionBox,this.wCur-(-borderSize));
	},	
	
	
	initSwapFirst: function() {
		// Begin by hiding main elements
		Element.hide(this.photo);
		Element.show(this.loader);
		Element.hide(this.captionBox);
		//Element.setInnerHTML(this.caption,"");
		//Element.setInnerHTML(this.counter,"");
		Element.hide(this.linkContainer);
		// Set new dimensions and source, then resize
		
		this.setNewPhotoParams();
		//this.resizePhotoBox();
		//this.initCaption();
		
		//To resize icon box, activate the following line
		//Element.setWidth(this.iconsBox,this.wCur-(-borderSize));
		this.setPhotoCaption();
		this.initIcons();
		Behaviour.apply();
	}
}

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

// Establish CSS-driven events via Behaviour script
var myrules = {

	'body' :  function(el){
			Effect.Center('WindowBox');
		window.onresize = function(el){
			Effect.Center('WindowBox');
		}
	},


	'#Photo' : function(element){
		element.onload = function(){
			var myPhoto = new Slideshow(photoId);
			myPhoto.showPhoto();
		}
	},
	'#PrevLink' : function(element){
		element.onmouseover = function(){
		}
		element.onclick = function(){
			var myPhoto = new Slideshow(photoId);
			myPhoto.prevPhoto();
		}
	},
/*	'#Icons img' : function(element){
		element.onmouseover = function(){
			soundManager.play('beep');
			//Element.setOpacity(this,'1.00');
		}
		element.onclick = function(){
			var myPhoto = new Slideshow(photoId);
			myPhoto.goToPhoto(this.id);
			soundManager.play('select');
		}
		element.onmouseout = function(){
			//Element.setOpacity(this,'0.5');
		}
	},*/
	
	'#NextLink' : function(element){
		element.onmouseover = function(){
		}
		element.onclick = function(){
			var myPhoto = new Slideshow(photoId);
			myPhoto.nextPhoto();
		}
	},
	

	a : function(element){
		element.onfocus = function(){
			this.blur();
		}
	},
	
	
	//Icon Behaviors
		

	'img.MouseOver' : function(el){
		setMouseOver(el);
		element.onmouseover = function(){
			mouseGoesOver(this);
		}
		element.onclick = function(){
		}
		element.onmouseout = function(){
			mouseGoesOut(this);
		}
	},	
	'#IconFrame img': function(el){
		element.onmouseover = function(){
			Element.setStyle(this, { border: 'solid 1px orange'} );
		}
		element.onclick = function(){
			var myPhoto = new Slideshow(photoId);
			myPhoto.goToPhoto(this.id);
		}
			element.onmouseout = function(){
			Element.setStyle(this, { border: 'solid 1px white'} );
		}
	},
	
	'#icon_prev img'  : function(){
		element.onload = function(el){
		}

		element.onclick = function(el){
			scrollBack('IconFrame', 'icons', '531');
		}
	},
	'#icon_next img'  : function(){
		element.onload = function(el){
		}
		element.onclick = function(el){
			scrollForward('IconFrame', 'icons', '531', '1');
		}
	}

};


// Add window.onload event to initialize
Behaviour.addLoadEvent(init);
Behaviour.apply();
function init() {
	var myPhoto = new Slideshow(photoId);	
	myPhoto.initSwapFirst();
}