/**
 * OPACITY FADING
 */
var fadingTime = 1000;

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;
    
    if (document.getElementById) { // this is the way the standards work
        object = document.getElementById(id).style;
    }
    else 
        if (document.all) { // this is the way old msie versions work
            object = document.all[id].style;
        }
        else 
            if (document.layers) { // this is the way nn4 works
                object = document.layers[id].style;
            }
	
	if (object && object.display == "none") {
		toggleLayer(id);
	}

    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftElement(id)
{
	shiftOpacity(id,fadingTime);
}

function shiftOpacity(id, millisec){
    //if an element is invisible, make it visible, else make it visible
    if (document.getElementById(id).style.opacity == 0) {
        opacity(id, 0, 100, millisec);
    }
    else {
        opacity(id, 100, 0, millisec);
    }
}

function blendimage(divid, imageid, imagefile, millisec){
    var speed = Math.round(millisec / 100);
    var timer = 0;
    
    //set the current image as background
    document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
    
    //make image transparent
    changeOpac(0, imageid);
    
    //make new image
    document.getElementById(imageid).src = imagefile;
    
    //fade in image
    for (i = 0; i <= 100; i++) {
        setTimeout("changeOpac(" + i + ",'" + imageid + "')", (timer * speed));
        timer++;
    }
}

function currentOpac(id, opacEnd, millisec){
    //standard opacity is 100
    var currentOpac = 100;
    
    //if the element has an opacity set, get it
    if (document.getElementById(id).style.opacity < 100) {
        currentOpac = document.getElementById(id).style.opacity * 100;
    }
    
    //call for the function that changes the opacity
    opacity(id, currentOpac, opacEnd, millisec)
}

/**
 *
 * @param {Object} newSpeed
 */
function setSpeed(newSpeed){
    if (speed == newSpeed) {
        return;
    }
    
    var myImage = document.getElementById("button_" + speed);
    myImage.style.opacity = (0.5);
    myImage.style.MozOpacity = (0.5);
    myImage.style.KhtmlOpacity = (0.5);
    myImage.style.filter = "alpha(opacity=50)";
    speed = newSpeed;
    myImage = document.getElementById("button_" + speed);
    myImage.style.opacity = (1.0);
    myImage.style.MozOpacity = (1.0);
    myImage.style.KhtmlOpacity = (1.0);
    myImage.style.filter = "alpha(opacity=100)";
}

/**
 * Switching language without changing page
 * @param {lcode} language code
 */
