﻿//* Code is loaded via editorGalleryLoader.js

	//* Previous & Next Controls
	jQuery('.PromotionGallery.PrevNextPagination').each(function (index) {

		var gallery = jQuery(this);
		var galleryWidth = jQuery('.slideShowPreviousNext img', gallery).width();

		//* Set the gallery to the width of the first image
		gallery.width(galleryWidth);

		jQuery('.slideShowPreviousNext', gallery).each(function () {

			var current = jQuery(this);
			var currentSlide = jQuery('.slidesshowPreviousNextControls', gallery);
			var prev = currentSlide.find('a.prev'), next = currentSlide.find('a.next');
			current.cycle({
				prev: prev,
				next: next,
				fx: 'fade',
				speed: 500,
				timeout: 4500,
				pause: 1
			});
		});

		jQuery('.slidesshowPreviousNextControls .prev', gallery).css('visibility', 'visible');
		jQuery('.slidesshowPreviousNextControls .next', gallery).css('visibility', 'visible');
		jQuery('.slideShowPreviousNext img', gallery).show();
	});


	//* Numeric Controls
	jQuery('.PromotionGallery.NumericPagination').each(function (index) {

		var gallery = jQuery(this);
		var galleryWidth = jQuery('.slideshowNumbers img', gallery).width();

		//* Set the gallery to the width of the first image
		gallery.width(galleryWidth);

		jQuery('.slideshowNumbers', gallery).each(function () {

			var slideshowNumbers = jQuery(this);

			slideshowNumbers.before('<div class="slideshowNumbersNav"></div>').cycle({
				fx: 'fade',
				speed: 500,
				timeout: 4500,
				pager: slideshowNumbers.prev(),
				slideExpr: 'img'
			});

		});
	});


	//* Text Content
	jQuery('.slidesshowTextContent').each(function () {
		var current = jQuery(this);
		current.cycle({
			fx: 'scrollRight',
			delay: 1,
			pause: 2
		});
	});


	//* Play, Pause, Previous, & Next Controls
	jQuery('.PromotionGallery.ControlPanelPagination').each(function (index) {

		var gallery = jQuery(this);
		var galleryWidth = jQuery('.slidesshowControlPanel img', gallery).width();

		//* Set the gallery to the width of the first image
		gallery.width(galleryWidth);

		//* Set the control panel to the image width
		jQuery('.slidesshowControlPanelBtns', gallery).width(galleryWidth);

		/* Control Panel */
		jQuery('.slidesshowControlPanel', gallery).each(function () {

			var current = jQuery(this), currentSlide = current.closest('.slidesshowControlPanelControls');
			var prev = currentSlide.find('a.prev'), next = currentSlide.find('a.next');
			var playPauseButton = currentSlide.find('a.playPauseButton');

			playPauseButton.toggle(function () {

				jQuery(this).removeClass('pause');
				jQuery(this).addClass('play');

				current.cycle('pause'); return false;

			}, function () {

				jQuery(this).removeClass('play');
				jQuery(this).addClass('pause');

				current.cycle('resume'); return false;

			});

			current.cycle({
				prev: prev,
				next: next,
				fx: 'fade',
				speed: 500,
				timeout: 4500
			});
		});



		gallery.hover(function () {

			jQuery('.slidesshowControlPanelBtns', gallery).css('visibility', 'visible').hide().fadeIn('fast');
			
		},
		function () {

			jQuery('.slidesshowControlPanelBtns', gallery).fadeOut();
		}
		);

	});
