//        A "True" Preloader
//        Written by: Randy Girard - April 2003
//        You are free to redistribute or edit this code in
//        any way as long as this notice stays intact.

//Q: How igsactly does this method of preloading things work?
//A: This script makes a hidden layer, then prints html code
//   inside of the layer. An event (onload) is then setup
//   to redirect to the next page when loading is complete.
//   So, the browser loads the images and saves them into
//   your temporary internet files. As you continue through
//   the site, there is no wait for pictures or flash movies
//   to load.
//   This can be customized to preload close to anything!! (wav's, midi's, probly even mp3's!!)

//I do not recommend having any images on your "loading" page

var DoRedirect = "true";         //set this to "true" to redirect when completed loading, other values will be considered false (case sensitive)
var RedirectTo = "plauen1.html";        //This is the page we will navigate to once the load is complete (this may be case sensitive, depending on the server it is hosted on)
var AmmountPreloads = 3;         //How many things do you have to preload?

//Don't edit the below line of code!!
var imgArray = CreateArray(AmmountPreloads + 1,2);


        //Edit the variable "AmmountPreloads" and the below lines to customize what is preloaded.
        imgArray[1][0] = "plauen1.swf";        //Path to what we are preloading
        imgArray[1][1] = "flash";                 //Tell the script how to preload it


                //Q: Why did I not tell the script how to preload most of the images?!
                //A: I just added that option... if it is undefined, the script uses
                //   the last one which was used. example, if you have 3 images you
                //   want to preload, you only need to tell the script the first
                //   one is an image (like done so above). This also works with the
                //   flash movies.


        //This is how u load flash movies
//        imgArray[4][0] = "flashmovie1.swf";        //Path to what we are preloading
//        imgArray[4][1] = "flash";                 //Tell the script how to preload it
//WARNING: Unlike images, if the flash movie does not exist, the page will not finish loading!!
//         (or will atleast take a loooooooooong time)


//Do not edit anything below this comment!!

        //This function creates 2 dimension arrays
        function CreateArray(dim1) {
                if (CreateArray.arguments.length == 1) {
                        return new Array(dim1);
                } else {
                        var multiArray = new Array(dim1)
                        for (var i = 0; i < dim1; i++) {
                                multiArray[i] = new Array(CreateArray.arguments[1]);
                        }
                        return multiArray;
                }
        }

//This will print a hidden DIV layer for us to preload our stuff on.
window.document.write("<div id='preloadLayer' style='position:absolute; left:0px; top:0px; width:0px; height:1px; z-index:1; visibility: hidden;'>");

//Loop through all of our things to preload
var LastType = "";
for (loop = 1; loop < imgArray.length; loop++) {
        var PrintString = "";
        var CheckType = "";

        //Check to make sure the path to what we are preloading exists
        if ( imgArray[loop][0] ) {
        //Check if it is an image type of load
        if ( imgArray[loop][1] == "image" || (!imgArray[loop][1] && LastType == "image" )) {
                //A simple image code is written to the page
                PrintString = "<img src='" + imgArray[loop][0] + "'>";
        //Check if it is a flash type of load
        } else if ( imgArray[loop][1] == "flash" || (!imgArray[loop][1] && LastType == "flash" )) {
                //Again, a pretty simple flash code is written to the page
                PrintString = "<OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0'> <PARAM NAME=movie VALUE='" + imgArray[loop][0] + "'> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#000000> <EMBED src='" + imgArray[loop][0] + "' quality=high bgcolor=#000000 ALIGN='' TYPE='application/x-shockwave-flash' PLUGINSPAGE='http://www.macromedia.com/go/getflashplayer'></EMBED></OBJECT>";
        //Self explanitary ^_^
        } else {
                //O NO!! The type of load they specified is not supported!! Lets alert the user
                alert("Preload Warning: File type '" + imgArray[loop][1] + "' is not supported!! Keep in mind this is Case-sensitive!!");
        }
        //If this loop has a type, lets set the LastType variable
        if ( imgArray[loop][1] ) { LastType = imgArray[loop][1]; } }

        //Lets print the string we have generated. if there isn't one, just a new line is printed.
        window.document.write("<br>" + PrintString);
}

//We're done printing out our stuff, so we need the closing tag for the div layer:
window.document.write("</div>");


//This function will redirect to the page specified at the top of this script
function Redirect() {
    window.location.replace(RedirectTo);
}

//Now lets set an event so that once the page fully loads, we will redirect to the next page.
//Also added an option to cancel the redirect.
if ( DoRedirect == "true" ) {
        window.onload = Redirect;
}