// function frontSlideImage image

frontSlideImage = function (strSelector, strSelectorButton, strTextDesc, timeDelay) {
    var tOut;
    var curindex = 0;
    var maxindex = 0;
    var preIndex = -1;
    var leftSlide = 0;
    maxindex = $(strSelector).length;
    $('.innerSlide').width(maxindex * 55);
    if (maxindex >= 2) {
        if (timeDelay > 0) {
            autochange($(strSelector + ":eq(" + curindex + ")"));
        }
        else {
            changimage($(strSelector + ":eq(" + curindex + ")"));
        }
    }
    else {
        $(strSelectorButton + ":eq(" + curindex + ")").addClass("active");
        $(strSelector + ":eq(" + curindex + ")").fadeIn(800);
        if (strTextDesc != '') {
            $(strTextDesc + ".active").removeClass("active");
            $(strTextDesc + ":eq(" + curindex + ")").addClass("active");
        }
        var curthumb = $(strSelectorButton + ":eq(" + curindex + ")");
        $('#sceneTip').text(curthumb.children('.sceneTip').text());
        $('#sceneTip').css('left', 105).show();
    }
    $(strSelectorButton).click(function () {
        curindex = $(strSelectorButton).index($(this));
        changimage($(strSelector + ":eq(" + curindex + ")"));

    });
    $('#navCtrl .pause').click(function () {
        if ($(this).hasClass('play')) {
            autochange($(strSelector + ":eq(" + curindex + ")"));
            $(this).removeClass('play');
        }
        else {
            clearTimeout(tOut);
            $(this).addClass('play');
        }

    });
    $('#navCtrl .prev').click(function () {
        if (curindex > 0) curindex--;
        changimage($(strSelector + ":eq(" + curindex + ")"));
    });
    $('#navCtrl .next').click(function () {
        if (curindex < maxindex - 1) curindex++;
        changimage($(strSelector + ":eq(" + curindex + ")"));
    });
    function changimage(obj) {
        if (preIndex != curindex) {
            $(strSelector + ":eq(" + preIndex + ")").fadeOut(800);
            $(strSelector + ":eq(" + curindex + ")").css("z-index", 1);
            $(obj).css("z-index", 2)
            preIndex = curindex;
            $(strSelectorButton + ".active").removeClass("active");
            $(strSelectorButton + ":eq(" + curindex + ")").addClass("active");
            var curthumb = $(strSelectorButton + ":eq(" + curindex + ")");
            if (strTextDesc != '') {
                $(strTextDesc + ".active").removeClass("active");
                $(strTextDesc + ":eq(" + curindex + ")").addClass("active");
            }
            leftSlide = -275 * Math.floor(curindex / 5);
            $('.innerSlide').animate({ left: leftSlide });
            $('#sceneTip').text(curthumb.children('.sceneTip').text());
            $('#sceneTip').css('left', curthumb.position().left + 105 + leftSlide).show();
            $(obj).fadeIn(800);
        }
    }
    function autochange(obj) {
        clearTimeout(tOut);
        changimage(obj)
        tOut = setTimeout(function () {
            curindex++;
            if (curindex == maxindex) {
                curindex = 0;
            }
            autochange($(strSelector + ":eq(" + curindex + ")"));
        }, timeDelay);
    }
};

function gallerySlide(parentId, selectorContent, selectorItem, selectorTargetImage, selectorTargetText, containerWidth, itemWidth, marginLeft, crollSpeed, clickable) 
{
    var numItem = $(selectorItem).length;
    var slideContent = $(selectorContent);
    var playing = false;
    var slideWidth = (numItem * itemWidth)-marginLeft;
    var minLeft = containerWidth - slideWidth;
    var slideLeft = 0;
    var stepLeft = 0;
    var stepRight = (slideWidth-containerWidth) > (containerWidth+marginLeft) ? (containerWidth+marginLeft) :(slideWidth-containerWidth);
    slideContent.width(slideWidth)
    if (clickable==1) 
    {
        frontSlideImage(selectorTargetImage, selectorItem, selectorTargetText,0);
    }
    $('#'+parentId +' .lButton').click(function () {
        if (playing == true) return;
        if (slideLeft < 0) {
            playing = true;
            slideContent.animate({
                opacity: 0.8,
                left: '+=' + stepLeft
            }, stepLeft + crollSpeed, function () {
                slideContent.animate({
                    opacity: 1
                });
                playing = false;
                slideLeft += stepLeft;
                stepLeft = -slideLeft > (containerWidth+marginLeft) ? (containerWidth+marginLeft) : -slideLeft;
                stepRight = (slideWidth + slideLeft - containerWidth) > (containerWidth+marginLeft) ? (containerWidth+marginLeft) : (slideWidth + slideLeft - containerWidth);
            });
        }
    });
    $('#' + parentId + ' .rButton').click(function () {
        if (playing == true) return;
        if (slideLeft > minLeft) {
            playing = true;
            slideContent.animate({
                opacity: 0.8,
                left: '-=' + stepRight
            }, stepRight + crollSpeed, function () {
                slideContent.animate({
                    opacity: 1
                });
                playing = false;
                slideLeft -= stepRight;
                stepLeft = -slideLeft > (containerWidth+marginLeft) ? (containerWidth+marginLeft) : -slideLeft;
                stepRight = (slideWidth + slideLeft-containerWidth) > (containerWidth+marginLeft) ? (containerWidth+marginLeft) : (slideWidth + slideLeft-containerWidth);
            });
        }
    });
}

function openGallery() {
    winGallery = open('/gallery.aspx', "Gallery", "width=888,height=790,scrollbars=no,status=no,toolbar=no,menubar=no,titlebar=no,personalbar=no,resizable=1,location=0");
}
