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 Content1Total = 0;
         function ContentFunction1(Content) 
        {
            for(var x=0; x < Content.length; x++)
            {
                var Page = Content[x];
                var html = new String();
                
	Content1Total += Page.length;		
                
                for(var y=0; y < Page.length; y++)
                {
                    var image = Page[y].image;
                    var title = Page[y].title;
                    var url = Page[y].url;
                    html = html + new String("<div class='oneFourth' onclick='window.open(\""+url+"\",\"_parent\")'><div class='image'><img onload='this.style.border=\"1px solid #abaca9\"' onmouseover='this.style.border=\"1px solid #3fcd50\"' onmouseout='this.style.border=\"1px solid #abaca9\"' src='"+image+"' /></div><div class='title'><span id=flipperTitleType onmouseover='this.style.textDecoration=\"underline\"' onmouseout='this.style.textDecoration=\"none\"'>"+title+"</span></div></div>");                        
                }
                
                //The addPage method will create a new page and add the html string to it
                scrollbooth1.addPage(html);
            }
            
            
        }
                


        function ContentFunction2(Content) 
        {
            for(var x=0; x < Content.length; x++)
            {
                var Page = Content[x];
                var html = "<div class='bigimage' onclick='location.href=\""+Page.url+"\"'><img onload='this.style.border=\"1px solid #abaca9\"' onmouseover='this.style.border=\"1px solid #3fcd50\"' onmouseout='this.style.border=\"1px solid #abaca9\"' src='"+Page.image+"' /></div><div class='bigtitle' onclick='location.href=\""+Page.url+"\"' onmouseover='this.style.textDecoration = \"underline\"' onmouseout='this.style.textDecoration=\"none\"'>"+Page.title+"</div><div class='bigtitleSubtext'>"+Page.subtext+"</div>";
                scrollbooth2.addPage(html);
            }         
            
        }



        var Content3Total = 0;
        function ContentFunction3(Content) 
        {
            for(var x=0; x < Content.length; x++)
            {
                var Page = Content[x];
                var html = new String();
                
	Content3Total += Page.length
                
                for(var y=0; y < Page.length; y++)
                {
                    var link = Page[y].link; 
                    var url = Page[y].url;                   
                    html = html + new String("<div class='headlineBox' onclick='location.href=\""+url+"\"' onmouseover='this.style.textDecoration = \"underline\"' onmouseout='this.style.textDecoration=\"none\"'>"+link+"</div>");
		                     
                }
                
                //The addPage method will create a new page and add the html string to it
                scrollbooth3.addPage(html);
            }
            
           
        }
        
        
        
        // ScrollBooth(Name,HolderWidth,HolderHeight,HolderID,NavID,NextID,BackID,ContentFunction)
        var scrollbooth1 = new ScrollBooth("scrollboothOne", 400, 400, "holder1", "nav1", "nextButton1", "backButton1", ContentFunction1);
        var scrollbooth2 = new ScrollBooth("scrollboothTwo", 414, 400, "holder2", "nav2", "nextButton2", "backButton2", ContentFunction2);
        var scrollbooth3 = new ScrollBooth("scrollboothThree", 400, 400, "holder3", "nav3", "nextButton3", "backButton3", ContentFunction3);
                
        //Here are some events that you can set for your Scrollbooth object.  They are not mandatory        
        scrollbooth1.onscrollboothload = function(Name)
        {
            
        };
        scrollbooth1.onupdatenav = function(PageNumber,PageID)
        {
            
        };
        scrollbooth1.onaddpage = function(PageNumber,PageID)
        {            
            var end = Content1[0].length;
            document.getElementById("counter1").innerHTML = new String("1-" + end + " / " + Content1Total);

            FormatNavLinks(1,scrollbooth1.Name,4,scrollbooth1.PageCount);
            
            
            if(PageNumber > 1)
            {               
                $("#nextButton1").fadeTo("fast",1);
                document.getElementById("nextButton1").style.cursor = "pointer";              
            }
            if(PageNumber == 1)
            {
                $("#backButton1").fadeTo("fast",.3);
                document.getElementById("backButton1").style.cursor = "default";
            }
            
		
        };
        scrollbooth1.onscrolltopage = function(PageNumber,PageID)
        {            
            var start = ((PageNumber - 1) * 2) + 1;
            var end = start + (Content1[(PageNumber-1)].length - 1);
            document.getElementById("counter1").innerHTML = new String(start + "-" + end + " / " + Content1Total);
            
            FormatNavLinks(PageNumber,scrollbooth1.Name,4,scrollbooth1.PageCount);	
            
            
            if(PageNumber == 1)
            {                
                $("#backButton1").fadeTo("fast",.3);
                document.getElementById("backButton1").style.cursor = "default";
                $("#nextButton1").fadeTo("fast",1);
                document.getElementById("nextButton1").style.cursor = "pointer";              
            }
            else if(PageNumber == scrollbooth1.PageCount)
            {
                $("#nextButton1").fadeTo("fast",.3);
                document.getElementById("nextButton1").style.cursor = "default";
                $("#backButton1").fadeTo("fast",1);
                document.getElementById("backButton1").style.cursor = "pointer";
            }
            else
            {
                $("#nextButton1").fadeTo("fast",1);
                $("#backButton1").fadeTo("fast",1);
                document.getElementById("backButton1").style.cursor = "pointer";
                document.getElementById("nextButton1").style.cursor = "pointer";
            }        
	
        };       
        scrollbooth1.onscrollbootherror = function(Name,Error)
        {
            //Error is an object with 'id' and 'text' elements.            
            
        };
        
        scrollbooth2.onscrollboothload = function(Name)
        {
            //Name is the name you entered into the Scrollbooth constructor
        };
        scrollbooth2.onupdatenav = function(PageNumber,PageID)
        {
            
        };

	var Scrollbooth2Total = 0;
        scrollbooth2.onaddpage = function(PageNumber,PageID)
        {
         	Scrollbooth2Total++;
	document.getElementById("counter2").innerHTML = "1 / " + Scrollbooth2Total;

              FormatNavLinks(1,scrollbooth2.Name,4,scrollbooth2.PageCount);	 
              
            if(PageNumber > 1)
            {               
                $("#nextButton2").fadeTo("fast",1);
                document.getElementById("nextButton2").style.cursor = "pointer";              
            }
            if(PageNumber == 1)
            {
                $("#backButton2").fadeTo("fast",.3);
                document.getElementById("backButton2").style.cursor = "default";
            }
              
        };       
	
         scrollbooth2.onscrolltopage = function(PageNumber,PageID)
        {	
	document.getElementById("counter2").innerHTML = PageNumber + " / " + Scrollbooth2Total;

              FormatNavLinks(PageNumber,scrollbooth2.Name,4,scrollbooth2.PageCount);
              
            if(PageNumber == 1)
            {                
                $("#backButton2").fadeTo("fast",.3);
                document.getElementById("backButton2").style.cursor = "default";
                $("#nextButton2").fadeTo("fast",1);
                document.getElementById("nextButton2").style.cursor = "pointer";              
            }
            else if(PageNumber == scrollbooth2.PageCount)
            {
                $("#nextButton2").fadeTo("fast",.3);
                document.getElementById("nextButton2").style.cursor = "default";
                $("#backButton2").fadeTo("fast",1);
                document.getElementById("backButton2").style.cursor = "pointer";
            }
            else
            {
                $("#nextButton2").fadeTo("fast",1);
                $("#backButton2").fadeTo("fast",1);
                document.getElementById("backButton2").style.cursor = "pointer";
                document.getElementById("nextButton2").style.cursor = "pointer";
            }       
       
        };       
        scrollbooth2.onscrollbootherror = function(Name,Error)
        {
            //Error is an object with 'id' and 'text' elements.            
            alert(Name + " Error ID: " + Error.id + " - " + Error.text);
        };
        
        scrollbooth3.onscrollboothload = function(Name)
        {
            //Name is the name you entered into the Scrollbooth constructor
        };
        scrollbooth3.onupdatenav = function(PageNumber,PageID)
        {
            
        };
        scrollbooth3.onaddpage = function(PageNumber,PageID)
        {
            	var end = Content3[0].length;
            document.getElementById("counter3").innerHTML = new String("1-" + end + " / " + Content3Total);

              FormatNavLinks(1,scrollbooth3.Name,4,scrollbooth3.PageCount);	
              
            if(PageNumber > 1)
            {               
                $("#nextButton3").fadeTo("fast",1);
                document.getElementById("nextButton3").style.cursor = "pointer";              
            }
            if(PageNumber == 1)
            {
                $("#backButton3").fadeTo("fast",.3);
                document.getElementById("backButton3").style.cursor = "default";
            }
        };
        scrollbooth3.onscrolltopage = function(PageNumber,PageID)
        {            
            var start = ((PageNumber - 1) * 5) + 1;
            var end = start + (Content3[(PageNumber-1)].length - 1);
            document.getElementById("counter3").innerHTML = new String(start + "-" + end + " / " + Content3Total);

              FormatNavLinks(PageNumber,scrollbooth3.Name,4,scrollbooth3.PageCount);
              
              if(PageNumber == 1)
            {                
                $("#backButton3").fadeTo("fast",.3);
                document.getElementById("backButton3").style.cursor = "default";
                $("#nextButton3").fadeTo("fast",1);
                document.getElementById("nextButton3").style.cursor = "pointer";              
            }
            else if(PageNumber == scrollbooth3.PageCount)
            {
                $("#nextButton3").fadeTo("fast",.3);
                document.getElementById("nextButton3").style.cursor = "default";
                $("#backButton3").fadeTo("fast",1);
                document.getElementById("backButton3").style.cursor = "pointer";
            }
            else
            {
                $("#nextButton3").fadeTo("fast",1);
                $("#backButton3").fadeTo("fast",1);
                document.getElementById("backButton3").style.cursor = "pointer";
                document.getElementById("nextButton3").style.cursor = "pointer";
            }
              
        };       
        scrollbooth3.onscrollbootherror = function(Name,Error)
        {
            //Error is an object with 'id' and 'text' elements.            
            alert(Name + " Error ID: " + Error.id + " - " + Error.text);
        };