function setLanguage(lcode){
    if (lcode == languagecode) {
        return;
    }
    
    var myElement, myFastSpeedButton, mySlowSpeedButton, myEnterButton, mySpeedHelpButton, myBanner;
	
	myElement = document.getElementById("button_" + languagecode);
    myElement.style.opacity = (0.5);
    myElement.style.MozOpacity = (0.5);
    myElement.style.KhtmlOpacity = (0.5);
    myElement.style.filter = "alpha(opacity=50)";
    
	languagecode = lcode;
    
	myElement = document.getElementById("button_" + languagecode);
    myElement.style.opacity = (1.0);
    myElement.style.MozOpacity = (1.0);
    myElement.style.KhtmlOpacity = (1.0);
    myElement.style.filter = "alpha(opacity=100)";
    
    myFastSpeedButton = document.getElementById("button_fast");
    mySlowSpeedButton = document.getElementById("button_slow");
	myEnterButton = document.getElementById("button_enter");
   	myEnterButton.src = "./images/intro-bottom_"+languagecode+".jpg";
	mySpeedHelpButton = document.getElementById("speed_help");
	myBanner = document.getElementById("intro_banner");
    
    if (languagecode == "fr") {
    	myFastSpeedButton.title = "Connexion rapide";
    	mySlowSpeedButton.title = "Connexion lente";
    	myEnterButton.title = "::: Entrer :::";
		mySpeedHelpButton.title = "Si tu as une connection Internet rapide comme Buzzz the &eacute;clair (tu comprendras plus tard) et que tu veux en prendre plein les yeux et plein les oreilles, eh bin... tu peux aller &agrave; un concert de Pink Floyd. Ah, euh... sinon tu peux choisir la version en ch&ecirc;ne massif de notre site en cliquant sur le gros p&eacute;dalier. Si tu es perdu(e) au fin fond de la Mongolie, &eacute;gar&eacute;(e) quelque part sur les Andes boliviennes, ou chez toi en France mais que ta connexion Internet est comme le 'r' &agrave; la fin de Roger, elle sert &agrave; rien, eh bin clique sur le petit p&eacute;dalier pasque on a fait une version expr&egrave;s pour toi, oh ! laiss&eacute;(e) pour compte de la technologie moderne."
		myBanner.title = "Plan&egrave;te.D est le nom donné &agrave; la vie aventureuse de Delphine Million et Damien Artero, un jeune couple dynamique et sensible, parti plus de deux ans pour un tour de la plan&egrave;te avec Buzz le tandem et Bob la remorque, et d&eacute;sormais vers&eacute; dans les p&eacute;riples cyclistes. Ces Voyageurs-Vid&eacute;astes ont d&eacute;velopp&eacute; un art de vivre sur les routes du monde...le V.V.V. = V&eacute;lo Vid&eacute;o Volontariat";
	}
    else 
        if (languagecode == "eng") {
	    	myFastSpeedButton.title = "Fast Internet";
	    	mySlowSpeedButton.title = "Slow Internet";
	    	myEnterButton.title = "::: Enter :::";
			mySpeedHelpButton.title = "If your Internet connexion is as fast as Buzzz Lightyear (you'll get that one later) and you'd fancy an amazing light and sound show, well... you can go to a Pink Floyd's concert. And err... yes you can as well clic on the big crankset for the broadband version of our website, with nice graphics. If you're lost in Outer Mongolia, wandering on the bolivian Altiplano, or home in New Zealand but your Internet connexion is as fast as an albatros carrying a coconut (african or european does not matter) well go for the small crankset 'cause we made a light version especially for you, oh! You poor wee forgotten fellow";
			myBanner.title = "Plančte.D is the name given to Delphine Million and Damien Artero’s adventure; a young, dynamic and sensitive couple, the 2 set off on a long journey around the planet with Buzz the tandem and Bob the trailer. A journey that last more than two years and through which these film -makers-on-the-move have created a way of life on the road: C.F.V. Cycling Filming Volonteering";
        }
        else 
            if (languagecode == "es") {
				myFastSpeedButton.title = "Banda ancha";
				mySlowSpeedButton.title = "Banda lenta";
		    	myEnterButton.title = "::: Entrar :::";
				mySpeedHelpButton.title = "Si tu connecci&oacute;n a Internet es tan rapida que ya se fue y si te gustar&iacute;a de ver a un show tremendo, bueno... puedes ir a un concerto de Pink Floyd. Si no err... tambien puedes venir sobre nuestro sito web, que esta muy lindo con fotograf&iacute;as, pel&iacute;culas y todo. Si estas perdida/perdido en Mongolia, o si estas caminando en Bolivia, ooooo... si estas en tu casa en Espa&ntilde;a pero tu computadora no esta de la nueva generaci&oacute;n y Internet anda mas lentamente que nosotros sobre la bici doble en la Cordillera de Lipez (quasi imposible pero... nunca se sabe) entonces ser&iacute;a mejor para ti usar el sito para banda lenta que hemos hecho specialmente para ti (de nada...)";
				myBanner.title = "Plan&egrave;te.D es el nombre dado a las aventuras de Delphine Million y Damien Artero, una pareja joven y din&aacute;mica, sensible, que ha dado la vuelta al mundo por m&aacute;s de dos a&ntilde;os; una gira por el planeta con Buzz el tandem y Bob el carito. Estos viajeros han desarrollado una forma de vida en las carreteras del mundo...el V.V.V. = Velo V&iacute;deo Volontariado";
            }
            else 
                if (languagecode == "de") {
					myFastSpeedButton.title = "Schnelle Internetverbindungen";
					mySlowSpeedButton.title = "Langsame Internetverbindungen";
			    	myEnterButton.title = "::: Eintreten :::";
					mySpeedHelpButton.title = "Solltest Du eine Internet-verbindung mit der Geschwindigkeit von Buzzz Lightyear haben und wilde sowie unglaubliche Licht und Musikshows w&uuml;nschen... errrr dann geh' zu einem Pink Floyd Konzert. Oder, tja, do kannst weiter zur schnelle Version unserer Webseite gehen, &uuml;berf&uuml;llt mit Bildern, Videos, Audio und einfach Alles. Solltest Du Dich in Mongolien verlaufen haben, oder Du wanderst in Altiplano, Bolivien, oder ob Du zu Hause in Neu Seeland bist mit einer Internetverbindung so schnell wie ein Albatross, der eine Kokusnuss tr&auml;gt (ein afrikanischer oder europ&auml;ischer ist egal) also geh einfach auf unsere langsame Seite weil wir haben auch eine 'light' Version gemacht f&uuml;r Dich, armer Internetasket.";
					myBanner.title = "Plan&egrave;te.D ist die Name, einer Abenteuer:  Delphine Million und Damien Artero, eine junge, dynamische und sensiblen Ehepaar, die rund um die Welt gefahren ist, um den Planeten zu entdecken, mit ihrem Tandem Buzz. Eine Reise, die l&auml;nger als zwei Jahre gedauert hat Diese Reisen und Videok&uuml;nstler haben ein Kunst des Lebens auf den Straßen der Welt entwickelt: R.F.F. = Radfahren Filmen Freiwilligarbeiten";
                }
}

