/**********************************************************************************
***********************************************************************************
****************** Slideshow Controller Utilities *********************************
**********************************************************************************/


var imageList = new Array() // DO NOT EDIT THIS LINE;


/****** This is the only section that should be edited
******* All other sections should not be modified in any way */

// INSTRUCTIONS
// Images are not added to the page directly but are added through code here.
// The only exception is a place holder image if the user turns off JavaScript.
// It is located in the NoScript section on the page.

// The image list below tells the system what images are to be added,
// the alternate text for each image and the URL the user should be directed
// to should they click on the image.
// The format for adding an image is as follows:

// imageList[image number] = { src: "image source", alt: "alternative text", href: "URL" }; 
// do not include the // as they represent a comments section or comment line
// So as a working example (again ignoring the comments tags)
// imageList[0] = { src: "nsu.jpg", alt: "Welcome to NSU!", href: "http://www.northern.edu" };

// IMPORTANT THINGS TO REMEMBER
// 1. JavaScript is case sensitive so imageList is not the same as ImageList - USE imageList
// 2. Counting in JavaScript starts at 0 so the first picture is actually picture 0
// 3. Be sure to start all picture lists with 0 and ensure that each new image number
// is increased by 1 - so 0, 1, 2, 3, etc.
// 4. Users have to download all of the images before the page is available so you will want
// to keep the number of images reasonable - 10 or less - and be sure that the image sizes are small
// 5. Be sure to match quoted items and use double quotes not single quotes - for example
// use src: "someimage.jpg" and not src: 'someimage.jpg'
// 6. The semi-colon is required at the end of each line

// Starting Template (copy everything but the // to add a new image and replace quoted items where appropriate)
// imageList[image number] = { src: "image source", alt: "alternative text", href: "URL" };



imageList[0] = { src: "/PublishingImages/2.jpg", alt: "Be You. Be Us. Be Northern.", href: "http://www.northern.edu" };
imageList[1] = { src: "/PublishingImages/3.jpg", alt: "Apply at NSU!", href: "http://www.northern.edu/Admissions/Financial_Aid/Pages/default.aspx" };
imageList[2] = { src: "/PublishingImages/Winter.jpg", alt: "Winter", href: "http://www.northern.edu" };
imageList[3] = { src: "/PublishingImages/wolf-pact.jpg", alt: "The WOLF Pact Scholarship", href: "http://www.northern.edu/Admissions/WolfPact/Pages/default.aspx" };
imageList[4] = { src: "/PublishingImages/Web_CharlesMann.jpg", alt: "Charles Mann", href: "http://www3.northern.edu/nsutickets/tickets.aspx" };
imageList[5] = { src: "/PublishingImages/Price.jpg", alt: "Price", href: "http://www.northern.edu" };
imageList[6] = { src: "/PublishingImages/Young_Dakota.jpg", alt: "Young Dakota Artists", href: "http://www.northern.edu/Academics/Departments/Fine_Arts/Art/Pages/Galleries.aspx" };
imageList[7] = { src: "/PublishingImages/Mystical_Music.jpg", alt: "Mystical Music", href: "http://www.northern.edu" };
imageList[8] = { src: "/PublishingImages/Reference_BC.jpg", alt: "Construction", href: "http://www.northern.edu/About/Pages/construction.aspx" };
imageList[9] = { src: "/PublishingImages/Josh_Moon_Ath.jpg", alt: "Josh Moon", href: "http://www.northern.edu/News/Pages/february2012_newad.aspx" };





/****** END OF EDITABLE SECTION ********************/


/***************************************************/


/***** DO NOT EDIT ANYTHING BELOW THIS LINE *******/


//Pre-load the images
//This section pre-loads the images into the user's cache on their computer
try {
    imgObject = new Image();

    for (var i = 0; i <= imageList - 1; i++) {
        imgObject.src = imageList[i].src.toString();
    }

    imgLeftNav = new Image();
    imgRightNav = new Image();

    imgLeftNav.src = "/PublishingImages/arrow-left.png";
    imgRightNav.src = "/PublishingImages/arrow-right.png";
}
catch (err)
{ }


//Custom image object declartion
//The object is used for mapping images into the controller array
//and for drawing images to the screen
function Images(cid, src, alt, href) {
    this.cid = cid;
    this.src = src;
    this.alt = alt;
    this.href = href;
}


//create the images manager for controlling the images during the slide show
//and randomize the images for presentation
//the system only randomizes the starting point for the images
//as trying to randomize the whole set would delay the loading of the page.

