slideShowURL = 'SlideShow_assets/SlideShow.html';       // parameter from openSlideShowWindow.js
slideShowNS4URL = 'SlideShow_assets/SlideShowNS4.html'; // parameter from openSlideShowWindow.js

slides = new Array();
slides[0] = new Slide('../north1_files/P1040985.jpg', '800', '600', 'Auckland');
slides[1] = new Slide('../north1_files/P1050063.jpg', '597', '801', 'halte au mont Manganui...');
slides[2] = new Slide('../north1_files/P1050064.jpg', '600', '800', 'pas prevue au programme!');
slides[3] = new Slide('../north1_files/P1050067.jpg', '800', '600', 'notre palace!');
slides[4] = new Slide('../north1_files/P1050083.jpg', '594', '800', '');
slides[5] = new Slide('../north1_files/P1050092.jpg', '588', '800', '');
slides[6] = new Slide('../north1_files/P1050106.jpg', '600', '800', '');
slides[7] = new Slide('../north1_files/P1050110.jpg', '598', '800', '');
slides[8] = new Slide('../north1_files/P1050125.jpg', '592', '800', '');
slides[9] = new Slide('../north1_files/P1050128.jpg', '600', '800', '');
slides[10] = new Slide('../north1_files/P1050148.jpg', '600', '800', '');
slides[11] = new Slide('../north1_files/P1050157.jpg', '450', '800', 'la region des hobbits');
slides[12] = new Slide('../north1_files/P1050162.jpg', '529', '800', '');
slides[13] = new Slide('../north1_files/P1050179.jpg', '534', '800', '');
slides[14] = new Slide('../north1_files/P1050180.jpg', '800', '534', '');
slides[15] = new Slide('../north1_files/P1050195.jpg', '534', '800', 'village Maori');
slides[16] = new Slide('../north1_files/P1050199.jpg', '800', '534', '');
slides[17] = new Slide('../north1_files/P1050203.jpg', '534', '800', '');
slides[18] = new Slide('../north1_files/P1050208.jpg', '534', '800', 'des signes noirs comme a Sydney');
slides[19] = new Slide('../north1_files/P1050211.jpg', '800', '534', '');
slides[20] = new Slide('../north1_files/P1050216.jpg', '800', '534', '');
slides[21] = new Slide('../north1_files/P1050217.jpg', '534', '800', '');
slides[22] = new Slide('../north1_files/P1050221.jpg', '800', '534', '');
slides[23] = new Slide('../north1_files/P1050223.jpg', '800', '534', '');
slides[24] = new Slide('../north1_files/P1050224.jpg', '800', '534', '');
slides[25] = new Slide('../north1_files/P1050225.jpg', '800', '534', 'Hells Gate :(');
slides[26] = new Slide('../north1_files/P1050231.jpg', '534', '800', '');
slides[27] = new Slide('../north1_files/P1050240.jpg', '534', '800', 'l’eau du riz :)');
slides[28] = new Slide('../north1_files/P1050249.jpg', '534', '800', '');
slides[29] = new Slide('../north1_files/P1050256.jpg', '800', '534', '');
slides[30] = new Slide('../north1_files/P1050259.jpg', '534', '800', '');
slides[31] = new Slide('../north1_files/P1050261.jpg', '534', '800', '');
slides[32] = new Slide('../north1_files/P1050262.jpg', '534', '800', '');
slides[33] = new Slide('../north1_files/P1050268.jpg', '800', '534', '');
slides[34] = new Slide('../north1_files/P1050272.jpg', '534', '800', '');
slides[35] = new Slide('../north1_files/P1050281.jpg', '534', '800', '');
slides[36] = new Slide('../north1_files/P1050288.jpg', '534', '800', '');
slides[37] = new Slide('../north1_files/P1050296.jpg', '800', '534', 'comment flinguer un short en 8 secondes :(');
slides[38] = new Slide('../north1_files/P1050301.jpg', '534', '800', '');
slides[39] = new Slide('../north1_files/P1050305.jpg', '534', '800', 'comment flinguer ses bijoux en 8 secondes :(');
slides[40] = new Slide('../north1_files/P1050322.jpg', '534', '800', '');
slides[41] = new Slide('../north1_files/P1050336.jpg', '450', '800', 'le lac Taupo');
slides[42] = new Slide('../north1_files/P1050347.jpg', '600', '800', '');
slides[43] = new Slide('../north1_files/P1050348.jpg', '600', '800', '');
slides[44] = new Slide('../north1_files/P1050352.jpg', '800', '600', '');
slides[45] = new Slide('../north1_files/P1050366.jpg', '590', '800', '');
slides[46] = new Slide('../north1_files/P1050368.jpg', '600', '800', '');
slides[47] = new Slide('../north1_files/P1050370.jpg', '800', '600', 'plan du trek');
slides[48] = new Slide('../north1_files/P1050371.jpg', '600', '800', 'avec l’altitude');
slides[49] = new Slide('../north1_files/P1050372.jpg', '600', '800', '');
slides[50] = new Slide('../north1_files/P1050373.jpg', '600', '800', '');
slides[51] = new Slide('../north1_files/P1050377.jpg', '600', '800', 'pinaise ca grimpe!');
slides[52] = new Slide('../north1_files/P1050402.jpg', '600', '800', '');
slides[53] = new Slide('../north1_files/P1050410.jpg', '600', '800', '');
slides[54] = new Slide('../north1_files/P1050411.jpg', '600', '800', '');
slides[55] = new Slide('../north1_files/P1050412.jpg', '600', '800', '');
slides[56] = new Slide('../north1_files/P1050416.jpg', '800', '600', 'ca grimpe de plus en plus');
slides[57] = new Slide('../north1_files/P1050420.jpg', '600', '800', '');
slides[58] = new Slide('../north1_files/P1050421.jpg', '600', '800', '');
slides[59] = new Slide('../north1_files/P1050422.jpg', '600', '800', '');
slides[60] = new Slide('../north1_files/P1050428.jpg', '600', '800', 'passage au decu des nuages');
slides[61] = new Slide('../north1_files/P1050433.jpg', '600', '800', '');
slides[62] = new Slide('../north1_files/P1050438.jpg', '600', '800', '');
slides[63] = new Slide('../north1_files/P1050449.jpg', '800', '600', '');
slides[64] = new Slide('../north1_files/P1050457.jpg', '600', '800', 'la cachette du mechant dans bioman c’est la!');
slides[65] = new Slide('../north1_files/P1050460.jpg', '600', '800', '');
slides[66] = new Slide('../north1_files/P1050461.jpg', '800', '600', '');
slides[67] = new Slide('../north1_files/P1050463.jpg', '600', '800', '');
slides[68] = new Slide('../north1_files/P1050468.jpg', '600', '800', '');
slides[69] = new Slide('../north1_files/P1050469.jpg', '600', '800', '');
slides[70] = new Slide('../north1_files/P1050478.jpg', '800', '600', '');
slides[71] = new Slide('../north1_files/P1050481.jpg', '600', '800', '');
slides[72] = new Slide('../north1_files/P1050482.jpg', '600', '800', '');
slides[73] = new Slide('../north1_files/P1050486.jpg', '600', '800', '');
slides[74] = new Slide('../north1_files/P1050491.jpg', '600', '800', '');
slides[75] = new Slide('../north1_files/P1050497.jpg', '800', '600', '');
slides[76] = new Slide('../north1_files/P1050502.jpg', '600', '800', 'the Red Crater');
slides[77] = new Slide('../north1_files/P1050506.jpg', '600', '800', 'force rose!');
slides[78] = new Slide('../north1_files/P1050508.jpg', '600', '800', '');
slides[79] = new Slide('../north1_files/P1050509.jpg', '600', '800', '');
slides[80] = new Slide('../north1_files/P1050518.jpg', '800', '600', '');
slides[81] = new Slide('../north1_files/P1050525.jpg', '600', '800', '');
slides[82] = new Slide('../north1_files/P1050539.jpg', '800', '600', 'apres la montée, la descente');
slides[83] = new Slide('../north1_files/P1050550.jpg', '600', '800', '');
slides[84] = new Slide('../north1_files/P1050559.jpg', '600', '800', 'les lacs d’emeraude');
slides[85] = new Slide('../north1_files/P1050574.jpg', '600', '800', '');
slides[86] = new Slide('../north1_files/P1050575.jpg', '600', '800', '');
slides[87] = new Slide('../north1_files/P1050579.jpg', '600', '800', '');
slides[88] = new Slide('../north1_files/P1050587.jpg', '600', '800', 'hyper profond');
slides[89] = new Slide('../north1_files/P1050596.jpg', '600', '800', '');
slides[90] = new Slide('../north1_files/P1050606.jpg', '600', '800', 'la hute de haute montagne');
slides[91] = new Slide('../north1_files/P1050609.jpg', '600', '800', '');
slides[92] = new Slide('../north1_files/P1050617.jpg', '800', '600', '');
slides[93] = new Slide('../north1_files/P1050624.jpg', '600', '800', '');
slides[94] = new Slide('../north1_files/P1050627.jpg', '600', '800', 'sur le toit de notre backpackers');
slides[95] = new Slide('../north1_files/P1050632.jpg', '800', '600', '...');
slides[96] = new Slide('../north1_files/P1050634.jpg', '600', '800', 'vue sur Wellinngton');
slides[97] = new Slide('../north1_files/P1050641.jpg', '800', '600', '');
slides[98] = new Slide('../north1_files/P1050642.jpg', '592', '800', '');
isPureISOLatin1 = true;
contentEncodingConstant = 4;
feedbackURL = "TODO";
showFeedbackButton = false;
feedbackEnabled = true;

