//
// CodaEffects.js - (C) 2007 Panic, Inc.
//
// Used to scroll our tabbed view.
// Requires: Effects.js
//
// Not for redistribution.

// Scroll: Setup Scrolling Stuff

var currentSection = "seminaire"; // The default loaded section on the page
var tabTag = "-tab";
var paneTag = "-pane";

// Scroll the page manually to the position of element "link", passed to us.

function ScrollSection(link, scrollArea, offset)
{

	// Store the last section, and update the current section

	if (currentSection == link) {
		return;
	}
	lastSection = currentSection;
	currentSection = link;
	
	// Change the section highlight.
	// Extract the root section name, and use that to change the background image to 'top', revealing the alt. state

    sectionTab = currentSection.split("-")[0] + tabTag;
    document.getElementById(sectionTab).className = "active";
    if (lastSection) {
	    lastTab = lastSection.split("-")[0] + tabTag;
	    document.getElementById(lastTab).className = "inactive";
	}
	
	// réinitialiser croix
	for (var i = 1; i < 7; i++) {
	    document.getElementById("cross" + i).className = "inactif";
	}
	
	// fade out
    opacity("fond", 80, 0, 650);
    document.getElementById("scroller").style.visibility = "hidden";
	
	// Title, meta, background, croix
	if(currentSection == "accueil-pane") {
	    document.title = "Devenir Prêtre? Formation Théologique - Montréal | etrepretre.com";
	    document.getElementsByTagName("meta")[1].content = "L’Institut de formation théologique de Montréal est à la recherche de personnes intéressées à s’investir dans l’Église";
	    document.getElementById("background").className = "accueil_bg";
	} else if(currentSection == "seminaire-pane") {
	    document.title = "Grand Séminaire : Formation Spirituelle, Pastorale | etrepretre.com";
	    document.getElementsByTagName("meta")[1].content = "Découvrez le processus de formation d’un projet à 4 dimensions : humaine, spirituelle, intellectuelle et pastorale";
	    document.getElementById("background").className = "seminaire_bg";
	    document.getElementById("cross1").className = "actif";
	    document.getElementById("seminaire-tab").className = "active";
	} else if(currentSection == "pretre-pane") {
	    document.title = "Formation Presbytérale et Formation des Prêtres | etrepretre.com";
	    document.getElementsByTagName("meta")[1].content = "Devenez prêtre et initiez-vous à des tâches pastorales concrètes dans le cadre de la formation spirituelle";
	    document.getElementById("background").className = "pretre_bg";
	    document.getElementById("cross2").className = "actif";
	} else if(currentSection == "tradition-pane") {
	    document.title = "Formation Intellectuelle : Philosophie, Théologie | etrepretre.com";
	    document.getElementsByTagName("meta")[1].content = "Obtenez une formation intellectuelle en philosophie, en théologie et en pastorale via l’Institut de formation théologique de Montréal";
	    document.getElementById("background").className = "tradition_bg";
	    document.getElementById("cross3").className = "actif";
	} else if(currentSection == "programmes-pane") {
	    document.title = "Programmes : Enseignement Catholique Complet | etrepretre.com";
	    document.getElementsByTagName("meta")[1].content = "Découvrez nos 3 programmes offerts à l’Institut de formation théologique de Montréal : Majeure en philosophie, Baccalauréat en théologie, Maîtrise en pastorale";
	    document.getElementById("background").className = "programmes_bg";
	    document.getElementById("cross4").className = "actif";
	} else if(currentSection == "recrutement-pane") {
	    document.title = "Admission à la formation théologique de Montréal | etrepretre.com";
	    document.getElementsByTagName("meta")[1].content = "Inscrivez vous à nos programmes de formation : Majeure en philosophie, Baccalauréat en théologie, Maîtrise en pastorale";
	    document.getElementById("background").className = "recrutement_bg";
	    document.getElementById("cross5").className = "actif";
	} else if(currentSection == "coordonnees-pane") {
	    document.title = "Coordonnées du Grand Séminaire de Montréal | etrepretre.com ";
	    document.getElementsByTagName("meta")[1].content = "Pour obtenir plus d’information, n’hésitez pas à communiquer avec le recteur du Grand Séminaire";
	    document.getElementById("background").className = "coordonnees_bg";
	    document.getElementById("cross6").className = "actif";
	}

	// Get the element we want to scroll, get the position of the element to scroll to
	
	theScroll = document.getElementById(scrollArea);
	position = findElementPos(document.getElementById(link));

	// Get the position of the offset div -- the div at the far left.
	// This is the amount we compensate for when scrolling
	
	if (offset != "") {
		offsetPos = findElementPos(document.getElementById(offset));
		position[0] = position[0] - offsetPos[0];
	}

	scrollStart(theScroll, theScroll.scrollLeft, position[0], "horiz");
	// return false;
}

//
// Animated Scroll Functions
// Scrolls are synchronous -- only one at a time.
//

var scrollanim = {time:0, begin:0, change:0.0, duration:0.0, element:null, timer:null};

function scrollStart(elem, start, end, direction)
{
	//console.log("scrollStart from "+start+" to "+end+" in direction "+direction);

	if (scrollanim.timer != null) {
		clearInterval(scrollanim.timer);
		scrollanim.timer = null;
	}
	scrollanim.time = 0;
	scrollanim.begin = start;
	scrollanim.change = end - start;
	scrollanim.duration = 40; // durée de la transition
	scrollanim.element = elem;
	
	if (direction == "horiz") {
		scrollanim.timer = setInterval("scrollHorizAnim();", 10);
	}
	else {
		scrollanim.timer = setInterval("scrollVertAnim();", 10);
	}
}

function scrollHorizAnim()
{
	if (scrollanim.time > scrollanim.duration) {
		// background transparent
	    opacity('fond', 0, 80, 650);
	    document.getElementById("scroller").style.visibility = "visible";
		clearInterval(scrollanim.timer);
		scrollanim.timer = null;
	}
	else {
		move = sineInOut(scrollanim.time, scrollanim.begin, scrollanim.change, scrollanim.duration);
		scrollanim.element.scrollLeft = move;
		scrollanim.time++;
	}
}

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}