﻿function CheckRecentRecipes()
{
    PageMethods.lngGetLatestRecipeTick(OnRecipeTickSucceeded, onRecipeFailed);
}

function OnRecipeTickSucceeded(result, userContext, methodName)
{
    var LatestTick = parseInt(result);
  
    var LatestDisplayTick = parseInt($get(txtLatestRecipeTicks).value); 
  
    if (LatestTick > LatestDisplayTick)
    {
        $get(txtLatestRecipeTicks).value = LatestTick;
        PageMethods.strGetLatestRecipeDetails(addRecipe, onFailed);
    }
}

function addRecipe(result, userContext, methodName) 
{
    $("#RecentRecipesList").prepend("<li><a href=\"/pages/Recipes/viewrecipe.aspx?q=" + result[0] + "\">" + result[1] + ", </a></li>");
    $("#RecentRecipesList li:last-child").remove();
}

function onRecipeFailed(ex, ctx, methodName) {
    alert(ex.get_message()); 
    clearInterval(recipeInterval); 
}

function pageLoad() {
    var recipeInterval = setInterval("CheckRecentRecipes()", 5000);
}
