var numpics = opener.document.links.length;
var allpics = new Array();
var currIndex = 0;
var altTexts = new Array();
var landscapeWidth = 250;
var portraitWidth = 250;

getAllPics();
whichSlide();
anyPortrait(); 
findImgWidth();        

function newSlide()
    {
        window.open("slideshow.html", "slideshow", "height=" + screen.availHeight +", width=" + screen.availWidth);    
    }


function findImgWidth()
    {
        var possH = window.innerHeight - 35;
        var possW = window.innerWidth;
         
        portraitWidth = possH * 0.75; 
         
        if (possH/possW >= 0.75)
            {
                landscapeWidth = possW;
            }
        else 
            {
                landscapeWidth = (4/3) * possH;
            }
            
        if (landscapeWidth > 1000)
            {
                landscapeWidth = 1000;
            }       
    }

function getAllPics()
    {
        var allrefs = new Array();
        
        for (i=0; i < numpics; i++)                             // Makes an array of the hrefs of ALL
            {                                                   //links on the page that opened the
                var anyRef = opener.document.links[i].href;     // slideshow page
                
                allrefs.push(anyRef);
            }
            
        for (i=0; i < allrefs.length; i++)
            {
                var currRef = allrefs[i];                   // Tests whether each href contains "jpg"
                                                            // in its name, and adds it to the array
                if ((currRef.indexOf("JPG") != -1) || (currRef.indexOf("jpg") != -1))           // "allpics" only if it does.
                    {
                    allpics.push(currRef);
                    }
            } 
            
            preloadImages();
    }

function preloadImages()
    {
        var preloadImg = new Image();
        
        for (i=0; i < allpics.length; i++)
            {
            preloadImg.src = allpics[i];
            }
    }
    
function anyPortrait()
    {
        for (i=0; i < opener.document.images.length; i++)
            {
            var thisAltText = opener.document.images[i].alt;
            
            altTexts.push(thisAltText);
            }
    }   

function getPic(picnum)
    {
        var currPic = allpics[picnum];
        currIndex = picnum;

        return currPic;
    }

function nextSlide()
    {
        var newIndex = currIndex + 1;
        
        if (newIndex <= (allpics.length - 1))
            {
            var newSlide = getPic(newIndex);
            
            document.slidepic.src = newSlide;
            }   
            
        if (altTexts[newIndex] == "portrait")
            {
            document.slidepic.width = portraitWidth;
            }
        else
            {
            document.slidepic.width = landscapeWidth;
            }
        
        whichSlide();
    }   

function prevSlide()
    {
        var newIndex = currIndex - 1;
                
        if (newIndex >= 0)
            {
            var newSlide = getPic(newIndex);
            
            document.slidepic.src = newSlide;
            }
            
        if (altTexts[newIndex] == "portrait")
            {
            document.slidepic.width = portraitWidth;
            }
        else
            {
            document.slidepic.width = landscapeWidth;
            }
        
        whichSlide();
    }
    

function whichSlide()
    {
        var slidenum = currIndex + 1;
        var slidetotal = allpics.length;
        
        if (slidenum < 10)
            {
            prefix = "&nbsp;&nbsp;";
            }
        else
            {
            prefix = "";
            }
            
        var slideString = "Picture " + prefix + slidenum + " of " + slidetotal;
   
        document.getElementById("whichslide").innerHTML = slideString;
        
        if (slidenum >= slidetotal)
            {
                document.getElementById('next').className = "invisible";
            }
            
        else             
            {
                document.getElementById('next').className = "std";
            }
            
        if (slidenum == 1)
            {
                document.getElementById('prev').className = "invisible";
            }
            
        else             
            {
                document.getElementById('prev').className = "std";
            }
            
        
        return "";
    }

function quitSlide()
    {
        var quit = confirm("Do you really want to quit the slideshow?");
        
        if (quit == true)
            {
            window.close()
            }
    }
    