(function ($) {
	$.fn.extend({
		cycleShow: function (settings) {
			settings = $.extend({}, $.fn.cycleShow.defaults, settings);
			
			return $(this).each(function () {
				var self = $(this),
					ul = $('ul', this);
				
				switch (settings.source) {
					case 'xjax':
						DDC.Api.DataAccessManager.get({
							url: settings.xjaxUrl,
							params: settings.xjaxParams,
							callback: function (data) {
								// build the markup
								for (var i = 0; i < data.length; i++) {
									settings.writeItem(data[i], ul);
								}
								$(ul).cycle({
									timeout: settings.timeout,
									pause: true,
									cleartype: true
								});
								$(self).removeClass('cycleshowLoading');
							}
						});
						break;
					default:
						break;
				}
			});
		}
	});
	$.fn.extend($.fn.cycleShow, {
		defaults: {
			source: 'xjax',
			xjaxUrl: null,
			xjaxParams: {},
			timeout: 6000,
			writeItem: function (item, ul) {
				var li = '<li>' +
					'<strong><a style="background-image: url(' + (item.img || '') + ');" href="' + (item.target || '#') + '">' + (item.title || '') + '</a></strong>' +
					'<p class="description"><a href="' + (item.target || '#') + '">' + (item.disclaimer || '') + '</a></p>' +
					'</li>';
				$(ul).append(li);
			}
		}
	});
})(jQuery);