var MINIMUM_FONT = "10";
var UNITS = "";

function elementFontSize(element)
{
    var fontSize = MINIMUM_FONT; 

    if (document.defaultView)
    {
        var computedStyle = document.defaultView.getComputedStyle(element, null);
        if (computedStyle)
        {
            fontSize = computedStyle.getPropertyValue("font-size");
        }
    }
    else if (element.currentStyle)
    {
        fontSize = element.currentStyle.fontSize;
    }

    if ((UNITS.length == 0) && (fontSize != MINIMUM_FONT))
    {
        UNITS = fontSize.substring(fontSize.length - 2, fontSize.length)
    }

    return parseFloat(fontSize);
}

function adjustFontSizeIfTooBig(idOfElement)
{
    var oTextBoxOuterDiv;
    var oTextBoxMiddleDiv;
    var oTextBoxInnerDiv;
    var oTextBoxOuterDiv = document.getElementById(idOfElement);
    
    if (oTextBoxOuterDiv)
    {
        oTextBoxMiddleDiv = getChildOfType(oTextBoxOuterDiv, "DIV", 0);
        if (oTextBoxMiddleDiv)
        {
            oTextBoxInnerDiv = getChildOfType(oTextBoxMiddleDiv, "DIV", 0);
            if (oTextBoxInnerDiv)
            {
                var offsetHeight = oTextBoxInnerDiv.offsetHeight;
                var specifiedHeight = offsetHeight;
                if (oTextBoxMiddleDiv.style.height != "")
                {
                    specifiedHeight = parseFloat(oTextBoxMiddleDiv.style.height);
                }
                else if (oTextBoxOuterDiv.style.height != "")
                {
                    specifiedHeight = parseFloat(oTextBoxOuterDiv.style.height);
                }
                if (offsetHeight > specifiedHeight)
                {
                    var smallestFontSize = 200;
                    
                    var aParaChildren = getParaDescendants(oTextBoxInnerDiv);
                    var oneLine = false;
                    for (i = 0; i < aParaChildren.length; i++)
                    {
                        var oParagraphDiv = aParaChildren[i];
                        var lineHeight = elementLineHeight(oParagraphDiv);
                        oneLine = oneLine || (lineHeight * 1.5 >= specifiedHeight);
                        if (oParagraphDiv.nodeName == "DIV")
                        {
                            var fontSize = elementFontSize(oParagraphDiv);
                            smallestFontSize = Math.min( smallestFontSize, fontSize );
                            for (j = 0; j < oParagraphDiv.childNodes.length; j++)
                            {
                                var oSpan = oParagraphDiv.childNodes[j];
                                if ((oSpan.nodeName == "SPAN") || (oSpan.nodeName == "A"))
                                {
                                    fontSize = elementFontSize(oSpan);
                                    smallestFontSize = Math.min( smallestFontSize, fontSize );
                                }
                            }
                        }
                    }
                    var minimum = parseFloat(MINIMUM_FONT);
                    
                    var count = 0
                    while ((smallestFontSize > minimum) && (offsetHeight > specifiedHeight) && (count < 10))
                    {
                        ++ count;
                        if (oneLine)
                        {
                            var oldWidth = parseInt(oTextBoxOuterDiv.style.width);
                            oTextBoxInnerDiv.style.width =
                                "" + oldWidth * Math.pow(1.05, count) + "px";
                        }
                        else
                        {
                            var scale = Math.max(0.95, minimum / smallestFontSize);
                            
                            for (i = 0; i < aParaChildren.length; i++)
                            {
                                var oParagraphDiv = aParaChildren[i];
                                if (oParagraphDiv.nodeName == "DIV")
                                {
                                    var paraFontSize = elementFontSize(oParagraphDiv) * scale;
                                    var paraLineHeight = elementLineHeight(oParagraphDiv) * scale;
                                    for (j = 0; j < oParagraphDiv.childNodes.length; j++)
                                    {
                                        var oSpan = oParagraphDiv.childNodes[j];
                                        if ((oSpan.nodeName == "SPAN") || (oSpan.nodeName == "A"))
                                        {
                                            var spanFontSize = elementFontSize(oSpan) * scale;
                                            var spanLineHeight = elementLineHeight(oSpan) * scale;
                                            oSpan.style.fontSize = spanFontSize + UNITS;
                                            oSpan.style.lineHeight = spanLineHeight + UNITS;
                                            smallestFontSize = Math.min( smallestFontSize, spanFontSize );
                                        }
                                    }
                                    oParagraphDiv.style.fontSize = paraFontSize + UNITS;
                                    oParagraphDiv.style.lineHeight = paraLineHeight + UNITS;
                                    smallestFontSize = Math.min( smallestFontSize, paraFontSize );
                                }
                            }
                        }
                        
                        offsetHeight = oTextBoxInnerDiv.offsetHeight;
                    }
                }
            }
        }
    }
}


