IMpreload('ApeMania_files', 'shapeimage_3', '0');
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('../ApeMania_files/DSC_0086.jpg', '532', '800', 'Waiting in the chair');
slides[1] = new Slide('../ApeMania_files/DSC_0087.jpg', '532', '800', 'Brian Penikas at work');
slides[2] = new Slide('../ApeMania_files/DSC_0088.jpg', '532', '800', 'waiting for paint to dry');
slides[3] = new Slide('../ApeMania_files/DSC_0089.jpg', '532', '800', 'teeth blackened');
slides[4] = new Slide('../ApeMania_files/DSC_0090.jpg', '532', '800', 'lips blackened');
slides[5] = new Slide('../ApeMania_files/DSC_0091.jpg', '532', '800', 'smoothing edges');
slides[6] = new Slide('../ApeMania_files/DSC_0092.jpg', '532', '800', 'lower jaw');
slides[7] = new Slide('../ApeMania_files/DSC_0093.jpg', '532', '800', 'powder');
slides[8] = new Slide('../ApeMania_files/DSC_0094.jpg', '532', '800', 'chimp on the way');
slides[9] = new Slide('../ApeMania_files/DSC_0096.jpg', '532', '800', 'Duke almost done');
slides[10] = new Slide('../ApeMania_files/DSC_0098.jpg', '532', '800', 'not a monchichi');
slides[11] = new Slide('../ApeMania_files/DSC_0099.jpg', '532', '800', 'on to the next one');
slides[12] = new Slide('../ApeMania_files/DSC_0100.jpg', '800', '532', 'note the silly grin');
slides[13] = new Slide('../ApeMania_files/DSC_0105.jpg', '800', '532', 'color applied');
slides[14] = new Slide('../ApeMania_files/DSC_0106.jpg', '532', '800', 'and inside mouth');
slides[15] = new Slide('../ApeMania_files/DSC_0107.jpg', '532', '800', 'more shading');
slides[16] = new Slide('../ApeMania_files/DSC_0108.jpg', '532', '800', 'beard time');
slides[17] = new Slide('../ApeMania_files/DSC_0110.jpg', '532', '800', 'and sideburns');
slides[18] = new Slide('../ApeMania_files/DSC_0111.jpg', '532', '800', 'it’s 4:30, time for milking.');
slides[19] = new Slide('../ApeMania_files/DSC_0112.jpg', '532', '800', 'the other Rob is prepped');
slides[20] = new Slide('../ApeMania_files/DSC_0113.jpg', '800', '532', 'off to the forbidden zone');
slides[21] = new Slide('../ApeMania_files/DSC_0115.jpg', '532', '800', 'Eyebrow ridges');
slides[22] = new Slide('../ApeMania_files/DSC_0116.jpg', '532', '800', 'getting used to the idea');
slides[23] = new Slide('../ApeMania_files/DSC_0117.jpg', '532', '800', 'wigging out');
slides[24] = new Slide('../ApeMania_files/DSC_0119.jpg', '532', '800', 'lovely...');
slides[25] = new Slide('../ApeMania_files/DSC_0120.jpg', '532', '800', 'almost there');
slides[26] = new Slide('../ApeMania_files/DSC_0121.jpg', '532', '800', 'done.');
slides[27] = new Slide('../ApeMania_files/DSC_0122.jpg', '532', '800', 'what????');
slides[28] = new Slide('../ApeMania_files/DSC_0123.jpg', '532', '800', 'get out of here!');
slides[29] = new Slide('../ApeMania_files/DSC_0125.jpg', '532', '800', 'display your weapons.');
slides[30] = new Slide('../ApeMania_files/DSC_0126.jpg', '532', '800', 'lovely bust.');
slides[31] = new Slide('../ApeMania_files/DSC_0127.jpg', '532', '800', 'disguised');
slides[32] = new Slide('../ApeMania_files/DSC_0128.jpg', '532', '800', 'gorrila instigator');
slides[33] = new Slide('../ApeMania_files/DSC_0130.jpg', '532', '800', 'teeth in place');
slides[34] = new Slide('../ApeMania_files/DSC_0132.jpg', '532', '800', 'let’s get out of here.');
slides[35] = new Slide('../ApeMania_files/DSC_0133.jpg', '800', '532', 'zipping up');
slides[36] = new Slide('../ApeMania_files/DSC_0135.jpg', '800', '532', 'what have I done...');
slides[37] = new Slide('../ApeMania_files/DSC_0136.jpg', '532', '800', 'what are you looking at?');
slides[38] = new Slide('../ApeMania_files/DSC_0138.jpg', '800', '532', 'ok, let’s go...');
slides[39] = new Slide('../ApeMania_files/DSC_0139.jpg', '532', '800', 'happy family..');
slides[40] = new Slide('../ApeMania_files/DSC_0141.jpg', '800', '532', 'mostly...');
slides[41] = new Slide('../ApeMania_files/DSC_0142.jpg', '532', '800', 'on the way to stardom.');
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 smallTransparentGif = "";
function fixupIEPNG(strImageID, transparentGif) 
{
    smallTransparentGif = transparentGif;
    if (windowsInternetExplorer && (browserVersion < 7))
    {
        var img = document.getElementById(strImageID);
        if (img)
        {
            var src = img.src;
            img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')";
            img.src = transparentGif;
            img.attachEvent("onpropertychange", imgPropertyChanged);
        }
    }
}

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("id3");
    adjustFontSizeIfTooBig("id3");
    adjustLineHeightIfTooBig("id4");
    adjustFontSizeIfTooBig("id4");
    fixupIEPNG("id1", "ApeMania_files/transparent.gif");
    fixupIEPNG("id2", "ApeMania_files/transparent.gif");
    fixupIEPNG("shapeimage_3_link_0", "ApeMania_files/transparent.gif");
    fixupIEPNG("shapeimage_3", "ApeMania_files/transparent.gif");
    fixupIEPNG("id5", "ApeMania_files/transparent.gif");
    fixupIEPNG("id6", "ApeMania_files/transparent.gif");
    fixupIEPNG("id7", "ApeMania_files/transparent.gif");
    fixupIEPNG("id8", "ApeMania_files/transparent.gif");
    fixupIEPNG("id9", "ApeMania_files/transparent.gif");
    return true;
}