/**
 *
 */
function setUpPage(){
    setUpLanguage();
    setUpSpeed();
}

/**
 *
 */
function setUpLanguage(){
    if (languagecode) {
    }
    else {
        languagecode = "fr";
    }
}

function setUpSpeed(){
    if (speed) {
    }
    else {
        speed = "fast";
    }
    
}

/**
 * Make an element visible - fade
 * @param {Object} id
 */
function switchElementOn(id){

    if (isOn(id)) {
        return;
    }
    
    opacity(id, 0, 100, fadingTime);
}

function isOn(objectId){
    var myObject = document.getElementById(objectId);
    
    if ((myObject.style.opacity && myObject.style.opacity != 0.0) ||
    (myObject.style.MozOpacity && myObject.style.MozOpacity != 0.0) ||
    (myObject.style.KhtmlOpacity && myObject.style.KhtmlOpacity != 0.0) ||
    (myObject.style.filter && myObject.style.filter != "alpha(opacity=0)")) 
        return true;
    else 
        return false;
    
}

/**
 *
 * @param {Object} id
 */
function switchElementOff(id){
    opacity(id, 100, 0, fadingTime);
}

/**
 * Make an element visible - no fade
 * @param {Object} whichLayer
 */
function toggleLayer(whichLayer){

    var elem, vis;
    if (document.getElementById) { // this is the way the standards work
        elem = document.getElementById(whichLayer);
    }
    else 
        if (document.all) { // this is the way old msie versions work
            elem = document.all[whichLayer];
        }
        else 
            if (document.layers) { // this is the way nn4 works
                elem = document.layers[whichLayer];
            }
    vis = elem.style;
    // if the style.display value is blank we try to figure it out here
    if (vis.display == "" && elem.offsetWidth != undefined && elem.offsetHeight != undefined) 
        vis.display = (elem.offsetWidth != 0 && elem.offsetHeight != 0) ? "block" : 'none';
    vis.display = (vis.display == "" || vis.display == "block") ? "none" : "block";
}

function goTo(page) {
	var url = page+".html?lang="+languagecode+"&speed="+speed;
	window.location = url;
	
}

function displayDocument(url, containerId) {
	
    var elem;
	
    if (document.getElementById) { // this is the way the standards work
        elem = document.getElementById(containerId);
    }
    else 
        if (document.all) { // this is the way old msie versions work
            elem = document.all[containerId];
        }
        else 
            if (document.layers) { // this is the way nn4 works
                elem = document.layers[containerId];
            }
			
    elem.src = url;
}

/**
 * Defines nominal height according to screen resolution
 */
function getImageNominalResolution(f){
	
	var factor = 1;
	
	if (f) {
		factor = f;	
	}
	
    if (screen.width >= 1280 && screen.height >= 768) {
		return " width=\""+(factor*1200)+"\" height=\""+(factor*600)+"\" ";
    }
    else 
        if (screen.width == 1024 && screen.height == 768) {
			return " width=\""+(factor*1200)+"\" height=\""+(factor*600)+"\" ";
        }
        else 
            if (screen.width <= 800 && screen.height <= 600) {
				return " width=\""+(factor*750)+"\" height=\""+(factor*468)+"\" ";
            }
}

/**
 * Defines nominal height according to screen resolution
 */
function getButtonNominalResolution(f){
	
	var factor = 1;
	
	if (f) {
		factor = f;	
	}
	
    if (screen.width >= 1280 && screen.height >= 768) {
		return " width=\""+(factor*30)+"\" height=\""+(factor*30)+"\" ";
    }
    else 
        if (screen.width == 1024 && screen.height == 768) {
			return " width=\""+(factor*30)+"\" height=\""+(factor*30)+"\" ";
        }
        else 
            if (screen.width <= 800 && screen.height <= 600) {
				return " width=\""+(factor*15)+"\" height=\""+(factor*15)+"\" ";
            }
}

