(function ($) {
	//shortcut for fancyBox object
	var F = $.fancybox;

	//Add helper object
	F.helpers.buttons = {
		tpl: '<div id="fancybox-buttons"><ul><li><a class="btnPrev" title="Zur&uuml;ck" href="javascript:$.fancybox.prev();">Previous</a></li><li><a class="btnPlay" title="Slideshow" href="javascript:$.fancybox.play();;">Play</a></li><li><a class="btnNext" title="Vorw&auml;rts" href="javascript:$.fancybox.next();">Vorw&auml;rts</a></li><li><a class="btnToggle" title="Gr&ouml;&szlig;e &auml;ndern" href="javascript:$.fancybox.toggle();">Toggle</a></li><li><a class="btnClose" title="Schliessen" href="javascript:$.fancybox.close();">Schliessen</a></li></ul></div>',
		list: null,
		buttons: {},

		update: function () {
			var toggle = this.buttons.toggle.removeClass('btnDisabled btnToggleOn');

			//Size toggle button
			if (F.current.canShrink) {
				toggle.addClass('btnToggleOn');

			} else if (!F.current.canExpand) {
				toggle.addClass('btnDisabled');
			}
		},

		beforeShow: function () {
			//Increase top margin to give space for buttons
			F.current.margin[0] += 30;
		},

		onPlayStart: function () {
			if (this.list) {
				this.buttons.play.text('Pause').addClass('btnPlayOn');
			}
		},

		onPlayEnd: function () {
			if (this.list) {
				this.buttons.play.text('Play').removeClass('btnPlayOn');
			}
		},

		afterShow: function (opts) {
			if (!this.list) {
				this.list = $(opts.tpl || this.tpl).appendTo('body');

				this.buttons = {
					prev : this.list.find('.btnPrev'),
					next : this.list.find('.btnNext'),
					play : this.list.find('.btnPlay'),
					toggle : this.list.find('.btnToggle')
				}
			}

			//Prev
			if (F.current.index > 0 || F.current.loop) {
				this.buttons.prev.removeClass('btnDisabled');
			} else {
				this.buttons.prev.addClass('btnDisabled');
			}

			//Next / Play
			if (F.current.loop || F.current.index < F.group.length - 1) {
				this.buttons.next.removeClass('btnDisabled');
				this.buttons.play.removeClass('btnDisabled');

			} else {
				this.buttons.next.addClass('btnDisabled');
				this.buttons.play.addClass('btnDisabled');
			}

			this.update();
		},

		onUpdate: function () {
			this.update();
		},

		beforeClose: function (opts) {
			if (this.list) {
				this.list.remove();
			}

			this.list = null;
			this.buttons = {};
		}
	};

}(jQuery));