function IMpreload(path, name, areaIndex)
{
    var rolloverName = name+'_rollover_'+areaIndex;
    var rolloverPath = path+'/'+rolloverName+'.png';
    self[rolloverName] = new Image();
    self[rolloverName].src = rolloverPath;

    var linkName = name+'_link_'+areaIndex;
    var linkPath = path+'/'+linkName+'.png';
    self[linkName] = new Image();
    self[linkName].src = linkPath;
    return true;
}

function IMmouseover(name, areaIndex)
{
    var rolloverName = name+'_rollover_'+areaIndex;
    var linkName = name+'_link_'+areaIndex;
    var img  = document.getElementById(linkName);
    if (img)
    {
        img.src = self[rolloverName].src;
    }
    return true;
}

function IMmouseout(name, areaIndex)
{
    var linkName = name+'_link_'+areaIndex;
    var img  = document.getElementById(linkName);
    if (img)
    {
        img.src = self[linkName].src;
    }
    return true;
}

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;
    }
}

var inImgPropertyChanged = false;
function imgPropertyChanged()
{
    if ((window.event.propertyName == "src") && (! inImgPropertyChanged))
    {
        inImgPropertyChanged = true;
        var el = window.event.srcElement;
        if (el.src != smallTransparentGif)
        {
            el.filters.item(0).src = el.src;
            el.src = smallTransparentGif;
        }
        inImgPropertyChanged = false;
    }
}

