jQuery(document).ready(function(e){

    /*
     * Code for ANSER THIS button
     */

    jQuery('#twitter-contest-answer-this-button').click(function(){
	jQuery('#twitter-contest-answer-form-main').show();
	jQuery(this).hide();
	console.log('test');
    });//end of click bind


    /*
     *	AJAXify answer form
     */
    
    // bind 'answer form' and provide a simple callback function
    // prepare Options Object
    var options = {
	target:     '#twitter-contest-answer-form-main'
    };

    jQuery('#twitter-contest-answer-form').ajaxForm(options);



    /*
     * Pagination Code
     */


    //Global
    var globalItemsPerPage = 5;
    
    //make all 'li' hidden
    function hideAll(){
	jQuery('#twitter-contest-ans-list ul li').each( function(index){
	    jQuery(this).hide();
	})
    }

    
    function rtTwitterHandlePagination(new_page_index, pagination_container) {
	var startIndex = new_page_index * globalItemsPerPage ;
	hideAll();
	jQuery("#twitter-contest-ans-list ul li").slice(startIndex , startIndex + globalItemsPerPage ).each( function(index){
	    jQuery(this).show();
	})
    }

    //start pagination
    // First Parameter: number of items
    // Second Parameter: options object
    if(globalItemsPerPage < jQuery('#twitter-contest-ans-list ul li').length){
	jQuery(".twitter-contest-ans-list-pagination").pagination(jQuery('#twitter-contest-ans-list ul li').length, {
	    items_per_page: globalItemsPerPage ,
	    link_to: '#__id__',
	    callback:rtTwitterHandlePagination
	});
    }

})//end of doc ready