var g_ContentState = 1;
var g_CurrentPageImg = 1;
var g_TestimonialPg = 0;

/* Once Document Is Ready */
$(document).ready(function() {

    $('#ContentBox').delay(1000).slideDown('slow', function() {
        // Animation complete.
    });

    /* EVENTS */

    $("#Comp-1").hover(
        function() {
            $('#Comp-1-Txt').slideDown('fast', function() { /* Animation complete. */ });
        },
        function() {
            $('#Comp-1-Txt').slideUp('fast', function() { /* Animation complete. */ });
        });

    $("#Comp-2").hover(
        function() {
            $('#Comp-2-Txt').slideDown('fast', function() { /* Animation complete. */ });
        },
        function() {
            $('#Comp-2-Txt').slideUp('fast', function() { /* Animation complete. */ });
        });

    $("#Comp-3").hover(
        function() {
            $('#Comp-3-Txt').slideDown('fast', function() { /* Animation complete. */ });
        },
        function() {
            $('#Comp-3-Txt').slideUp('fast', function() { /* Animation complete. */ });
        });


    $("#Comp-4").hover(
        function() {
            $('#Comp-4-Txt').slideDown('fast', function() { /* Animation complete. */ });
        },
        function() {
            $('#Comp-4-Txt').slideUp('fast', function() { /* Animation complete. */ });
        });

    $("#Comp-5").hover(
        function() {
            $('#Comp-5-Txt').slideDown('fast', function() { /* Animation complete. */ });
        },
        function() {
            $('#Comp-5-Txt').slideUp('fast', function() { /* Animation complete. */ });
        });

    $("#Comp-6").hover(
        function() {
            $('#Comp-6-Txt').slideDown('fast', function() { /* Animation complete. */ });
        },
        function() {
            $('#Comp-6-Txt').slideUp('fast', function() { /* Animation complete. */ });
        });


    $('#MinContentBox').click(function(event) {
        event.preventDefault();
        if (g_ContentState) {
            $('#ContentBoxText').slideUp('slow', function() {
                // Animation complete.
                document.getElementById("ContentBoxButton").src = "images/content-box-button-more.png";
                g_ContentState = 0;
            });
        }
        else {
            $('#ContentBoxText').slideDown('slow', function() {
                // Animation complete.
                document.getElementById("ContentBoxButton").src = "images/content-box-button-less.png";
                g_ContentState = 1;
            });

        }
    });

    $('#MinContentBox2').click(function(event) {
        event.preventDefault();
        if (g_ContentState) {
            $('#ContentBoxText').slideUp('slow', function() {
                // Animation complete.
                document.getElementById("ContentBoxButton").src = "images/content-box-button-more.png";
                g_ContentState = 0;
            });
        }
        else {
            $('#ContentBoxSub1').hide(0, function() {
                // Animation complete.
            });

            $('#ContentBoxSub2').hide(0, function() {
                // Animation complete.
            });

            $('#ContentBoxText').slideDown('slow', function() {
                // Animation complete.
                document.getElementById("ContentBoxButton").src = "images/content-box-button-less.png";
                g_ContentState = 1;
            });

        }
    });

    $('#MinContentBoxSub1').click(function(event) {
        event.preventDefault();
        $('#ContentBoxSub1').slideUp('slow', function() {
            // Animation complete.
            $('#ContentBoxText').slideDown('slow', function() {
                // Animation complete.
                document.getElementById("ContentBoxButton").src = "images/content-box-button-less.png";
                g_ContentState = 1;
            });
        });
    });


    $('#MinContentBoxSub2').click(function(event) {
        event.preventDefault();
        $('#ContentBoxSub2').slideUp('slow', function() {
            // Animation complete.
            $('#ContentBoxText').slideDown('slow', function() {
                // Animation complete.
                document.getElementById("ContentBoxButton").src = "images/content-box-button-less.png";
                g_ContentState = 1;
            });
        });
    });


    $('#FlyRods').click(function(event) {
        event.preventDefault();
        if (g_ContentState) {
            $('#ContentBoxText').slideUp('slow', function() {
                // Animation complete.
                document.getElementById("ContentBoxButton").src = "images/content-box-button-more.png";
                g_ContentState = 0;
                $('#ContentBoxSub1').slideDown('slow', function() {
                    // Animation complete.
                });
            });
        }
    });

    $('#SaltwaterRods').click(function(event) {
        event.preventDefault();
        if (g_ContentState) {
            $('#ContentBoxText').slideUp('slow', function() {
                // Animation complete.
                document.getElementById("ContentBoxButton").src = "images/content-box-button-more.png";
                g_ContentState = 0;
                $('#ContentBoxSub1').slideDown('slow', function() {
                    // Animation complete.
                });
            });
        }
    });

    
    $('#SalmonRods').click(function(event) {
        event.preventDefault();
        if (g_ContentState) {
            $('#ContentBoxText').slideUp('slow', function() {
                // Animation complete.
                document.getElementById("ContentBoxButton").src = "images/content-box-button-more.png";
                g_ContentState = 0;
                $('#ContentBoxSub2').slideDown('slow', function() {
                    // Animation complete.
                });
            });
        }
    });




    $("#ThumbnailImg-1").hover(
        function() {
            document.getElementById("ThumbnailImg-1").style.borderColor = "#c18002";
        },
        function() {
            if (g_CurrentPageImg != 1)
                document.getElementById("ThumbnailImg-1").style.borderColor = "#583b04";
        });

    $("#ThumbnailImg-2").hover(
        function() {
            document.getElementById("ThumbnailImg-2").style.borderColor = "#c18002";
        },
        function() {
            if (g_CurrentPageImg != 2)
                document.getElementById("ThumbnailImg-2").style.borderColor = "#583b04";
        });

    $("#ThumbnailImg-3").hover(
        function() {
            document.getElementById("ThumbnailImg-3").style.borderColor = "#c18002";
        },
        function() {
            if (g_CurrentPageImg != 3)
                document.getElementById("ThumbnailImg-3").style.borderColor = "#583b04";
        });

    $("#ThumbnailImg-4").hover(
        function() {
            document.getElementById("ThumbnailImg-4").style.borderColor = "#c18002";
        },
        function() {
            if (g_CurrentPageImg != 4)
                document.getElementById("ThumbnailImg-4").style.borderColor = "#583b04";
        });

    $('#ThumbnailImg-1').click(function(event) {
        event.preventDefault();
        if (g_CurrentPageImg != 1) {
            document.getElementById("ThumbnailImg-" + g_CurrentPageImg).style.borderColor = "#583b04";
            g_CurrentPageImg = 1;
            document.getElementById("ThumbnailImg-1").style.borderColor = "#c18002";
        }

        if (g_TestimonialPg == 1) {
            $('#ContentBoxText').slideUp('slow', function() {
                // Animation complete.
                document.getElementById("ContentBoxButton").src = "images/content-box-button-more.png";
                g_ContentState = 0;
                document.getElementById("TestimonialOne").style.display = "block";
                document.getElementById("TestimonialTwo").style.display = "none";
                document.getElementById("TestimonialThree").style.display = "none";
                document.getElementById("TestimonialFour").style.display = "none";                
            });


            $('#ContentBoxText').delay(600).slideDown('slow', function() {
                // Animation complete.
                document.getElementById("ContentBoxButton").src = "images/content-box-button-less.png";
                g_ContentState = 1;
            });                   
        }
        else {

            $('#PageImg').fadeTo('slow', 0.01, function() {
                // Animation complete.
                document.getElementById("PageImg").src = "images/" + PageName + "-slide-1.jpg";
                $('#PageImg').delay(500).fadeTo('slow', 1, function() {
                    // Animation complete.
                });
            });
        }

    });


    $('#ThumbnailImg-2').click(function(event) {
        event.preventDefault();

        if (g_CurrentPageImg != 2) {
            document.getElementById("ThumbnailImg-" + g_CurrentPageImg).style.borderColor = "#583b04";
            g_CurrentPageImg = 2;
            document.getElementById("ThumbnailImg-2").style.borderColor = "#c18002";
        }

        if (g_TestimonialPg == 1) {

            $('#ContentBoxText').slideUp('slow', function() {
                // Animation complete.
                document.getElementById("ContentBoxButton").src = "images/content-box-button-more.png";
                g_ContentState = 0;
                document.getElementById("TestimonialOne").style.display = "none";
                document.getElementById("TestimonialTwo").style.display = "block";
                document.getElementById("TestimonialThree").style.display = "none";
                document.getElementById("TestimonialFour").style.display = "none";
            });


            $('#ContentBoxText').delay(600).slideDown('slow', function() {
                // Animation complete.
                document.getElementById("ContentBoxButton").src = "images/content-box-button-less.png";
                g_ContentState = 1;
            });                   
        }
        else {

            $('#PageImg').fadeTo('slow', 0.01, function() {
                // Animation complete.
                document.getElementById("PageImg").src = "images/" + PageName + "-slide-2.jpg";
                $('#PageImg').delay(500).fadeTo('slow', 1, function() {
                    // Animation complete.
                });
            });
        }
    });

    $('#ThumbnailImg-3').click(function(event) {
        event.preventDefault();

        if (g_CurrentPageImg != 3) {
            document.getElementById("ThumbnailImg-" + g_CurrentPageImg).style.borderColor = "#583b04";
            g_CurrentPageImg = 3;
            document.getElementById("ThumbnailImg-3").style.borderColor = "#c18002";
        }
        if (g_TestimonialPg == 1) {

            $('#ContentBoxText').slideUp('slow', function() {
                // Animation complete.
                document.getElementById("ContentBoxButton").src = "images/content-box-button-more.png";
                g_ContentState = 0;
                document.getElementById("TestimonialOne").style.display = "none";
                document.getElementById("TestimonialTwo").style.display = "none";
                document.getElementById("TestimonialThree").style.display = "block";
                document.getElementById("TestimonialFour").style.display = "none";
            });

            $('#ContentBoxText').delay(600).slideDown('slow', function() {
                // Animation complete.
                document.getElementById("ContentBoxButton").src = "images/content-box-button-less.png";
                g_ContentState = 1;
            });                            
        }
        else {
                $('#PageImg').fadeTo('slow', 0.01, function() {
                // Animation complete.
                document.getElementById("PageImg").src = "images/" + PageName + "-slide-3.jpg";
                $('#PageImg').delay(500).fadeTo('slow', 1, function() {
                    // Animation complete.
                });
            });
        }
    });

    $('#ThumbnailImg-4').click(function(event) {
        event.preventDefault();

        if (g_CurrentPageImg != 4) {
            document.getElementById("ThumbnailImg-" + g_CurrentPageImg).style.borderColor = "#583b04";
            g_CurrentPageImg = 4;
            document.getElementById("ThumbnailImg-4").style.borderColor = "#c18002";
        }
        if (g_TestimonialPg == 1) {
            $('#ContentBoxText').slideUp('slow', function() {
                // Animation complete.
                document.getElementById("ContentBoxButton").src = "images/content-box-button-more.png";
                g_ContentState = 0;
                document.getElementById("TestimonialOne").style.display = "none";
                document.getElementById("TestimonialTwo").style.display = "none";
                document.getElementById("TestimonialThree").style.display = "none";
                document.getElementById("TestimonialFour").style.display = "block";
            });

            $('#ContentBoxText').delay(600).slideDown('slow', function() {
                // Animation complete.
                document.getElementById("ContentBoxButton").src = "images/content-box-button-less.png";
                g_ContentState = 1;
            });                            
        }
        else {
                $('#PageImg').fadeTo('slow', 0.01, function() {
                // Animation complete.
                document.getElementById("PageImg").src = "images/" + PageName + "-slide-4.jpg";
                $('#PageImg').delay(500).fadeTo('slow', 1, function() {
                    // Animation complete.
                });
            });
        }            
    });
    /* END OF EVENTS */

});


