﻿$(document).ready(function() 
{
    // Override "addToCookbook" links
    $('a.add-to-cookbook').click(function()
    {
        var link = $(this);
        $.post(link.attr('href'), null, function(data)
        {
            if (data.success)
            {
                link.hide();
                // add "already in your cookbook link"
                if (!link.hasClass('replace-with-text'))
                {
                    link.replaceWith($('<img src="../images/recipe/already-in-cookbook.gif" alt="Already in your cookbook" width="137" height="18" border="0"/>'));
                }
                else
                {
                    link.replaceWith($('<span class="bold">Already in your cookbook</span>'));
                }
            }
            else
            {
                window.location = "../cookbook/?recipe=" + data.recipeId;
            }
        }, 'json');
        
        return false;
    });
    
    $('a.recipe-popup').click(function()
    {
        GB_show($(this).attr('href'));
        return false;
    });
});
