﻿var PillsburyBaking = {};
		
PillsburyBaking.enablePaging = function() {
    //hide all the divs
    $("div#ideapages div.page").hide();
    
    //show the first div
    $("div#ideapages div:first-child").show();
    
    // Initialize the current and selected pages
    var currentPage = 1;
    var selectedPage;
    
    // Hide the prev button since you start at page 1
    $("div.pagination a.previouspage").css("display","none");
    
    // Mark the first page as active in pagination control
    $("div.pagination a.page1link").addClass("active");
    
    $("div.pagination a").click(function() {
        if (!$(this).hasClass("active")) { // if it's not already active...
            
            // Hide all divs
            $("div#ideapages div.page").hide();
            
            // Remove active class from all links
            $("div.pagination a").removeClass("active");
            
            // If it's a previous link...
            if ($(this).hasClass("previouspage")) {
                
                // if the current page is 2 
                if (currentPage == 2) {
                    //hide the prev button since you're now on page 1
                    $("div.pagination a.previouspage").css("display","none");
                    
                    // Add active class to appropriate link
                    $("div.pagination a.page1link").addClass("active");
                
                    // Show the correct page
                    $("div#ideapages div#page1").show();
                    
                } else if (currentPage == 3) {
                    // Show the next button
                    $("div.pagination a.nextpage").css("display","inline");
                    
                    // Add active class to appropriate link
                    $("div.pagination a.page2link").addClass("active");
                
                    // Show the correct page
                    $("div#ideapages div#page2").show();
                };

                // Set the new currentPage
                currentPage--;

             // If it's a next link...  
            } else if ($(this).hasClass("nextpage")) {
                
                // if the current page is 2 
                if (currentPage == 2) {
                    //hide the next button since you're now on page 3
                    $("div.pagination a.nextpage").css("display","none");
                    
                    // Add active class to appropriate link
                    $("div.pagination a.page3link").addClass("active");
                
                    // Show the correct page
                    $("div#ideapages div#page3").show();
                    
                } else if (currentPage == 1) {
                    // Show the prev button
                    $("div.pagination a.previouspage").css("display","inline");
                    
                    // Add active class to appropriate link
                    $("div.pagination a.page2link").addClass("active");
                
                    // Show the correct page
                    $("div#ideapages div#page2").show();
                };
                
                // Set the new currentPage
                currentPage++;
                
            } else { //otherwise, it's a page number
            
                // get the intended page from href
                selectedPage = $(this).attr("href");

                // Add active class to appropriate link and show the appropriate page
                switch (selectedPage) {
                    case "#page1": 
                        $("div.pagination a.page1link").addClass("active");
                        // Show the next button
                        $("div.pagination a.nextpage").css("display","inline");
                        //hide the prev button since you're now on page 1
                        $("div.pagination a.previouspage").css("display","none");
                        currentPage = 1;
                        break;
                    case "#page2": 
                        $("div.pagination a.page2link").addClass("active");
                        // Show the next button
                        $("div.pagination a.nextpage").css("display","inline");
                        // Show the prev button
                        $("div.pagination a.previouspage").css("display","inline");
                        currentPage = 2;
                        break;
                    case "#page3": 
                        $("div.pagination a.page3link").addClass("active");
                        // Show the prev button
                        $("div.pagination a.previouspage").css("display","inline");
                        //hide the next button since you're now on page 3
                        $("div.pagination a.nextpage").css("display","none");
                        currentPage = 3;
                        break;
                };
                $(selectedPage).show();
                
            };
        };
        return false;
    });
};

$(document).ready(function() {
    PillsburyBaking.enablePaging();
});