function InitHomePg() {
    pic1 = new Image(845, 1413);
    pic1.src = "images/home-slide-1.jpg";

    pic2 = new Image(845, 1413);
    pic2.src = "images/home-slide-2.jpg";

    pic3 = new Image(845, 1413);
    pic3.src = "images/home-slide-3.jpg";

    pic4 = new Image(845, 1413);
    pic4.src = "images/home-slide-4.jpg";
}

function InitRodsPg() {

    $(function() {
        $('a.lightbox').lightBox(); // Select all links with lightbox class        
    });

    $('#ContentBox2').delay(1000).slideDown('slow', function() {
        // Animation complete.
    });
}

function InitAboutPg() {
    pic1 = new Image(845, 1413);
    pic1.src = "images/about-slide-1.jpg";

    pic2 = new Image(845, 1413);
    pic2.src = "images/about-slide-2.jpg";

    pic3 = new Image(845, 1413);
    pic3.src = "images/about-slide-3.jpg";

    pic4 = new Image(845, 1413);
    pic4.src = "images/about-slide-4.jpg";
}

function InitFlyRodPg() {
    pic1 = new Image(845, 1413);
    pic1.src = "images/fly-rods-slide-1.jpg";

    pic2 = new Image(845, 1413);
    pic2.src = "images/fly-rods-slide-2.jpg";

    pic3 = new Image(845, 1413);
    pic3.src = "images/fly-rods-slide-3.jpg";

    pic4 = new Image(845, 1413);
    pic4.src = "images/fly-rods-slide-4.jpg";
}