function elementLineHeight(element)
{
    var lineHeight = MINIMUM_FONT; 
    
    if (document.defaultView)
    {
        var computedStyle = document.defaultView.getComputedStyle(element, null);
        if (computedStyle)
        {
            lineHeight = computedStyle.getPropertyValue("line-height");
        }
    }
    else if (element.currentStyle)
    {
        lineHeight = element.currentStyle.lineHeight;
    }
    
    if ((UNITS.length == 0) && (lineHeight != MINIMUM_FONT))
    {
        UNITS = lineHeight.substring(lineHeight.length - 2, lineHeight.length)
    }
    
    return parseFloat(lineHeight);
}

function adjustLineHeightIfTooBig(idOfElement)
{
    var oTextBoxOuterDiv;
    var oTextBoxMiddleDiv;
    var oTextBoxInnerDiv;
    var oTextBoxOuterDiv = document.getElementById(idOfElement);
    
    if (oTextBoxOuterDiv)
    {
        oTextBoxMiddleDiv = getChildOfType(oTextBoxOuterDiv, "DIV", 0);
        if (oTextBoxMiddleDiv)
        {
            oTextBoxInnerDiv = getChildOfType(oTextBoxMiddleDiv, "DIV", 0);
            if (oTextBoxInnerDiv)
            {
                var offsetHeight = oTextBoxInnerDiv.offsetHeight;
                var specifiedHeight = offsetHeight;
                if (oTextBoxMiddleDiv.style.height != "")
                {
                    specifiedHeight = parseFloat(oTextBoxMiddleDiv.style.height);
                }
                else if (oTextBoxOuterDiv.style.height != "")
                {
                    specifiedHeight = parseFloat(oTextBoxOuterDiv.style.height);
                }
                if (offsetHeight > specifiedHeight)
                {
                    var adjusted = true;
                    var count = 0;
                    while ((adjusted) && (offsetHeight > specifiedHeight) && (count < 10))
                    {
                        adjusted = false;
                        ++ count;
                        
                        var aParaChildren = getParaDescendants(oTextBoxInnerDiv);
                        for (i = 0; i < aParaChildren.length; i++)
                        {
                            var oParagraphDiv = aParaChildren[i];
                            if (oParagraphDiv.nodeName == "DIV")
                            {
                                var fontSize = elementFontSize(oParagraphDiv);
                                var lineHeight = elementLineHeight(oParagraphDiv) * 0.95;
                                if (lineHeight >= (fontSize * 1.1))
                                {
                                    oParagraphDiv.style.lineHeight = lineHeight + UNITS;
                                    adjusted = true;
                                }
                                
                                
                                
                                for (j = 0; j < oParagraphDiv.childNodes.length; j++)
                                {
                                    var oSpan = oParagraphDiv.childNodes[j];
                                    if ((oSpan.nodeName == "SPAN") || (oSpan.nodeName == "A"))
                                    {
                                        var fontSize = elementFontSize(oSpan);
                                        var lineHeight = elementLineHeight(oSpan) * 0.95;
                                        if (lineHeight >= (fontSize * 1.1))
                                        {
                                            oSpan.style.lineHeight = lineHeight + UNITS;
                                            var adjusted = true;
                                        }
                                    }
                                }
                            }
                        }
                        
                        offsetHeight = oTextBoxInnerDiv.offsetHeight;
                    }
                }
            }
        }
    }
}

