(function(jQuery) {
//
// plugin definition
//
jQuery.fn.mcPager = function(options) {
	// work out main settings (without metadata) - only do this work once per plugin call
	var main_opts = jQuery.extend({}, jQuery.fn.mcPager.defaults, options);

	// iterate and reformat each matched element
	return this.each(function() {
		$this = jQuery(this);

		// if metadata is present, extend main_opts, otherwise just use main_opts
		var o = jQuery.meta ? jQuery.extend({}, main_opts, $this.data()) : main_opts;

		jQuery(document).unbind('update.pager').bind('update.pager', function(e, data) {
//		jQuery(document).bind('update.pager', function(e, data) {
// DP_Debug.dump(data, 'Pager - Data', true, 3);
			
			if (data.cid) {
				if (data.pageCount && data.pageCount==1) {
					$this.hide();
				} else {
					$this.show();
//					jQuery('.mcChannelTitle').html(data.channelName + " (" + data.itemCount + ")");
					jQuery(o.pageNum, $this).html(data.page);
					jQuery(o.pageCount, $this).html(data.pageCount);

					jQuery(o.btnRight, $this).attr("href",'?cid=' + data.cid + '&page=' + (data.page+1));
					jQuery(o.btnLeft, $this).attr("href",'?cid=' + data.cid + '&page=' + (data.page-1));

					if (data.page<2)				jQuery(o.btnLeft, $this).hide();
					if (data.page>=data.pageCount)	jQuery(o.btnRight, $this).hide();
				}
			} else {
				$this.hide();
//				jQuery('.mcChannelTitle').html("A l'affiche");
			}

		});

	});
};

//
// define and expose our format function
//
jQuery.fn.mcPager.format = function(txt) {
	return '<strong>' + txt + '</strong>';
};

jQuery.fn.mcPager.defaults = {
	html		: '<div style="float:right;width:44px;"><a href="#" class="page-right"></a><a href="#" class="page-left"></a></div>page <span class="mcVideoListPage"></span> / <span class="mcVideoListPageCount"></span>',
	btnLeft		: ".page-left",
	btnRight	: ".page-right",
	pageNum		: ".mcVideoListPage",
	pageCount	: ".mcVideoListPageCount"
};

//
// end of closure
//
})(jQuery);