function InitSteelheadRodPg() {
    pic1 = new Image(845, 1413);
    pic1.src = "images/steelhead-rods-slide-1.jpg";

    pic2 = new Image(845, 1413);
    pic2.src = "images/steelhead-rods-slide-2.jpg";

    pic3 = new Image(845, 1413);
    pic3.src = "images/steelhead-rods-slide-3.jpg";

    pic4 = new Image(845, 1413);
    pic4.src = "images/steelhead-rods-slide-4.jpg";
}

function InitSaltwaterRodPg() {
    pic1 = new Image(845, 1413);
    pic1.src = "images/saltwater-rods-slide-1.jpg";

    pic2 = new Image(845, 1413);
    pic2.src = "images/saltwater-rods-slide-2.jpg";

    pic3 = new Image(845, 1413);
    pic3.src = "images/saltwater-rods-slide-3.jpg";

    pic4 = new Image(845, 1413);
    pic4.src = "images/saltwater-rods-slide-4.jpg";
}


function InitWarrantyPg() {
    pic1 = new Image(845, 1413);
    pic1.src = "images/warranty-slide-1.jpg";

    pic2 = new Image(845, 1413);
    pic2.src = "images/warranty-slide-2.jpg";

    pic3 = new Image(845, 1413);
    pic3.src = "images/warranty-slide-3.jpg";

    pic4 = new Image(845, 1413);
    pic4.src = "images/warranty-slide-4.jpg";
}

