﻿// Initially set opacity on thumbs and add
// additional styling for hover effect on thumbs
var onMouseOutOpacity = 1.00;
$('#thumbs ul.thumbs li').css('opacity', onMouseOutOpacity)
.hover(
/*function() {
$(this).not('.selected').fadeTo('fast', 1.0);
},
function() {
$(this).not('.selected').fadeTo('fast', onMouseOutOpacity);
}*/
);

$(document).ready(function() {
    // Initialize Advanced Galleriffic Gallery
    var galleryAdv = $('#gallery').galleriffic('#thumbs', {
        delay: 3000,
        numThumbs: 3,
        preloadAhead: -1,
        enableTopPager: true,
        enableBottomPager: true,
        imageContainerSel: '#slideshow',
        controlsContainerSel: '#controls',
        captionContainerSel: '#caption',
        loadingContainerSel: '#loading',
        renderSSControls: true,
        renderNavControls: true,
        playLinkText: 'Play Slideshow',
        pauseLinkText: 'Pause Slideshow',
        prevLinkText: '&lsaquo; Previous Photo',
        nextLinkText: 'Next Photo &rsaquo;',
        nextPageLinkText: 'Next &rsaquo;',
        prevPageLinkText: '&lsaquo; Prev',
        enableHistory: false,
        autoStart: true,
        onChange: function(prevIndex, nextIndex) {
            //$('#thumbs ul.thumbs').children()
            //.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
            //.eq(nextIndex).fadeTo('fast', 1.0);

            // get the relative directory
            var path = $('img.thumbimg').eq(prevIndex).attr("src");
            path = path.substring(0, path.lastIndexOf("/"));
            if (isIE6) {

                $('img.thumbimg').eq(prevIndex).attr("src", path + "/ie6thumb" + (prevIndex + 1) + ".jpg");

                $('img.thumbimg').eq(nextIndex).attr("src", path + "/ie6thumb" + (nextIndex + 1) + "_over.jpg");
            } else {
                $('img.thumbimg').eq(prevIndex).attr("src", path + "/thumb" + (prevIndex + 1) + ".png");

                $('img.thumbimg').eq(nextIndex).attr("src", path + "/thumb" + (nextIndex + 1) + "_over.png");
            }

        },
        onTransitionOut: function(callback) {
            $('#caption').fadeOut('fast');
            $('#slideshow').fadeOut('fast', callback);
        },
        onTransitionIn: function() {
            $('#slideshow, #caption').fadeIn('fast');
        },
        onPageTransitionOut: function(callback) {
            $('#thumbs ul.thumbs').fadeOut('fast', callback);
        },
        onPageTransitionIn: function() {
            $('#thumbs ul.thumbs').fadeIn('fast');
        }
    });


    $("img.#thumb1")
        .mouseover(function() {
            //pause the slideshow
            galleryAdv.pause();

            //goto the specific index
            if (galleryAdv.currentIndex != 0) {
                galleryAdv.goto(0);
            }
        })

    $("img.#thumb2")
        .mouseover(function() {
            galleryAdv.pause();
            if (galleryAdv.currentIndex != 1) {
                galleryAdv.goto(1);
            }
        })


    $("img.#thumb3")
        .mouseover(function() {
            galleryAdv.pause();
            if (galleryAdv.currentIndex != 2) {
                galleryAdv.goto(2);
            }
        })


    $('#slideshow')
    .mouseover(function() {
        //stop slideshow
        galleryAdv.pause();
    })


    .click(function() {
        //alert(galleryAdv.currentIndex);
        if (galleryAdv.currentIndex === 0)
            window.location = link3;
        if (galleryAdv.currentIndex === 1)
            window.location = link1;
        if (galleryAdv.currentIndex === 2)
            window.location = link2;
        return false;
    });

});