﻿	var timer1;
	var timer2;
	var timer3;
	var timer4;
	var timer5;
	var timer6;
	var timer7;
	var timer8;

    var rotate_delay = 3000;
    var rotate_delay2 = 100;

    var halt = "no";
    
    var images = new Array(4);
    var links = new Array(4);
    var icons = new Array(4);

    images[0] = "images/rotate/rotate-1-4.jpg";
    images[1] = "images/rotate/rotate-2-2.jpg";
    images[2] = "images/rotate/rotate-3-4.jpg";
    images[3] = "images/rotate/rotate-4-4.jpg";

    links[0] = "http://www.lcpgifts.com/newreleases.aspx?NR=Winter%202011%20and%20Spring%202012";
    links[1] = "http://www.lcpgifts.com/Collections/s-240-Stitches-Collection.aspx";
    links[2] = "http://www.lcpgifts.com/Collections/s-140-Our-Love-Collection.aspx";
    links[3] = "http://www.lcpgifts.com/Collections/s-202-Bronze-Title-Bar.aspx";

    icons[0] = "images/rotate/rotate-1-4_small.jpg";
    icons[1] = "images/rotate/rotate-2-2_small.jpg";
    icons[2] = "images/rotate/rotate-3-4_small.jpg";
    icons[3] = "images/rotate/rotate-4-4_small.jpg";

    current = 0;
    
    function start_rotate()
    {
        rotate();
    }

    function setOpacity(obj, opacity) 
    {
        opacity = (opacity == 100)?99.999:opacity;
        
        // IE/Win
        obj.style.filter = "alpha(opacity:"+opacity+")";

        // Safari<1.2, Konqueror
        obj.style.KHTMLOpacity = opacity/100;

        // Older Mozilla and Firefox
        obj.style.MozOpacity = opacity/100;

        // Safari 1.2, newer Firefox and Mozilla, CSS3
        obj.style.opacity = opacity/100;
    }

    function fadeIn(objId,opacity) 
    {
            if (document.getElementById) 
            {
                obj = document.getElementById(objId);
                setOpacity(obj, opacity);
            }
    }
    
    function fadeOut(objId,opacity) 
    {
            if (document.getElementById) 
            {
                obj = document.getElementById(objId);

                if (opacity == 90)
                {
                    if (current == 1)
                        document.getElementById("rotatediv").style.backgroundImage = "url(images/rotate/rotate-2-2.jpg)";
                    else if (current == 2)
                        document.getElementById("rotatediv").style.backgroundImage = "url(images/rotate/rotate-3-4.jpg)";
                    else if (current == 3)
                        document.getElementById("rotatediv").style.backgroundImage = "url(images/rotate/rotate-4-4.jpg)";
                    else if (current == 4)
                        document.getElementById("rotatediv").style.backgroundImage = "url(images/rotate/rotate-1-4.jpg)";
                }

                if (opacity >= 0) 
                {
                    setOpacity(obj, opacity);
                    opacity -= 10;
                    timer4 = window.setTimeout("fadeOut('"+objId+"',"+opacity+")", 50);
                }
            }
    }
    
    function fadeOut2(objId,opacity) 
    {
        if(document.getElementById) 
        {
            obj = document.getElementById(objId);

            if (current == 1)
                document.getElementById("rotatediv").style.backgroundImage = "url(images/rotate/rotate-2-2.jpg)";
            else if (current == 2)
                document.getElementById("rotatediv").style.backgroundImage = "url(images/rotate/rotate-3-4.jpg)";
            else if (current == 3)
                document.getElementById("rotatediv").style.backgroundImage = "url(images/rotate/rotate-4-4.jpg)";
            else if (current == 4)
                document.getElementById("rotatediv").style.backgroundImage = "url(images/rotate/rotate-1-4.jpg)";
                
            if (opacity >= 0) 
            {
                setOpacity(obj, opacity);
                opacity -= 10;
                window.setTimeout("fadeOut2('"+objId+"',"+opacity+")", 50);
            }
            else
            {
	            halt = "no";
	            rotate();
            }
        }
    }

    function findnext(curr)
    {
        clearTimeout(timer1);
        clearTimeout(timer2);
        clearTimeout(timer3);
        clearTimeout(timer4);
        clearTimeout(timer5);
        clearTimeout(timer6);
        clearTimeout(timer7);
        clearTimeout(timer8);

        current = curr;

        if (current == 4)
            current = 0;

        halt = "yes";

        image = document.getElementById("thephoto");  
        setOpacity(image, 100);
        image.style.visibility = 'visible';
        
        document.images.show.src = images[current];
        
        addlink(current);
        apply_styles(current);

        timer5 = window.setTimeout("fadeOut2('thephoto', 100);", 5000);
        current = current + 1;
    }

    function findprevious(curr)
    {
        clearTimeout(timer1);
        clearTimeout(timer2);
        clearTimeout(timer3);
        clearTimeout(timer4);
        clearTimeout(timer5);
        clearTimeout(timer6);
        clearTimeout(timer7);
        clearTimeout(timer8);

        halt = "yes";

        if (current == 1)
            current = 3;
        else
            current = curr - 2;

        image = document.getElementById("thephoto");  
        setOpacity(image, 100);
        image.style.visibility = 'visible';
        
        document.images.show.src = images[current];
        
        addlink(current);
        apply_styles(current);

        timer5 = window.setTimeout("fadeOut2('thephoto', 100);", 5000);
        current = current + 1;
    }
    
    function find(imagenum)
    {
        clearTimeout(timer1);
        clearTimeout(timer2);
        clearTimeout(timer3);
        clearTimeout(timer4);
        clearTimeout(timer5);

        halt = "yes";
        
        image = document.getElementById("thephoto");  
        setOpacity(image, 100);
        image.style.visibility = 'visible';
        
        document.images.show.src = images[imagenum];
        current = imagenum;
        
        addlink(current);
        apply_styles(current);

        timer5 = window.setTimeout("fadeOut2('thephoto', 100);", 5000);
        current = current + 1;
    }
    
    function toggleStart()
    {
        
    }
    
    function rotate() 
    {
         if(halt = "no")
         {   
            if(current < images.length)
            {
                //document.getElementById("rotatediv").style.backgroundImage = "url(images/rotate/rotate_bga.jpg)";
                //document.images.show.style.visibility = "hidden";
                document.images.show.src = images[current];
                image = document.getElementById("thephoto");
                addlink(current);
                
                //setOpacity(image, 0);
                //image.style.visibility = 'visible';
                //fadeIn("thephoto", 100);

                apply_styles(current);

                timer1 = window.setTimeout("fadeOut('thephoto', 100);", 9000);

                current = current + 1;
                
                if (current == 4)
                    timer7 = window.setTimeout("apply_styles(0);", 9200);
                else
                    timer8 = window.setTimeout("apply_styles(current);", 9200);
                
                timer2 = window.setTimeout("rotate()", 10000);
	  //needs to be 1000 more than the fadeOut function timeout
            }
            else
            {
                current = 0;
                rotate();
            }
         }
    }
    
    function apply_styles(curr)
    {
        if (halt = "no") 
        {
            if (curr == 0) {
                icon = document.getElementById("icon1");
                setOpacity(icon, 100);
                icon2 = document.getElementById("icon2");
                setOpacity(icon2, 70);
                icon3 = document.getElementById("icon3");
                setOpacity(icon3, 70);
                icon4 = document.getElementById("icon4");
                setOpacity(icon4, 70);

                document.getElementById("active1").style.display = "";
                document.getElementById("active2").style.display = "none";
                document.getElementById("active3").style.display = "none";
                document.getElementById("active4").style.display = "none";
            }
            else if (curr == 1) {
                icon = document.getElementById("icon1");
                setOpacity(icon, 70);
                icon = document.getElementById("icon2");
                setOpacity(icon, 100);
                icon2 = document.getElementById("icon3");
                setOpacity(icon2, 70);
                icon3 = document.getElementById("icon4");
                setOpacity(icon4, 70);

                document.getElementById("active1").style.display = "none";
                document.getElementById("active2").style.display = "";
                document.getElementById("active3").style.display = "none";
                document.getElementById("active4").style.display = "none";
            }
            else if (curr == 2) {
                icon2 = document.getElementById("icon1");
                setOpacity(icon2, 70);
                 icon = document.getElementById("icon2");
                setOpacity(icon, 70);
                icon2 = document.getElementById("icon3");
                setOpacity(icon2, 100);
                icon3 = document.getElementById("icon4");
                setOpacity(icon4, 70);

                document.getElementById("active1").style.display = "none";
                document.getElementById("active2").style.display = "none";
                document.getElementById("active3").style.display = "";
                document.getElementById("active4").style.display = "none";
            }
            else if (curr == 3) {
                icon2 = document.getElementById("icon1");
                setOpacity(icon2, 70);
                 icon = document.getElementById("icon2");
                setOpacity(icon, 70);
                icon2 = document.getElementById("icon3");
                setOpacity(icon2, 70);
                icon3 = document.getElementById("icon4");
                setOpacity(icon4, 100);

                document.getElementById("active1").style.display = "none";
                document.getElementById("active2").style.display = "none";
                document.getElementById("active3").style.display = "none";
                document.getElementById("active4").style.display = "";
            }
        }
    }
    
    function addlink(curr)
    {
        document.getElementById('link').href = links[curr];
    }
