/**
 * reload/rebind Thickbox and Fancybox
 */
var reloadThickboxAndFancybox = function() {
	
	$('a.thickbox, area.thickbox, input.thickbox').unbind();
	tb_init('a.thickbox, area.thickbox, input.thickbox'); //pass where to apply thickbox
	
	/* Apply fancybox */
	$("a.cond").fancybox({
		'hideOnContentClick': true,
		'transitionIn'	:	'fade',
		'transitionOut'	:	'fade'
	});
};

/**
 * Callback function that displays the content.
 *
 * Gets called every time the user clicks on a pagination link.
 *
 * @param {int}page_index New Page index
 * @param {jQuery} jq the container with the pagination links as a jQuery object
 */
var handlePaginationClick = function (page_index, jq, target){    
    // Replace old content with new content
	$(target).empty();
	$(target).append( $(target + '-subset-' + page_index).html() );
    
    // Prevent click event propagation
    return false;
};

var conditionPaginationHandler = function (page_index, jq, target){    
    // Replace old content with new content
	$(target).empty();
	var items = $(target + '-subset-' + page_index);
	$(target).append( items.html().replace(/hidden-cond/gm,"cond") );
	
	reloadThickboxAndFancybox();
	
    // Prevent click event propagation
    return false;
};

var webtvPaginationHandler = function (page_index, jq, target){    
    // Replace old content with new content
	$(target).empty();
	var items = $(target + '-subset-' + page_index);
	$(target).append(items.html().replace(/\"top-hidden-/gm,"\"top-"));
    
	// animate list
	$(".voci dl").click(function() {	
		getRoleTopVideos($(this), function(target) {
			target.animate({"height": "toggle"}, 1000);
		});								
	});
	
    // Prevent click event propagation
    return false;
};

var pagination = function (target, totElem, page_items, callbackFunct) {
	$(target + '-pagination').pagination(totElem, {
		items_per_page:typeof page_items == "number" ? page_items : 5,
		load_first_page:true,
		link_to:'javascript:void(0);',
		callback: function (page_index, jq) {callbackFunct ? callbackFunct(page_index,jq,target) : handlePaginationClick(page_index,jq,target);}
	});
};

