function fancySlider_tryDemo(dropDown)
{
    var selectedValue = dropDown.value;
    document.location.href = "?slider=" + selectedValue;
}

function demopage_switchslider(mainDivID)
{
    var isDemo = false;

    var a = window.location.href.substring(window.location.href.indexOf('?') + 8);
    
    if (a !== undefined && a !== '' && window.location.href.indexOf('?') > 0)
    {
        $("#" + mainDivID).find('.aviaslider').attr('id', a);
        isDemo = true;
    }

    return isDemo;
}

/*
https://www.potcakecollars.com/system/js/front/aviaslider-jquery-slideshow-source/documentation_html/
http://www.kriesi.at/themes/avisio/
http://www.kriesi.at/support/topic/avia-slider-adding-thumbnails-as-controls-like-in-the-avisio-theme

autorotation: true
autorotationSpeed:3

//slideControlls: should the controll bullets be displayed or not	
slideControlls: 'none'
*/
function doFancySlider(mainDivID, width, height, animSpeed, blockDelay) {

    $(document).ready(function () {
        var isDemo = demopage_switchslider(mainDivID);

        if (isDemo) {
            $("#" + mainDivID).find('#frontpage-slider').aviaSlider({
                blockSize: {
                    height: 80,
                    width: 80
                },
                transition: 'slide',
                display: 'all',
                transitionOrder: ['diagonaltop', 'diagonalbottom', 'topleft', 'bottomright', 'random']
            });
            $("#" + mainDivID).find('#diagonal-blocks').aviaSlider({
                blockSize: {
                    height: 80,
                    width: 80
                },
                transition: 'slide',
                display: 'diagonaltop',
                switchMovement: true
            });
            $("#" + mainDivID).find('#winding-blocks').aviaSlider({
                blockSize: {
                    height: 80,
                    width: 80
                },
                transition: 'slide',
                display: 'topleft',
                switchMovement: true
            });
            $("#" + mainDivID).find('#randomized-blocks').aviaSlider({
                blockSize: {
                    height: 80,
                    width: 80
                },
                transition: 'slide',
                display: 'random'
            });
            $("#" + mainDivID).find('#fading_curtain').aviaSlider({
                blockSize: {
                    height: 'full',
                    width: 40
                },
                display: 'topleft',
                transition: 'fade',
                betweenBlockDelay: 150,
                animationSpeed: 600,
                switchMovement: true
            });
            $("#" + mainDivID).find('#fading-top-curtain').aviaSlider({
                blockSize: {
                    height: 40,
                    width: 'full'
                },
                display: 'topleft',
                transition: 'fade',
                betweenBlockDelay: 150,
                animationSpeed: 600,
                switchMovement: true
            });
            $("#" + mainDivID).find('#fullwidth-fade-slider').aviaSlider();
            $("#" + mainDivID).find('#direction-fade-slider').aviaSlider({
                blockSize: {
                    height: 3,
                    width: 'full'
                },
                display: 'topleft',
                transition: 'fade',
                betweenBlockDelay: 10,
                animationSpeed: 400,
                switchMovement: true
            });
            $("#" + mainDivID).find('#droping-curtain').aviaSlider({
                blockSize: {
                    height: 'full',
                    width: 40
                },
                display: 'topleft',
                transition: 'drop',
                betweenBlockDelay: 80,
                animationSpeed: 800,
                switchMovement: true,
                slideControlls: 'items',
                appendControlls: '.aviaslider'
            })
        }
        else
        {
            /*jQuery('a[href$=jpg], a[href$=png], a[href$=gif], a[href$=jpeg]').prettyPhoto({
            theme: "light_square"
            });*/

            $("#" + mainDivID).find('#frontpage-slider').aviaSlider({
                blockSize: {
                    height: width,
                    width: width
                },
                showText: true,
                transition: 'slide',
                display: 'all',
                transitionOrder: ['diagonaltop', 'diagonalbottom', 'topleft', 'bottomright', 'random']
            });

            $("#" + mainDivID).find('#diagonal-blocks').aviaSlider({
                blockSize: {
                    height: height,
                    width: width
                },
                showText: true,
                transition: 'slide',
                display: 'diagonaltop',
                switchMovement: true
            });

            $("#" + mainDivID).find('#winding-blocks').aviaSlider({
                blockSize: {
                    height: height,
                    width: width
                },
                showText: true,
                transition: 'slide',
                display: 'topleft',
                switchMovement: true
            });

            $("#" + mainDivID).find('#randomized-blocks').aviaSlider({
                blockSize: {
                    height: height,
                    width: width
                },
                showText: true,
                transition: 'slide',
                display: 'random'
            });

            $("#" + mainDivID).find('#fading_curtain').aviaSlider({
                blockSize: {
                    height: 'full',
                    width: (width / 2)
                },
                showText: true,
                display: 'topleft',
                transition: 'fade',
                betweenBlockDelay: blockDelay,
                animationSpeed: animSpeed,
                switchMovement: true
            });

            $("#" + mainDivID).find('#fading-top-curtain').aviaSlider({
                blockSize: {
                    height: (height / 2),
                    width: 'full'
                },
                showText: true,
                display: 'topleft',
                transition: 'fade',
                betweenBlockDelay: blockDelay,
                animationSpeed: animSpeed,
                switchMovement: true
            });

            $("#" + mainDivID).find('#fullwidth-fade-slider').aviaSlider();

            $("#" + mainDivID).find('#direction-fade-slider').aviaSlider({
                blockSize: {
                    height: 3,
                    width: 'full'
                },
                showText: true,
                display: 'topleft',
                transition: 'fade',
                betweenBlockDelay: blockDelay,
                animationSpeed: animSpeed,
                switchMovement: true
            });

            $("#" + mainDivID).find('#droping-curtain').aviaSlider({
                blockSize: {
                    height: 'full',
                    width: (width / 2)
                },
                showText: true,
                display: 'topleft',
                transition: 'drop',
                betweenBlockDelay: blockDelay,
                animationSpeed: animSpeed,
                switchMovement: true,
                slideControlls: 'items',
                appendControlls: '.aviaslider'
            })
        }
    });
}



function getNewIndex(mainDivID, mIndex) {
    var index = -1;

    $("#" + mainDivID).find(".slidecontrolls").children("a").each(function (ind) {
        if ($(this).attr("class").indexOf("active_item") > 0) {
            index = ind;
        }
    });

    var totalSlides = $("#" + mainDivID).find(".slidecontrolls").children("a").length;
    index = index + mIndex;

    if (index < 0) {
        index = totalSlides - 1;
    }
    if (index >= totalSlides) {
        index = 0;
    }

    return index;
}

function moveFancySlider(mainDivID, mIndex) {
    var index = getNewIndex(mainDivID, mIndex);

    $("#" + mainDivID).find(".slidecontrolls").children("a").each(function (ind)
    {
        if (ind == index)
        {
            $(this).trigger('click');
        }
    });
}
