// JavaScript Document

	// This is a very simple demo that shows how a range of elements can
	// be paginated.

	/**
	 * 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
	 */
	function pageselectCallback(page_index, jq){
		var new_content = $('div#hidden-content div.page:eq('+page_index+')').clone().hide('slow').fadeIn(500);
		$('#blog-items').empty().append(new_content);
		return false;
	}
   
	/** 
	 * Callback function for the AJAX content loader.
	 */
	function initPagination() {
		var num_entries = $('div#hidden-content div.page').length;
		// Create pagination element
		$("#blog-pagination-nav").pagination(num_entries, {
			num_edge_entries: 1,
			num_display_entries: 10,
			callback: pageselectCallback,
			items_per_page:1
		});
	 }
	

	
	$(document).ready(function(){
						
		initPagination(); // Initialise Pagination
		
		// Only allow ratings once stars selected
            $( "input#star-rating-submit" ).click( function(e) {
		if( $(this).parent().find( "input:radio:checked" ).val() == undefined ) {
		    $( "div#rating-error" ).empty().append( "Please choose a rating star before voting on this post." );
		    e.preventDefault();
		}
	    });
		// View All functionality		
		$("div#blog-view-all a").click(function(event) {
			event.preventDefault();
			$("div#blog-pagination, div#blog-items, div#blog-view-all").hide(10);
			$("div#hidden-content, div#paginate").fadeIn(750);
		});
		// Revert back to Paginate functionality
		$("div#paginate a").click(function(event) {
			event.preventDefault();							   
			$("div#blog-pagination, div#blog-items, div#blog-view-all").fadeIn(750);
			$("div#hidden-content, div#paginate").hide(10);
		});
		
							   
	});
