(function($){
galleryspecial = function(gall_dir) {

//how many photos to display SHOW PER PAGE
	/* **************************** */
	var limit = 20;
	/* **************************** */

gall_dir = "gallery/"+gall_dir+"/";

	//set the value of our hidden input fields
	$('#current_page').val(1);
	$('#show_per_page').val(limit);

	//TOTAL number of photos; 
	var numphotos;
	//NUMBER OF PAGES DISPLAYED
	var number_of_pages;
	
	$.ajax({
                 type: "GET",
                 url: gall_dir+"album.xml",
                 dataType: "xml",
                 cache: false,
                 success: function(xml) {
		$("#gallerybox").empty();

		numphotos = $(xml).find("photo").length;
		number_of_pages = Math.ceil(numphotos/limit);               

		//function to display pictures
		function callingpage(start,end) {
                 	$(xml).find('photo').slice(start,end).each(function(i){
                 	//if(i<gx){return true;};
			var name_text = $(this).find('pixname').text();
			var caption_text = $(this).find('caption').text();
			
                 	 $('<div class="gall_imglink"><\/div>')
                          .html('<a rel="example_group4" href="' + gall_dir +  '/large/'+name_text+'" title="'+caption_text+'" ><img src="' + gall_dir + 'small/'+name_text + '"  /><\/a>')  
                             .appendTo('#gallerybox');
			}); //close each
		};


	function go_to_page(page_num){
	//get the number of items shown per page
	var show_per_page = parseInt($('#show_per_page').val());

	//get the element number where to start the slice from
	var start_from = (page_num -1)* show_per_page;

	//get the element number where to end the slice
	var end_on = start_from + show_per_page;

	callingpage(start_from,end_on);

	$('.page_link[longdesc=' + page_num +']').addClass('current').siblings('.current').removeClass('current');

	//update the current page input field
	$('#current_page').val(page_num);
	};

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

//initialise - no number pagination display yet so no live needed
go_to_page(1);

// display the number pagination navigation display
var navigation_html = '<a class="back" href="#null"><span>Prev<\/span><\/a>';
var current_link = 1;
	while(number_of_pages >= current_link){
		navigation_html += '<a class="page_link" href="#null" longdesc="' + current_link +'"><span>'+ (current_link) +'<\/span><\/a>';
		current_link++;
	}
	navigation_html += '<a class="next" href="#null" ><span>Next<\/span><\/a>';
	$('.buttons').html(navigation_html);
//add current class to the first page link
	$('.buttons .page_link:first').addClass('current');

$(".back").live('click', function(){
	$("#gallerybox").empty();
	previous();
});

$(".next").live('click', function(){
	$("#gallerybox").empty();
	next();
});

$(".page_link").live('click', function(){
	$("#gallerybox").empty();
	go_to_page($(this).attr('longdesc'));
});


		var greview = $(xml).find('review').text();

		//gdate = "Gallery event review on "+ gdate;
		//is page 'recent gallery' page or 'profile' gallery
    		            
		$('#galleryreview').html(greview); 
		$('.jScrollPaneContainer').jScrollPane();

                 } //success               
	});  //ajax




		$("a[rel=example_group4]").livequery(function(){		
		$(this).fancybox({
		 		'titleShow'     : true,
		 		'titlePosition'  : 'inside',
				'transitionIn'		: 'elastic',
				'transitionOut'		: 'elastic',
				'titleFormat' : function(){ return '<span style="color:#555;font-size:14px;font=weight:bold">'+this.title+'<\/span>';}			
		});		
		});
return false;




          }           
})(jQuery);

