	//PAGINATION
	$(document).ready(function(){
	
	//how much items per page to show
	var show_per_page = 20; 
	//getting the amount of elements inside content div
	var number_of_items = $('#download-page-featured').children().size();

	//calculate the number of pages we are going to have
	var number_of_pages = Math.ceil(number_of_items/show_per_page);
	
	//set the value of our hidden input fields
	$('#current_page').val(0);
	$('#show_per_page').val(show_per_page);
	
	//now when we got all we need for the navigation let's make it '
	
	/* 
	what are we going to have in the navigation?
		- link to previous page
		- links to specific pages
		- link to next page
	*/
	var navigation_html = '<div id="downloadsPagination"><ul class="pagination"><li>Pages:</li>';
	var current_link = 0;
	navigation_html += '<li class="prev" style="display:none"><a href="javascript:prev();">Previous</a></li>';
	while(number_of_pages > current_link){
		
		navigation_html +=' <li class="page_link" longdesc="' + current_link +'"><a  href="javascript:go_to_page(' + current_link +')"  title="'+ (current_link + 1) +'">'+ (current_link + 1) +'</a></li>';
		
		//navigation_html += '<a class="page_link" href="javascript:go_to_page(' + current_link +')" longdesc="' + current_link +'">'+ (current_link + 1) +'</a>';
		current_link++;
	}
	
	
	navigation_html += '<li class="next"><a href="javascript:next();">Next</a></li>';
	
	navigation_html += '<li class="viewall"><a href="javascript:viewall();">View all</a></li></ul></div>';
	
	if(number_of_pages>1)
	{
	$('.footer-pag').html(navigation_html);
	
	//add active_page class to the first page link
	$('.pagination .page_link:first').addClass('currentPage');
	}
	//hide all the elements inside content div
	$('#download-page-featured').children().css('display', 'none');
	
	//and show the first n (show_per_page) elements
	$('#download-page-featured').children().slice(0, show_per_page).css('display', 'block');
	
});

function next(){

	new_page = parseInt($('#current_page').val()) + 1;
	//if there is an item after the current active link run the function
	if($('.currentPage').next('.page_link').length==true){
		go_to_page(new_page);
	}
	
}

function prev(){

	new_page = parseInt($('#current_page').val()) - 1;
	
	//if there is an item after the current active link run the function
	
		go_to_page(new_page);
	
	
}

function viewall(){
	
	var number_of_items = $('#download-page-featured').children().size();
	
	$('#download-page-featured').children().css('display', 'none').slice(0, number_of_items).css('display', 'block');
	$('.pagination').children().removeClass('currentPage');
	$('.viewall').addClass('currentPage');
	$('.next').css('display', 'none');
	$('.prev').css('display', 'none');
	
}

function go_to_page(page_num){
	//get the number of items shown per page
	var show_per_page = parseInt($('#show_per_page').val());
	
	var show_per_page = 20; 
	//getting the amount of elements inside content div
	var number_of_items = $('#download-page-featured').children().size();

	//calculate the number of pages we are going to have
	var number_of_pages = Math.ceil(number_of_items/show_per_page);
			
	//get the element number where to start the slice from
	start_from = page_num * show_per_page;
	if(page_num==number_of_pages-1)
	{
		$('.next').css('display', 'none');
	}
	else
	{
		$('.next').css('display', 'inline');
	}
	
	if(page_num > 0)
	{
		$('.prev').css('display', 'inline');
	}
	else
	{
		$('.prev').css('display', 'none');
	}
	
	
	//get the element number where to end the slice
	end_on = start_from + show_per_page;
	
	//hide all children elements of content div, get specific items and show them
	$('#download-page-featured').children().css('display', 'none').slice(start_from, end_on).css('display', 'block');
	
	/*get the page link that has longdesc attribute of the current page and add active_page class to it
	and remove that class from previously active page link*/
	$('.page_link[longdesc=' + page_num +']').addClass('currentPage').siblings('.currentPage').removeClass('currentPage');
	$('.viewall').removeClass('currentPage');
	//update the current page input field
	$('#current_page').val(page_num);
}
//END PAGINATION
	
$(document).ready(function(){
	$('#downloadSelect').sSelect();
});

jQuery(document).ready(function() {

	jQuery("#access LI").hover(
      function () {
        jQuery(this).addClass("dshover");
      },
      function () {
       jQuery(this).removeClass("dshover");
      }
    );
	
	$('#downloadSelect').bind('change',
		function() {
			var select_value = $(this).find(':selected').val();
			var current_location = window.location;
			
			if (/sortby/m.test(current_location)) {
				
				var loc = window.location.href;
				loc = loc.replace(/(sortby=[a-z]*)/mg, "sortby="+select_value);
				
				window.location = loc;
			}
			else
			{
			if (/\?/m.test(current_location))
			{
				window.location = current_location + '&sortby='+select_value;
			}
			else
			{
				window.location = current_location + '?sortby='+select_value;
			}
}			
			
		});
});

