//Partners is the slideshow that will cycle through all of the partner logos
//with a fade in and fade out affect.  First, load this when the page is loaded

window.addEventListener?window.addEventListener("load",partners_init,false):window.attachEvent("onload",partners_init);

src = new Array();  //Variable used to set the link location
pic = new Array();  //Variable is an array to store x number of picture files names.
alt = new Array();
opacity = 0;        //Variable to set the image opacity, which will increase or decrease between 1 and 0
var doopac = "increase";  //To determine if the opacity is increasing or decreasing
var mover = null;       //To determine if mouse is over image
//Declare the images that will be used...to add more images simply copy what is
//written, incrementing the number by 1 and changing the file path.
    pic[1] = "http://www.coloradoconceptlighting.com/images/partners/juno.jpg";
    pic[2] = "http://www.coloradoconceptlighting.com/images/partners/nightscaping.jpg";
    pic[3] = "http://www.coloradoconceptlighting.com/images/partners/lutron.jpg";
    pic[4] = "http://www.coloradoconceptlighting.com/images/partners/litetouch.jpg";
    pic[5] = "http://www.coloradoconceptlighting.com/images/partners/amx.jpg";
    pic[6] = "http://www.coloradoconceptlighting.com/images/partners/crestron.jpg";
    pic[7] = "http://www.coloradoconceptlighting.com/images/partners/iris.jpg";
    pic[8] = "http://www.coloradoconceptlighting.com/images/partners/liton.jpg";
    pic[9] = "http://www.coloradoconceptlighting.com/images/partners/vantage.jpg";
    pic[10] = "http://www.coloradoconceptlighting.com/images/partners/merlin.jpg";
    
//Declare where the link will point when the image is clicked
//The src MUST line up with the images in the same order
    src[1] = "http://www.junolighting.com";
    src[2] = "http://www.nightscaping.com";
    src[3] = "http://www.lutron.com";
    src[4] = "http://www.litetouch.com";
    src[5] = "http://www.amx.com";
    src[6] = "http://www.crestron.com";
    src[7] = "http://www.iris-lighting.com/";
    src[8] = "http://www.liton.com";
    src[9] = "http://www.vantagecontrols.com";
    src[10] = "http://www.merlinlights.com/";
    
//Declare the name of the link for the alt text of the link
//The alt MUST line up with the images and links in the same order
    alt[1] = "Juno Lighting Group - Recessed, Track, Under Cabinet and Decorative lighting fixtures for Residential, Commercial, Industrial, Retail and Hospitality lighting applications.";
    alt[2] = "Low Voltage Outdoor Landscape Lighting Manufacture - Nightscaping.";
    alt[3] = "Lutron Electronics, Inc. - Dimmers And Lighting Controls";
    alt[4] = "LiteTouch Lighting Control and Automation";
    alt[5] = "AMX.com - It is Your World Take Control&reg;";
    alt[6] = "Crestron Electronics - Home Automation, Business, Campus Solutions";
    alt[7] = "Iris Lighting";
    alt[8] = "LITON Lighting | Welcome!";
    alt[9] = "Vantage - Home - Living Perfection";
    alt[10] = "Merlin Light; Fine Art Lighting - Precision Optical Projector";
    
var x = 0;  //used to increment through the pictures, starting with a random number

//This will get a random number to start with when the page is initially loaded
//and will continue through the loop until an acceptable number is reached
while (x <= 0 || x > pic.length)
    {
        x = Math.floor(Math.random()*pic.length)
    }

picload = new Array();  //used to load the pictures

//Begin fuction partners_init()

function partners_init() {
    document.getElementById("lnklogos").setAttribute("href", src[x]);
    document.getElementById("lnklogos").setAttribute("onMouseOver", "mouseover();");
    document.getElementById("imglogo").setAttribute("alt", alt[x]);
    document.images.imglogo.style.filter = "alpha(opacity="+opacity*100+")"; //sets opacity for IE
    document.images.imglogo.style.MozOpacity = opacity;                      //sets opacity for mozilla
   	document.images.imglogo.style.opacity = opacity;						//sets opacity for webkit based browsers (safari and chrome)

    i = 1;

    while (i < pic.length)
    {
        picload[i] = new Image();  //an array of images
        picload[i].src = pic[i];   //sets the pic array containing the file path to the image src

        i++;
    }


    //Resets the imglogo src on the page to the randomly x indexed image src
    //By generating a random number, x, and loading that image, this will give a
    //different starting point to the rotating images when the page is first loaded
    //to increase the chances of clients seeing all of our partners, not just
    //the same starting logos.  The rotation will start with x, and then cycle through
    //by increment x until the end of the images, then start from the beginning at 1.
    document.images.imglogo.src = picload[x].src;


    if (mover == null || mover == "false")  //if mover is false or null then change the opacity, otherwise, go to else if and
    {										//don't change opacity.
        //Following statements to determine what will happen with opacity, then it will reload
        //the partners_init function (this function), and do all of the code again.

        //If opacity is still less than 1 and we are increasing opacity, then continue to increase
        if (opacity<1 && doopac=="increase")
        {
            opacity += .03;
            setTimeout(partners_init, 50);
        }
        //If opacity is greater than 1 (no longer an acceptable number) and we were increase,
        //then change doopac to decrease, and set opacity to highest acceptable number,
        //which means images will be fully visible
        else if (opacity>=1 && doopac=="increase")
        {
            opacity = 1;
            doopac = "decrease";
            setTimeout(partners_init, 1000);
        }
        //If opacity is less then or equal to 1 and we are decrease then lets continue to
        //decrease, as long as it is still above zero
        else if (opacity<=1 && doopac=="decrease" && opacity>0)
        {
            opacity -= .03;
            setTimeout(partners_init, 50);
        }
        //If opacity is smaller than zero (which is no longer acceptable number) and we were decreasing
        //then lets pause at zero (recall the function after timeout expires)
        //After the pause this function will reset opacity to 0 and set doopac to increase,
        //as well as move x to index the next image.  When the function is recalled after the
        //timeout, the opacity will start increasing on the next image.
        //If the end of the image list is reached, x will be set back to 1, the starting point for the images
        else if ((opacity<=0 && doopac=="decrease") || (doopac=="pause"))
        {
            if (doopac == "decrease") doopac = "pause";
            else if (doopac == "pause")
            {
                doopac = "increase";
                if (x<picload.length-1) x ++;
                else x = 1;
            }
            opacity = 0;
            setTimeout(partners_init, 300);
        }
    }
    else if (mover == "true") //if mover is set to true, then mouse is over image..."pause" changing opacity until mouse leaves
    {							//the image.  Timeout set low, which will rerun the function and still return here if mover is true.
           document.getElementById("lnklogos").setAttribute("onMouseOut", "mouseout();");

           setTimeout(partners_init, 300);
    }
 }
//End Function partners_init


function mouseover() {
    mover = "true";
//if mouse is over image, this function is triggered.  Setting is set within the tag on the page
//This event sets to mover to true when mouse is over image, which will "pause" the opacity at the current
//value until mouseout is triggered (when the mouse leaves the image).
}

function mouseout() {
    mover = "false";
//When mouse leaves image, return mover to false, and continue with change opacity (fading in and out effects).
}