function InitContactPg() {
    pic1 = new Image(845, 1413);
    pic1.src = "images/contact-slide-1.jpg";

    pic2 = new Image(845, 1413);
    pic2.src = "images/contact-slide-2.jpg";

    pic3 = new Image(845, 1413);
    pic3.src = "images/contact-slide-3.jpg";

    pic4 = new Image(845, 1413);
    pic4.src = "images/contact-slide-4.jpg";
}

function InitOrderPg() {
    pic1 = new Image(845, 1413);
    pic1.src = "images/order-slide-1.jpg";

    pic2 = new Image(845, 1413);
    pic2.src = "images/order-slide-2.jpg";

    pic3 = new Image(845, 1413);
    pic3.src = "images/order-slide-3.jpg";

    pic4 = new Image(845, 1413);
    pic4.src = "images/order-slide-4.jpg";
}

function InitTestimonialsPg() {
    g_TestimonialPg = 1;
    document.getElementById("TestimonialOne").style.display = "block";
    
}


/* ********* Gallery ******************** */
var arrayOfPics = new Array(2048);
var arrayOfWidths = new Array(2048);
var CurrentSelected = 0;
var PlayMode = 0;
var SlideCount = 0;
var timer = null;

function ChangePic(strSRC, selected, fslideshow) {
    if (fslideshow == 0)
        StopSlideShow();

    $('#SecondaryImg').fadeTo('slow', 0.01, function() {
        // Animation complete.
        document.getElementById("SecondaryImg").src = "images/pix.gif";
        document.getElementById("SecondaryImg").src = strSRC;
        $('#SecondaryImg').delay(600).fadeTo('slow', 1, function() {
            // Animation complete.
        });
    });

    object = document.getElementById("TN-" + CurrentSelected);
    object.style.borderColor = "#583b04";

    object = document.getElementById("TN-" + selected);
    object.style.borderColor = "#c18002";

    CurrentSelected = selected;
}

