function FormatNavLinks(PageNumber,Name,TotalAllowed,Total)
{
    var BeforePage = Math.ceil(TotalAllowed/2) - 1;
    var AfterPage = Math.floor(TotalAllowed/2);

    var NavStart;
    var NavEnd;   
    
    if(PageNumber == 1)
    {
        NavStart = 1;
        NavEnd = TotalAllowed;
    }
    else if(PageNumber == Total)
    {
        NavStart = Total - (TotalAllowed-1);
        NavEnd = Total;
    }
    else if(PageNumber >= (Total - (TotalAllowed-1)))
    {
        NavStart = (Total - (TotalAllowed-1));
        NavEnd = Total;
    }
    else
    {
        NavStart = ((PageNumber - BeforePage) > 1) ? PageNumber - BeforePage : 1;
        NavEnd = PageNumber + AfterPage;
    }
    
    for(var x = 1; x <= Total; x++)
    {
        var NavId = new String(Name + "NavPage" + x);
        
        if(document.getElementById(NavId) != null)
        {
            var NavLink = document.getElementById(NavId);
            
            if(x >= NavStart && x <= NavEnd)
            {
                NavLink.style.display = "block";
            }
            else
            {
                NavLink.style.display = "none";
            }
        }        
    }
}

        
        //These functions allow you to define how you want your content to be formatted
        var Content4Total = 0;
         function ContentFunction4(Content) 
        {
            for(var x=0; x < Content.length; x++)
            {
                var Page = Content[x];
                var html = new String();
                
	Content4Total += Page.length;		
                
                for(var y=0; y < Page.length; y++)
                {
                    var image = Page[y].image;
                    var title = Page[y].title;
                    var subtext = Page[y].subtext;
                    var url = Page[y].url;
                    html = html + new String("<div class='photoFlipper'><div class='image2'><img src='"+image+"' onmouseover='this.style.border=\"1px solid #3fcd50\"' onmouseout='this.style.border=\"1px solid #abaca9\"' style='border:1px solid #abaca9;' onclick='location.href=\""+url+"\"' /></div><div class='title'><span id=morePhotosFlipperType onmouseover='this.style.textDecoration=\"underline\"' onmouseout='this.style.textDecoration=\"none\"' onclick='location.href=\""+url+"\"'>"+title+"</span><div class='morePhotosFlipperTypeSubtext'>"+subtext+"</div></div></div>");                        
                }
                
                //The addPage method will create a new page and add the html string to it
                scrollbooth4.addPage(html);
            }
            
            
        }
                
        
        // ScrollBooth(Name,HolderWidth,HolderHeight,HolderID,NavID,NextID,BackID,ContentFunction)
        var scrollbooth4 = new ScrollBooth("scrollboothOne", 400, 400, "holder4", "nav4", "nextButton4", "backButton4", ContentFunction4);

                
        scrollbooth4.onscrollboothload = function(Name)
        {
            
        };
        scrollbooth4.onupdatenav = function(PageNumber,PageID)
        {
            
        };
        scrollbooth4.onaddpage = function(PageNumber,PageID)
        {            
            var end = Content4[0].length;
            document.getElementById("counter4").innerHTML = new String("1-" + end + " / " + Content4Total);

            FormatNavLinks(1,scrollbooth4.Name,4,scrollbooth4.PageCount);
            
            if(PageNumber > 1)
            {               
                $("#nextButton4").fadeTo("fast",1);
                document.getElementById("nextButton4").style.cursor = "pointer";              
            }
            if(PageNumber == 1)
            {
                $("#backButton4").fadeTo("fast",.3);
                document.getElementById("backButton4").style.cursor = "auto";
            }
            
		
        };
        scrollbooth4.onscrolltopage = function(PageNumber,PageID)
        {            
            var start = ((PageNumber - 1) * 2) + 1;
            var end = start + (Content4[(PageNumber-1)].length - 1);
            document.getElementById("counter4").innerHTML = new String(start + "-" + end + " / " + Content4Total);
            
            FormatNavLinks(PageNumber,scrollbooth4.Name,4,scrollbooth4.PageCount);	
            
            
            if(PageNumber == 1)
            {                
                $("#backButton4").fadeTo("fast",.3);
                document.getElementById("backButton4").style.cursor = "auto";
                $("#nextButton4").fadeTo("fast",1);
                document.getElementById("nextButton4").style.cursor = "pointer";              
            }
            else if(PageNumber == scrollbooth4.PageCount)
            {
                $("#nextButton4").fadeTo("fast",.3);
                document.getElementById("nextButton4").style.cursor = "auto";
                $("#backButton4").fadeTo("fast",1);
                document.getElementById("backButton4").style.cursor = "pointer";
            }
            else
            {
                $("#nextButton4").fadeTo("fast",1);
                $("#backButton4").fadeTo("fast",1);
                document.getElementById("backButton4").style.cursor = "pointer";
                document.getElementById("nextButton4").style.cursor = "pointer";
            }
            
	
        };       
        scrollbooth4.onscrollbootherror = function(Name,Error)
        {
            //Error is an object with 'id' and 'text' elements.            
            
        };
        
