﻿Shadowbox.loadSkin('classic', '/Scripts/Frameworks/Jquery/Plugins/shadowbox/skin');
$(function()
{
    //Procedural code style used

    $(".spot.dropdown select").change(function()
    {
        var value = $("option:selected", this).val();
        if (value != 'none')
        {
            location.href = value;
        }
        return false;
    });

    var inputtext;
    var textcache = false;

    function format(str)
    {
        for (i = 1; i < arguments.length; i++)
        {
            str = str.replace('{' + (i - 1) + '}', arguments[i]);
        }
        return str;
    }

    var openrecipeoverlay = function(input)
    {
        var q = $.trim(input.val());
        if (q.length > 0 && textcache && q != inputtext)
        {
            Shadowbox.open({
                player: 'iframe',
                content: '/3rdParty/wagawaga/search_results.html?q=' + q,
                height: 580,
                width: 705
            });
        }
    }

    Shadowbox.init({
        viewportPadding: 0,
        skipSetup: true,
        displayNav: false,
        enableKeys: false
    });

    var settextcache = function()
    {
        if (!textcache)
        {
            inputtext = $(this).val();
            textcache = true;
        }
    }
    $(".spot.recipe").find(":submit").click(function()
    {
        openrecipeoverlay($(this).prev(":text"));
        return false;
    }).end().find(":text").keypress(function(e)
    {
        settextcache.apply(this);
        if (e.which == '13')
        {
            openrecipeoverlay($(this));
            return false;
        }
    }).focus(function()
    {
        settextcache.apply(this);
        if ($.trim($(this).val()) == inputtext)
        {
            $(this).val("");
        }
    }).blur(function()
    {
        if ($.trim($(this).val()) == "")
        {
            $(this).val(inputtext);
        }
    });
});