﻿/*ShoppingList Plugin Start*/
(function($) {
    var ShoppingList = function() {
        /* all the divs */
        var divs = {
            WrapperDiv: '<div class="L34"><h3 class="chefHeader"></h3><a href="#" class="btnClear">Clear</a></div>',
            FooterDiv: '',
            shoppingListDiv: '<div class="shoppingList"><div class="padBtm"></div></div>',
            ItemDiv: '<div class="item"><p><strong></strong> - <a href="#">Remove</a><br /></p></div>',
            NoItemDiv: '<label id="NoRecipes" style="text-align:center;"></label>',
            EmailDiv: '<div><h3></h3><table></table></div>',
            EmptyDiv: '<div></div>'
        },
        /* removes the recipie div*/
        RemoveRecipe = function(RecipieDiv) {
            $(RecipieDiv).remove();
            /*if shopping list is empty the show empty message*/
            var ExistingRecipes = $('.shoppingList').find('div.item');
            if (ExistingRecipes.length == 0) {
                $('.shoppingList').empty().append(divs.NoItemDiv);
                $('#NoRecipes').html(globaloptions.NoRecipesContent);
            }
        },
        GetRecipe = function(RecipeDiv) {
            /*Extract recipie from the recipie div*/
            var localDiv = $(RecipeDiv).clone();
            var objRecipe = new Object();
            objRecipe.RecipeId = $(localDiv).attr('id');
            objRecipe.Title = $(localDiv).find('strong').text();
            var Data = $(localDiv).find('p');
            $(Data).find('strong').remove();
            $(Data).find('a').remove();
            $(Data).find('BR:first').remove();
            $(Data).find('BR:last').remove();
            $(Data).find('BR').replaceWith('||');
            objRecipe.Ingredients = $(Data).html().substr(2);
            return objRecipe;
        },
        /*defaults for the plugin*/
        defaults = {
            OnRemove: function() { return {}; }, /*event when remove link is clicked*/
            OnClear: function() { return {}; }, /*event for clear link*/
            HeaderContent: 'My Shopping List',
            ClearContent: 'Clear',
            RemoveButtonContent: 'Remove',
            NoRecipesContent: 'No Recipes found',
            AddthisUrl: 'http://www.addthis.com/bookmark.php',
            PrintAssetsLoaction: 'http://masterchef.staging.ten.com.au',
            CookieName: '',
            SiteName: '',
            LogoAltText: '',
            SponsorAltText: '',
            CookbookWidgetLocation: 'CookbookWidget/Cookbook.aspx'
        },
        /*clears the shoppinglist*/
        ClearAll = function() {
            var recipes = [];
            var count = 0;
            $('.shoppingList').find('div.item').each(function() {
                recipes[count] = GetRecipe(this);
                count++;
                RemoveRecipe(this);
            });
        },
        /* print shopping list*/
        PrintShoppingList = function() {
            if ($(this).GetShoppingList().length > 0) {

                window.open(globaloptions.CookbookWidgetLocation + "?action=printshoppinglist&cookiename=" + globaloptions.CookieName + "&sitename=" + globaloptions.SiteName + "&printassetlocation=" + globaloptions.PrintAssetLocation + "&logoalttext=" + globaloptions.LogoAltText + "&sponsoralttext=" + globaloptions.SponsorAltText, "ShoppingList", "toolbar=0,scrollbars=1");

            } else {
                
            }
        },
        globaloptions = {}
        return {
            init: function(options) {
                globaloptions = $.extend({}, defaults, options || {});
                $(this).find('.L34').remove();
                $(this).prepend(divs.WrapperDiv);
                $(this).find('.L34').append(divs.shoppingListDiv);
                $(this).find('.shoppingList').append(divs.NoItemDiv);
                /*addthis.button(".btnEmail", {}, {});*/
                $(this).find('.L34 .btnClear').click(function(event) {
                    var allRecipes = $(this).GetShoppingList();
                    ClearAll();
                    event.preventDefault();
                    if (allRecipes.length > 0) {
                        globaloptions.OnClear.apply(this, [allRecipes]);
                    }
                });
                /*change this on requirement*/
               
                $(this).find('.btnShoppingList').click(function(event) {
                    event.preventDefault();
                    PrintShoppingList();
                });
                $(this).find('.btnDownload').attr('href', globaloptions.CookbookWidgetLocation + "?action=downloadpdf&cookiename=" + globaloptions.CookieName + "&sitename=" + globaloptions.SiteName + "&printassetlocation=" + globaloptions.PrintAssetLocation + "&logoalttext=" + globaloptions.LogoAltText + "&sponsoralttext=" + globaloptions.SponsorAltText);
                $('#NoRecipes').html(globaloptions.NoRecipesContent);
                $(this).find('.L34').find('h3').html(globaloptions.HeaderContent);
            },
            AddRecipe: function(recipe) {
		var len = 0;
		for(var i =0;i<this.GetShoppingList().length;i++)
		{
		    len = len + this.GetShoppingList()[i].Ingredients.length;
		    len = len + this.GetShoppingList()[i].Title.length;
		    len = len + (this.GetShoppingList()[i].Ingredients.split('||').length*6);
		}
		len = len+recipe.Ingredients.length;
		len = len +recipe.Title.length;
		len = len+(recipe.Ingredients.split('||').length*6);
		if(len>2500)
		{
		    if($('.error').length==0){
		    	$('.favouriteRecipes').before($('<div/>').addClass('error').html('Only 2 recipes can be added to your shopping list at one time'));}
		    $('li[recipeid='+recipe.RecipeId+']').attr('checked','');
		    $.fn.CookbookWidget.RemoveRecipeFromShoppingList(recipe.RecipeId);
		    return;
		}else{
		    $('.error').remove();
		}
                var RecipeDiv = $(divs.ItemDiv).attr('id', recipe.RecipeId).get();
                $(RecipeDiv).find('strong').text(recipe.Title);
                $(RecipeDiv).find('a').click(function(event) {
                    var delrecipe = GetRecipe(RecipeDiv)
                    RemoveRecipe(RecipeDiv);
                    event.preventDefault();
                    globaloptions.OnRemove.apply(this, [delrecipe]);
                });
                var ShoppingListItems = recipe.Ingredients.split('||');
                for (var i = 0; i < ShoppingListItems.length; i++) {
                    $(RecipeDiv).find('p').append(ShoppingListItems[i] + '<br/>');
                }
                $('.shoppingList').find('#NoRecipes').remove();
                $('.shoppingList').append(RecipeDiv);
            },
            AddRecipes: function(recipes) {
                for (var i = 0; i < recipes.length; i++) {
                    this.AddRecipe(recipes[i]);
                }
            },
            GetEmailHtml: function() {
                var recipies = $(this).GetShoppingList();
                var Emailhtml = $(divs.EmptyDiv);
                for (var i = 0; i < recipies.length; i++) {
                    var RecipeDiv = $(divs.EmailDiv);
                    var Ingredients = recipies[i].Ingredients.split('||');
                    $(RecipeDiv).find('h3').text(recipies[i].Title);
                    for (var j = 0; j < Ingredients.length; j++) {
                        $(RecipeDiv).find('table').append('<tr><td>' + Ingredients[j] + '</td></tr>');
                    }
                    $(Emailhtml).append(RecipeDiv);
                }
		/*if($(Emailhtml).html().length>2000)
		{
		    throw "To many recipes selected";
		}*/
                return $(Emailhtml).html();
            },
            GetShoppingList: function() {
                var recipes = [];
                var count = 0;
                $('.shoppingList').find('div.item').each(function() {
                    recipes[count] = GetRecipe(this);
                    count++;
                });
                return recipes;
            },
            RemoveRecipe: function(recipe) {
                var RecipeDiv = $('.shoppingList').find('div[id=' + recipe.RecipeId + ']');
                RemoveRecipe(RecipeDiv);
		$('.error').remove();
            }
        };
    } ();
    $.fn.extend({
        ShoppingList: ShoppingList.init,
        AddRecipe: ShoppingList.AddRecipe,
        GetShoppingList: ShoppingList.GetShoppingList,
        AddRecipes: ShoppingList.AddRecipes,
        RemoveRecipe: ShoppingList.RemoveRecipe,
        GetEmailHtml: ShoppingList.GetEmailHtml
    });
})(jQuery);
/*ShoppingList Plugin End*/
$(document).ready(function() {
    var NetworkTenWidgets_CookbookWidget_Settings = {
        CookbookGridDiv: '#cookbook',
        ShoppingListDiv: '#shopping-list',
        CookbookWidgetLocation: 'CookbookWidget/Cookbook.aspx',
        CookbookURL: 'MockCookbookPage.html',
        CookieName: 'Cookbook',
        SiteName: "MasterChef",
        PageSize: 21,
        BtnAddOptionClass: 'addOption',
        BtnAddOptionSelectedClass: 'addOptionSelected',
        PrintAssetsLocation: 'http://masterchef.staging.ten.com.au',
        LogoAltText: 'Masterchef Australia',
        SponsorAltText: 'My MasterChef Shopping List',
        AddThisUrl: 'http://www.addthis.com/bookmark.php',
        EmptyShoppingListHtml: 'No Recipes found',
        EmptyCookbookHtml: 'No Recipes in Cookbook'
    };

    var NetworkTenWidgets_CookbookWidget_ShoppingList;

    addthis.addEventListener('addthis.menu.open', eventHandler);
    function eventHandler(evt) {

        addthis_share.email_vars.ShoppingList = $(NetworkTenWidgets_CookbookWidget_ShoppingList).GetEmailHtml();
    }

    $.namespace("CookbookWidget", {
        inherited: true,

        InitialiseWidget: function(options) {
            NetworkTenWidgets_CookbookWidget_Settings = jQuery.extend(NetworkTenWidgets_CookbookWidget_Settings, options);
            if ($(NetworkTenWidgets_CookbookWidget_Settings.ShoppingListDiv).length > 0) {
                NetworkTenWidgets_CookbookWidget_ShoppingList = $(NetworkTenWidgets_CookbookWidget_Settings.ShoppingListDiv).ShoppingList({
                    OnRemove: function(recipe) { $.fn.CookbookWidget.RemoveRecipeFromShoppingList(recipe.RecipeId) },
                    OnClear: function(recipes) { $.fn.CookbookWidget.ClearShoppingList(recipes) },
                    PrintAssetLocation: NetworkTenWidgets_CookbookWidget_Settings.PrintAssetsLocation,
                    CookieName: NetworkTenWidgets_CookbookWidget_Settings.CookieName,
                    SiteName: NetworkTenWidgets_CookbookWidget_Settings.SiteName,
                    LogoAltText: NetworkTenWidgets_CookbookWidget_Settings.LogoAltText,
                    SponsorAltText: NetworkTenWidgets_CookbookWidget_Settings.SponsorAltText,
                    AddThisUrl: NetworkTenWidgets_CookbookWidget_Settings.AddThisUrl,
                    NoRecipesContent: NetworkTenWidgets_CookbookWidget_Settings.EmptyShoppingListHtml,
                    CookbookWidgetLocation: NetworkTenWidgets_CookbookWidget_Settings.CookbookWidgetLocation
                });
            }
        },

        HasCookbookBeenUsedBefore: function() {
            var cookies = document.cookie;
            if (true) { }

            var theCookie = document.cookie;
            var ind = theCookie.indexOf(NetworkTenWidgets_CookbookWidget_Settings.CookieName);
            if (ind == -1) return "";
            var ind1 = theCookie.indexOf(';', ind);
            if (ind1 == -1) ind1 = theCookie.length;
            return unescape(theCookie.substring(ind + NetworkTenWidgets_CookbookWidget_Settings.CookieName.length + 1, ind1));
        },

        SetStateOfRecipeButton: function(SaveButton) {

            function SetAlreadySavedToCookbookState() {
                $(SaveButton)
					.text('Saved to Cookbook')
					.removeClass(NetworkTenWidgets_CookbookWidget_Settings.BtnAddOptionClass)
					.removeClass(NetworkTenWidgets_CookbookWidget_Settings.BtnAddOptionSelected)
					.addClass(NetworkTenWidgets_CookbookWidget_Settings.BtnAddOptionSelectedClass)
					.unbind('click')
					.click(function(event) {
					    
					    event.preventDefault();
					    document.location = NetworkTenWidgets_CookbookWidget_Settings.CookbookURL;
					});
            }

            function SetNotSavedToCookbookState(data) {
                $(SaveButton)
					.text('Save to Cookbook')
					.removeClass(NetworkTenWidgets_CookbookWidget_Settings.BtnAddOptionClass)
					.removeClass(NetworkTenWidgets_CookbookWidget_Settings.BtnAddOptionSelectedClass)
					.addClass(NetworkTenWidgets_CookbookWidget_Settings.BtnAddOptionClass)
					.unbind('click')
					.click(function(event) {
					    event.preventDefault();
					    $.ajax({
					        type: "POST",
					        url: NetworkTenWidgets_CookbookWidget_Settings.CookbookWidgetLocation + '?action=saverecipe',
					        data: JSON.stringify(data),
					        contentType: "application/json;",
					        dataType: "json",
					        async:false,
					        success: function(msg) {
					            SetAlreadySavedToCookbookState();
					        },
					        error: function(msg) {
					            
					        }
					    });

					});
            }

            var cookieValue = $.fn.CookbookWidget.HasCookbookBeenUsedBefore();

            var data = {
                RecipeUrl: document.URL,
                SiteName: NetworkTenWidgets_CookbookWidget_Settings.SiteName,
                CookieName: NetworkTenWidgets_CookbookWidget_Settings.CookieName
                
            };

            if (cookieValue != null && cookieValue != "") {
                /*the user has added recipes previously this "session"*/
                $.ajax({
                    type: "POST",
                    url: NetworkTenWidgets_CookbookWidget_Settings.CookbookWidgetLocation + '?action=checkrecipe',
                    data: JSON.stringify(data),
                    contentType: "application/json;",
                    dataType: "json",
                    success: function(msg) {
                        if (msg.Success) { /* the url has been saved to the cookbook*/
                            SetAlreadySavedToCookbookState();
                        }
                        else { /* the url has not been saved to the cookbook yet*/
                            SetNotSavedToCookbookState(data);
                        }
                    },
                    error: function(msg) {
                        
                    }
                });

            }
            else {
                /*the user has NOT added recipes previously this "session"*/
                SetNotSavedToCookbookState(data);
            }
        },

        LoadPagedCookbook: function(pageNumber) {


            var newPageNumber = pageNumber;
            if (newPageNumber == isNaN || newPageNumber == undefined || newPageNumber == "") {
                newPageNumber = $("#hdnPageNumber").text();
                if (isNaN(parseInt(newPageNumber))) {
                    newPageNumber = 1;
                }
            }

            var urlToLoad = NetworkTenWidgets_CookbookWidget_Settings.CookbookWidgetLocation + "?action=getcookbookrecipes";

            var data = {
                SiteName: NetworkTenWidgets_CookbookWidget_Settings.SiteName,
                PageSize: NetworkTenWidgets_CookbookWidget_Settings.PageSize,
                PageNum: newPageNumber,
                CookieName: NetworkTenWidgets_CookbookWidget_Settings.CookieName
            };


            $.ajax({
                type: "POST",
                url: urlToLoad,
                data: JSON.stringify(data),
                contentType: "application/json;",
                dataType: "json",
                async: false,
                success: function(msg) {

                    $(NetworkTenWidgets_CookbookWidget_Settings.CookbookGridDiv).empty();

                    if (msg.Total > 0) {
                        $(NetworkTenWidgets_CookbookWidget_Settings.CookbookGridDiv)
						.append('<h3 class="chefHeader">My Favourites</h3>')
						.append('<ul class="favouriteRecipes" />');

                        $(msg.SingleData.Recipes).each(function(index, recipe) {
                            var checked = recipe.OnShoppingList ? 'checked="checked"' : '';

                            $('.favouriteRecipes').append('<li recipeid="' + recipe.RecipeId + '"></li>');
                            $('.favouriteRecipes li[recipeid="' + recipe.RecipeId + '"]')
							.append('<span><input type="checkbox" id="check' + index + '" ' + checked + ' /><label for="check' + index + '">Add to My Shopping List</label></span>')
							.append('<img src="' + recipe.ImagePath + '" style="width:180px; height:101px;" alt="" /><a href="' + recipe.Url + '">' + recipe.Title + '</a>')
							.append('<a href="#" class="btnRemoveRecipe" title="Remove Recipe">Remove</a>');
                        });

                        $(".favouriteRecipes li").each(function(index, recipeObj) {
                            $.fn.CookbookWidget.SetRecipeActions(recipeObj);
                        });

                        /*generate page links*/
                        $(NetworkTenWidgets_CookbookWidget_Settings.CookbookGridDiv).append('<div class="clearFloats"></div>');
                        $(NetworkTenWidgets_CookbookWidget_Settings.CookbookGridDiv).append('<div class="links">');
                        if (msg.SingleData.NumberOfPages > 1) {
                            var links = $(NetworkTenWidgets_CookbookWidget_Settings.CookbookGridDiv).children('.links');
                            $(links).append('Go to page: ');
                            /*previous link*/
                            if (msg.SingleData.CurrentPage == 1) {
                                $(links).append('<span class="prev">&lt;Prev</span>');
                            }
                            else {
                                $(links).append('<a class="lnkPager lnkMovePrev prev" href="#">&lt;Prev</a>');
                            }

                            /*individual page links*/
                            for (i = 1; i <= msg.SingleData.NumberOfPages; i++) {
                                if (i == msg.SingleData.CurrentPage) {
                                    $(links).append('<span class="selected">' + i + '</span>');
                                }
                                else {
                                    $(links).append('<a class="lnkPager lnkMoveTo" moveTo="' + i + '" href="#">' + i + '</a>');
                                }
                            }

                            /*next link*/
                            if (msg.SingleData.CurrentPage == msg.SingleData.NumberOfPages) {
                                $(links).append('<span class="next">Next&gt;</span>');
                            }
                            else {
                                $(links).append('<a class="lnkPager lnkMoveNext next" href="#">Next&gt;</a>');
                            }
                        }
                        /*save number of pages and current page to hidden fields*/
                        $(NetworkTenWidgets_CookbookWidget_Settings.CookbookGridDiv).append('<input type="hidden" id="hdnMaxPages">');
                        $("#hdnMaxPages").val(msg.SingleData.NumberOfPages);
                        $(NetworkTenWidgets_CookbookWidget_Settings.CookbookGridDiv).append('<input type="hidden" id="hdnCurrentPage">');
                        $("#hdnCurrentPage").val(msg.SingleData.CurrentPage);

                        $(NetworkTenWidgets_CookbookWidget_Settings.CookbookGridDiv).append('</div>');

                        $.fn.CookbookWidget.SetPagingLinks();
                    }
                    else {
                        $(NetworkTenWidgets_CookbookWidget_Settings.CookbookGridDiv).html(NetworkTenWidgets_CookbookWidget_Settings.EmptyCookbookHtml);
                    }
                },
                error: function(msg) {
                   
                    
                }
            });
        },

        LoadRecipeList: function() {

            var data = {
                SiteName: NetworkTenWidgets_CookbookWidget_Settings.SiteName,
                CookieName: NetworkTenWidgets_CookbookWidget_Settings.CookieName
            };

            var urlToLoad = NetworkTenWidgets_CookbookWidget_Settings.CookbookWidgetLocation + "?action=getrecipelistrecipes";

            $.ajax({
                type: "POST",
                url: urlToLoad,
                data: JSON.stringify(data),
                contentType: "application/json;",
                dataType: "json",
                success: function(msg) {

                    if (msg.Count > 0) {
                        $(NetworkTenWidgets_CookbookWidget_ShoppingList).AddRecipes(msg.Data);
                    }
                }
            });
        },

        SetRecipeActions: function(item) {
            /*add/remove recipe to shopping list*/
            var chkbox = $(item).children("span").children(":checkbox")
            $(chkbox).click(function(event) {
                var checked = $(this).is(":checked");
                var recipeId = $(this).parent().parent().attr("recipeId");
                var action = '';

                if (checked) {
                    /*adding to shopping list*/
                    action = 'addtoshoppinglist';
                }
                else {
                    /*removing from shopping list*/
                    action = 'removefromshoppinglist';
                }

                var urlToLoad = NetworkTenWidgets_CookbookWidget_Settings.CookbookWidgetLocation + '?action=' + action;

                $.ajax({
                    type: "POST",
                    url: urlToLoad,
                    data: JSON.stringify(recipeId),
                    contentType: "application/json;",
                    dataType: "json",
                    success: function(msg) {
                        if (action == "addtoshoppinglist") {
                            $(NetworkTenWidgets_CookbookWidget_ShoppingList).AddRecipe(msg.SingleData);
                        } else {
                            $(NetworkTenWidgets_CookbookWidget_ShoppingList).RemoveRecipe(msg.SingleData);
                        }
                    },
                    error: function(msg) {
                        
                    }
                });

            });

            /*remove recipe from cookbook*/
            var removeBtn = $(item).children(".btnRemoveRecipe");
            $(removeBtn).click(function(event) {
                event.preventDefault();
                var recipeId = $(this).parent().attr("recipeId");

                var urlToLoad = NetworkTenWidgets_CookbookWidget_Settings.CookbookWidgetLocation + '?action=removefromcookbook';

                $.ajax({
                    type: "POST",
                    url: urlToLoad,
                    data: JSON.stringify(recipeId),
                    contentType: "application/json;",
                    dataType: "json",
                    success: function(msg) {
                        var currentPage = $("#hdnCurrentPage").val();
                        var urlToLoad = NetworkTenWidgets_CookbookWidget_Settings.CookbookWidgetLocation + "?action=getcookbookrecipes";

                        var data = {
                            SiteName: NetworkTenWidgets_CookbookWidget_Settings.SiteName,
                            PageSize: NetworkTenWidgets_CookbookWidget_Settings.PageSize,
                            PageNum: currentPage,
                            CookieName: NetworkTenWidgets_CookbookWidget_Settings.CookieName
                        };


                        $.ajax({
                            type: "POST",
                            url: urlToLoad,
                            data: JSON.stringify(data),
                            contentType: "application/json;",
                            dataType: "json",
                            async: true,
                            success: function(msg) {
                                
                                if (msg.SingleData.NumberOfPages < currentPage) {
                                    
                                    $.fn.CookbookWidget.LoadPagedCookbook(1);
                                }
                                else {
                                    
                                    $.fn.CookbookWidget.LoadPagedCookbook(currentPage);
                                }
                            }
                        });
                    },
                    error: function(msg) {

                        
                    }
                });
            });
        },

        RemoveRecipeFromShoppingList: function(recipeId) {
            var urlToLoad = NetworkTenWidgets_CookbookWidget_Settings.CookbookWidgetLocation + '?action=removefromshoppinglist';

            $.ajax({
                type: "POST",
                url: urlToLoad,
                data: JSON.stringify(recipeId),
                contentType: "application/json;",
                dataType: "json",
                success: function(msg) {
                    var recipeItemChkBox = $(NetworkTenWidgets_CookbookWidget_Settings.CookbookGridDiv).find('ul.favouriteRecipes li[recipeid="' + msg.SingleData.RecipeId + '"] input:checkbox');
                    if ($(recipeItemChkBox).length > 0) {
                        $(recipeItemChkBox).removeAttr('checked');
                    }
                },
                error: function(msg) {
                    
                }
            });
        },

        ClearShoppingList: function(recipes) {
            var urlToLoad = NetworkTenWidgets_CookbookWidget_Settings.CookbookWidgetLocation + '?action=clearshoppinglist';

            var data = {
                SiteName: NetworkTenWidgets_CookbookWidget_Settings.SiteName,
                CookieName: NetworkTenWidgets_CookbookWidget_Settings.CookieName
            };

            $.ajax({
                type: "POST",
                url: urlToLoad,
                data: JSON.stringify(data),
                contentType: "application/json;",
                dataType: "json",
                success: function(msg) {
                    $(recipes).each(function(i, recipe) {
                        var recipeItemChkBox = $(NetworkTenWidgets_CookbookWidget_Settings.CookbookGridDiv).find('ul.favouriteRecipes li[recipeid="' + recipe.RecipeId + '"] input:checkbox');
                        if ($(recipeItemChkBox).length > 0) {
                            $(recipeItemChkBox).removeAttr('checked');
                        }
                    });
                },
                error: function(msg) {
                    
                }
            });
        },

        MoveNext: function() {
            var maxPages = $("#hdnMaxPages").val();
            var currentPage = $("#hdnCurrentPage").val();
            var nextPage = parseInt(currentPage) + 1;
            if (currentPage < maxPages) {
                $.fn.CookbookWidget.ChangePageNumber(nextPage);
            }
        },

        MovePrev: function() {
            var currentPage = $("#hdnCurrentPage").val();
            var previousPage = parseInt(currentPage) - 1;
            if (currentPage > 1) {
                $.fn.CookbookWidget.ChangePageNumber(previousPage);
            }
            
        },

        ChangePageNumber: function(newPageNumber) {
            
            $.fn.CookbookWidget.LoadPagedCookbook(newPageNumber);
        },

        SetPagingLinks: function() {

            $(".lnkMovePrev").click(function(event) {
                event.preventDefault();
                $.fn.CookbookWidget.MovePrev();
            });

            $(".lnkMoveTo").click(function(event) {
                event.preventDefault();
                var newPageNumber = $(this).attr('moveTo');
                var currentPage = $("#hdnCurrentPage").text();
                if ($(this).text() != currentPage) {
                    $.fn.CookbookWidget.LoadPagedCookbook(newPageNumber);
                }
            });

            $(".lnkMoveNext").click(function(event) {
                event.preventDefault();
                $.fn.CookbookWidget.MoveNext();
            });
        }
    });
});
