
	var book = {
		gallery:'',
		width:0,
		height:0,
		startpage:'01',
		maxpages:'',
		zoomLevel:0,
		changePage:function(page,href){
			if(page==this.startpage) 
			{
				$('.prev').css('display','none');
				$('.next').css('display','inline');
			}
			else if(page==this.maxpages) 
			{
				$('.prev').css('display','inline');
				$('.next').css('display','none');
			}
			else
			{
				$('.prev').css('display','inline');
				$('.next').css('display','inline');		
			}
			
			$('.book-output .container').html('<img src="'+href+'" class="page"/>');
			$('.page-num').html(href.substr((book.gallery.length+1),2));
			this.setZoom(this.zoomLevel);

			page++;
			page = ""+page;
			var next_href=$('a[href^='+this.gallery+'/'+page+']').attr('href');
			$('.preload-next').html('<img src="'+next_href+'"/>');
			
			page = page - 2;
			page = ""+page;
			var prev_href=$('a[href^='+this.gallery+'/'+page+']').attr('href');
			$('.preload-prev').html('<img src="'+prev_href+'"/>');
		},
		init:function(gallery,width,height){
			this.maxpages=""+$('.book-section').length;
			this.gallery=gallery;
			this.width=width;
			this.height=height;
			$('.book-section').click(function(){
				var href=$(this).attr('href');
				var page=href.substr((book.gallery.length+1),2);
				book.changePage(page,href);				
				return false;
			});
			
			$('.book .next').click(function(){
				book.nextPage();
				return false;
			});
	
			$('.book .prev').click(function(){
				book.prevPage();
				return false;
			});
	
			$('.book .zoom-in').click(function(){
				book.zoom('in');
				return false;
			});
	
			$('.book .zoom-out').click(function(){
				book.zoom('out');
				return false;
			});
			
			$('.book .book-output').show();
		},
		nextPage: function(){
			var page = parseInt($('.book-output img').attr('src').substr((book.gallery.length+1),2));
			page++;
			page = ""+page;
			page = page.pad(2,'0',0);
			
			var href=$('a[href^='+this.gallery+'/'+page+']').attr('href');
			this.changePage(page,href);
		},
		prevPage: function(){
			var page = parseInt($('img.page').attr('src').substr((book.gallery.length+1),2));
			page--;
			page = ""+page;
			page = page.pad(2,'0',0);
			var href=$('a[href^='+this.gallery+'/'+page+']').attr('href');
			this.changePage(page,href);
		},
		setZoom:function(level){
			this.zoomLevel = level;
			var z = this.zoomLevel;
			var w = this.width;
			var h = this.height;
			$('img.page').attr('width',w+(w*(z/10))).attr('height',h+(h*(z/10)));
		},
		zoom: function(in_out){
			if(in_out=='in') this.setZoom(this.zoomLevel+1);
			else this.setZoom(this.zoomLevel-1);
			
		}
	};

	String.prototype.pad = function(l, s, t){
	return s || (s = " "), (l -= this.length) > 0 ? (s = new Array(Math.ceil(l / s.length)
		+ 1).join(s)).substr(0, t = !t ? l : t == 1 ? 0 : Math.ceil(l / 2))
		+ this + s.substr(0, l - t) : this;
	};