﻿$(document).ready(function () {
    for (id in g_icoSlideShows) {
        if ($('#' + id + ' #icoslideshow-entries').length > 0) {
            var slideShow = new IcoImageSlideShow.SlideShow(id, g_icoSlideShows[id].webPartProperties);
            slideShow.start();
        }        
    }

    var maxImageHeight = 0;
    $('#icoslideshow-entries .content').each(function (index, item) {
        if ($(item).height() > maxImageHeight) {
            maxImageHeight = $(item).height();
        }
    });
    if (maxImageHeight > 0) {
        maxImageHeight += 30;
    }
    $('#icoslideshow-entries.Bilderreihe').height(maxImageHeight);
});

_EnsureJSNamespace('IcoImageSlideShow');

IcoImageSlideShow.SlideShow = function (id, props) {
    this.webPartId = id;
    this.properties = props;

    $('#' + this.webPartId + ' #icoslideshow-control').toggle(function () {
        $('#' + this.webPartId + ' #icoslideshow-entries').cycle('pause');
        $(this).removeClass("pause");
        $(this).addClass("play");
    }, function () {
        $('#' + this.webPartId + ' #icoslideshow-entries').cycle('resume');
        $(this).removeClass("play");
        $(this).addClass("pause");
    });

    $('#' + this.webPartId + ' #icoslideshow-next').bind('click', { self: this }, this.next);
    $('#' + this.webPartId + ' #icoslideshow-back').bind('click', { self: this }, this.back);
};

IcoImageSlideShow.SlideShow.prototype = {
    start: function (startingslide) {
        startingslide = startingslide || 0;
        $('#' + this.webPartId + ' #icoslideshow-entries').cycle('stop');
        $('#' + this.webPartId + ' #icoslideshow-entries').cycle({
            fx: this.properties["SlideMode"],
            startingSlide: startingslide,
            timeout: this.properties["SlideInterval"],
            speed: this.properties["SlideSpeed"],
            delay: -1000,
            pager: '#' + this.webPartId + ' #icoslideshow-paging'
        });
        if (this.properties["SlideAutoStart"] != "True") {
            if ($('#icoslideshow-control').length > 0) {
                $('#icoslideshow-control').trigger('click');
            } else {
                $('#' + this.webPartId + ' #icoslideshow-entries').cycle('pause');
            }
        }
    },
    next: function (event) {
        $('#' + event.data.self.webPartId + ' #icoslideshow-entries').cycle('next');
    },
    back: function (event) {
        $('#' + event.data.self.webPartId + ' #icoslideshow-entries').cycle('prev');
    }
};


var lastSelectedListSmtPickerId = '';
function mso_launchListSmtPicker(textboxId) {
    if (!document.getElementById) return;

    var listTextBox = document.getElementById(textboxId);
    if (listTextBox == null) return;

    var serverUrl = '\u002f';

    var callback = function (results) {
        if (results == null
                        || results[1] == null
                        || results[3] == null) return;

        lastSelectedListSmtPickerId = results[0];
        var listUrl = '/';
        if (results[3].charAt(0) == '/') results[3] = results[3].substring(1);
        listUrl = listUrl + results[3];
        listTextBox.value = listUrl;
    };
    LaunchPickerTreeDialog('CbqPickerSelectListTitle', 'CbqPickerSelectListText', 'websLists', '', serverUrl, lastSelectedListSmtPickerId, '', '', '/_layouts/images/smt_icon.gif', '', callback, '', '');

}