function ShowSelect(selected) {
    object = document.getElementById("TN-" + selected);
    object.style.borderColor = "#c18002";
}

function HideSelect(selected) {
    if (selected != CurrentSelected) {
        object = document.getElementById("TN-" + selected);
        object.style.borderColor = "#583b04";
    }
}

/************************* the slideshow functions **********************************************/
function HighliteStop() {
    object = document.getElementById("StopButton");
    object.src = "images/stop-button-on.jpg";
}

function UnhighliteStop() {
    if (PlayMode == 1) {
        object = document.getElementById("StopButton");
        object.src = "images/stop-button.jpg";
    }
}

function HighlitePlay() {
    object = document.getElementById("PlayButton");
    object.src = "images/play-button-on.jpg";
}

function UnhighlitePlay() {
    if (PlayMode == 0) {
        object = document.getElementById("PlayButton");
        object.src = "images/play-button.jpg";
    }
}

function PlaySlideShow() {
    if (PlayMode == 1) {
        return;
    }
    else {
        PlayMode = 1;
        HighlitePlay();
        UnhighliteStop();
        AdvanceSlide();
    }
}

function StopSlideShow() {
    PlayMode = 0;
    HighliteStop();
    UnhighlitePlay();
    clearTimeout(timer);
    SlideCount = 0;
}


function AdvanceSlide() {
    if (CurrentSelected < arrayLastIndex) {
        SlideCount += 1;

        ChangePic(arrayOfPics[CurrentSelected + 1], CurrentSelected + 1, 1);

        if (SlideCount == 5) {
            var content = document.getElementById('Thumbnails');
            var y = content.scrollLeft;

            content.scrollLeft = y + 851;

            SlideCount = 0;
        }

        if (PlayMode == 1) {
            timer = setTimeout("AdvanceSlide()", 6000);
        }
    }
    else {
        SlideCount = 0;

        var content = document.getElementById('Thumbnails');
        var y = content.scrollLeft;
        content.scrollLeft = y - 1000000;

        ChangePic(arrayOfPics[0], 0, 1);
        t = setTimeout("AdvanceSlide()", 6000);
    }
}

/************************* the scroll functions **********************************************/

var slowStep = 4;
var fastStep = 30;
var stepSize = slowStep;
var scrollInterval;
var intervalSpeed = 5;

function scrollRight() {

    var content = document.getElementById('Thumbnails');
    var y = content.scrollLeft;

    content.scrollLeft = y + stepSize;

}


function scrollLeft() {
    var content = document.getElementById('Thumbnails');
    var y = content.scrollLeft;

    content.scrollLeft = y - stepSize;
}


function startScrollLeft() {

    object = document.getElementById("ScrollLeft");
    object.src = "images/left-arrow-nav-on.jpg";

    if (scrollInterval != null) {
        clearInterval(scrollInterval);
    }

    stepSize = slowStep;
    scrollInterval = setInterval("scrollLeft()", intervalSpeed);
}

function startScrollRight() {

    object = document.getElementById("ScrollRight");
    object.src = "images/right-arrow-nav-on.jpg";

    if (scrollInterval != null) {
        clearInterval(scrollInterval);
    }

    stepSize = slowStep;
    scrollInterval = setInterval("scrollRight()", intervalSpeed);
}


function stopScroll() {

    object = document.getElementById("ScrollLeft");
    object.src = "images/left-arrow-nav.jpg";
    object = document.getElementById("ScrollRight");
    object.src = "images/right-arrow-nav.jpg";

    clearInterval(scrollInterval);
    scrollInterval = null;

}

function stepUp() {

    stepSize = fastStep;

}

function stepDown() {

    stepSize = slowStep;

}

function initScroll() {
    //alert("DEBUG: InitiScroll()");
}


function KeyCheck(e) {

    var KeyID = (window.event) ? event.keyCode : e.keyCode;

    //alert(KeyID);
    switch (KeyID) {

        case 37:
            //alert("Arrow Left");
            stepSize = fastStep;
            stopScroll();
            scrollLeft();
            break;


        case 39:
            //alert("Arrow Right");
            stepSize = fastStep;
            stopScroll();
            scrollRight();
            break;

    }
}

//document.onkeyup = KeyCheck;
document.onkeydown = KeyCheck;
document.onkeyup = stopScroll;
 