var windowsInternetExplorer = false;
var browserVersion = 0;
function detectBrowser()
{
    windowsInternetExplorer = false;
    var appVersion = navigator.appVersion;
    if ((appVersion.indexOf("MSIE") != -1) &&
        (appVersion.indexOf("Macintosh") == -1))
    {
        var temp = appVersion.split("MSIE");
        browserVersion = parseFloat(temp[1]);
        windowsInternetExplorer = true;
    }
}

function getChildOfType(oParent, sNodeName, requestedIndex)
{
    var childrenOfType = oParent.getElementsByTagName(sNodeName);
    return (requestedIndex < childrenOfType.length) ?
           childrenOfType.item(requestedIndex) : null;
}

function getParaDescendants(oAncestor)
{
    var oParaDescendants = new Array();
    var oPotentialParagraphs = oAncestor.getElementsByTagName('DIV');
    for (var iIndex=0; iIndex<oPotentialParagraphs.length; iIndex++)
    {
        var oNode = oPotentialParagraphs.item(iIndex);
        if (oNode.className.lastIndexOf('paragraph') != -1)
        {
            oParaDescendants.push(oNode);
        }
    }
    return oParaDescendants;
}

function onPageLoad()
{
    detectBrowser();
    adjustLineHeightIfTooBig("id1");
    adjustFontSizeIfTooBig("id1");
    return true;
}

