function Paging() {}
	
	Paging.Initialize = function()
	{
		var obj = document.getElementById("paging");
		obj.CurrentPage = 1;
		obj.Pages = new Array();
		
	    var mode = Paging.GetQueryStringValue("mode", "default").toLowerCase();
		var panel = document.getElementById("panel");
	    for (var i = 0; i < panel.childNodes.length; i++)
	    {
	        if (panel.childNodes[i].tagName == "DIV" && panel.childNodes[i].className == "page")
	        {
	            panel.childNodes[i].id = "page_" + (i + 1);
	            panel.childNodes[i].style.display = (mode == "print") ? "block" : "none";
	            obj.Pages.push(panel.childNodes[i]);
	        }
	    }
		
	    var page = Number(Paging.GetQueryStringValue("page", 1));
	    if (page < 1) page = 1;
	    if (page > obj.Pages.length) page = obj.Pages.length;
	    
	    obj.CurrentPage = page;
	    if (obj.Pages.length > 0)
            obj.Pages[obj.CurrentPage - 1].style.display = "block";
	    
		obj.Next = Paging.Next;
		obj.Previous = Paging.Previous;
		obj.SetPage = Paging.SetPage;
		obj.SetControls = Paging.SetControls;
		
		var previous = document.getElementById("page_previous");
		previous.Paging = obj;
		previous.onclick = Paging.PreviousOnClick;
		
		var next = document.getElementById("page_next");
		next.Paging = obj;
		next.onclick = Paging.NextOnClick;
		
		$("#page_total").text(obj.Pages.length);
		
		obj.SetControls();
	}
	
	Paging.GetQueryStringValue = function(key, defaultValue)
    {
        if (defaultValue == null) defaultValue = "";
         
        key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
        var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
        var qs = regex.exec(window.location.href);
        
        return (qs == null ? defaultValue : qs[1]);
    }
	
	Paging.Next = function()
	{
		this.SetPage(this.CurrentPage + 1);
	}
	
	Paging.Previous = function()
	{
		this.SetPage(this.CurrentPage - 1);
	}
	
	Paging.SetPage = function(page)
	{
		if (page < 1 || page > this.Pages.length || page == this.CurrentPage)
			return;
		
	    var outDirection = (page < this.CurrentPage) ? 'right' : 'left';
	    var inDirection = (page > this.CurrentPage) ? 'right' : 'left';
		
	    Paging.SlideOut(this.Pages[this.CurrentPage - 1].id, outDirection, function(){
			    var paging = document.getElementById("paging")
			    paging.CurrentPage = page;
			    paging.SetControls();
			    Paging.SlideIn(paging.Pages[paging.CurrentPage - 1].id, inDirection);
		    });
	}
	
	Paging.SlideIn = function(pageId, direction, callback)
	{
		$("#"+pageId).show("slide", {'direction': direction}, 800, callback);
	}
	
	Paging.SlideOut = function(pageId, direction, callback)
	{
		$("#"+pageId).hide("slide", {'direction': direction}, 600, callback);
	}
	
	Paging.SetControls = function()
	{
		$("#page_current").text(this.CurrentPage);
		
		document.getElementById("page_previous").className = (this.CurrentPage == 1) ? "disabled" : "";
		document.getElementById("page_next").className = (this.CurrentPage == this.Pages.length) ? "disabled" : "";
		document.getElementById("paging").className = (this.Pages.length <= 1) ? "hide" : "";
	}
	
	Paging.PreviousOnClick = function()
	{
		document.getElementById("paging").Previous();
		return false;
	}
	
	Paging.NextOnClick = function()
	{
		document.getElementById("paging").Next();
		return false;
	}