//Randomly set the starting image based ont the number of images 
//provided in the imageList
var startImage = Math.floor(Math.random() * imageList.length);

//Image controller array
var imgArray = new Array();

//Load the image controller array with images in the imageList
//starting with the randomly designated starting image.
try {
    for (var i = 0; i <= imageList.length - 1; i++) {
        tmpImage = new Images("imgAd" + i, imageList[startImage].src,
                imageList[startImage].alt, imageList[startImage].href);

        imgArray.push(tmpImage);

        startImage += 1

        if (startImage >= imageList.length) {
            startImage = 0;
        }
    }
}
catch (err)
{ }


//Function used for rendering images to the browser
function RenderImages() {
    try {
        for (var i = 0; i <= imgArray.length - 1; i++) {
            //write out outer shell and link
            document.writeln('<div id= "' + imgArray[i].cid.toString() + '" style="position:absolute; height: 385px; width: 530px; top: 0px; left:' + (i * 530).toString() + 'px;">');
            document.writeln('<a href="' + imgArray[i].href.toString() + '" style="text-decoration: none;" >');
            document.writeln('<img src="' + imgArray[i].src.toString() + '" alt="' + imgArray[i].alt.toString() + '" style="height: 385px; width: 530px; border:0px;" />');
            document.writeln('</a>');
            document.writeln('</div>');
        }
    }
    catch (err)
    { }   
}

//Used for controlling and limiting the animation sequences during animation cycles
var imgCntrl = undefined;
var swapCount = 0;
var swapTotal = imgArray.length;
var maxPos = (imgArray.length - 1) * 530;

//Used for controlling the timing of automatic animation cycles (no user input required)
var showCntrl = undefined;

//Function fors controlling the display of the manual navigation controls
function ShowNavMenu(navMenu, direction) {
    try {
        if ((navigator.appName.indexOf("Microsoft") != -1) && (parseInt(navigator.appVersion) >= 4)) {
            document.getElementById(navMenu).filters.alpha.opacity = 40;
        }
        else {
            document.getElementById(navMenu).style.opacity = 0.4;
        }
    }
    catch (err)
    { }
}

function HideNavMenu(navMenu) {
    try {
        if ((navigator.appName.indexOf("Microsoft") != -1) && (parseInt(navigator.appVersion) >= 4)) {
            document.getElementById(navMenu).filters.alpha.opacity = 0;
        }
        else {
            document.getElementById(navMenu).style.opacity = 0;
        }
    }
    catch (err)
    { }
}

//Function for controlling the animation sequence
function SlideImages(direction) {
    try {

        if (swapCount == 5) {
            clearInterval(imgCntrl);
            imgCntrl = undefined;
            showCntrl = setTimeout(SlideShow, 4000);
            return;
        }

        swapCount += 1;

        for (var i = 0; i <= imgArray.length - 1; i++) {
            if (direction == 'left') {

                var currentPos = parseInt(document.getElementById(imgArray[i].cid).style.left.toString());

                currentPos = currentPos - 106;

                if (currentPos <= -maxPos) {
                    currentPos = 530;
                }


                document.getElementById(imgArray[i].cid).style.left = currentPos + "px";
            }
            else if (direction == 'right') {
                var currentPos = parseInt(document.getElementById(imgArray[i].cid).style.left.toString());

                if (currentPos >= maxPos) {
                    currentPos = -530;
                }

                currentPos = currentPos + 106;

                document.getElementById(imgArray[i].cid).style.left = currentPos + "px";
            }
        }
    }
    catch (err) {

    }

}

//Function for starting the initial timing of the automated slideshow process
//This function gets added to the body.onload event for any pages
//that use this code base.
function InitSlideShow() {
    try {

        if (imgArray.length <= 1) {
            return;
        }

        showCntrl = setTimeout(SlideShow, 4000);
    }
    catch (err)
    { }  
}

//Function for starting the animation process 
//This is for the automated timed version
function SlideShow() {
    try {
        swapCount = 0;
        imgCntrl = setInterval(function () { SlideImages('left') }, 125);
    }
    catch (err)
    { }
}

//Function for manually animating slides
function AnimateSlides(direction) {
    try {

        if (imgArray.length <= 1) {
            return;
        }

        if (imgCntrl == undefined) {
            clearTimeout(showCntrl);
            swapCount = 0;
            imgCntrl = setInterval(function () { SlideImages(direction) }, 125);
        }
    }
    catch (err)
    { } 
}
