﻿/// <reference path="/js/jquery-1.3.2.js" />
var curNavSection = "";
var curSubNavSection = "";

$(document).ready(function() {

    $("input[type='button']").addClass("button");
    $("input[type='text']").addClass("textbox");
    $("input[type='submit']").addClass("button");

    $("hr").wrap("<div class='hr'></div>");



    $("#sales_locator_submit").bind("click", function() {
        if ($("#sales_locator_text").attr("value") != "zip code" && $("#sales_locator_text").attr("value") != "") {
            showPopin("/SalesLocator.aspx?zip=" + $("#sales_locator_text").attr("value"), "300", "300", "sales_locator_popin_div");
        }
        else {
            alert("You must provide a postal code.");
        }
    });

    $(".ui-popin-signup").bind("click", function() {
        return signupNewUser();
    });

    $(".ui-popin-email").bind("click", function() {
        showPopin($(this).attr("href"), "505", "288", "email_recipe_popin_div");
        return false;
    });





    loadDefaultSubNav();
    var hideSubNavTimer = "";
    $("#navigation > ul > li:has(ul)").hover(function() {
        if (!$(this).children("ul").is(":visible")) {

            $(this).siblings(":has(ul)").each(function() {
                $(this).children("ul").hide();
            });
            $(this).children("ul").stop().fadeIn(300);
        }
        clearTimeout(hideSubNavTimer);
    }, function() {
        hideSubNavTimer = setTimeout(function() {
            $("#navigation > ul > li:has(ul)").each(function() {
                $(this).children("ul").hide();
            });
            loadDefaultSubNav();
        }, 500);
    });


    $("img.recipePhoto").each(function() {
        if ($(this).attr("effect_recipePhoto_loaded") == "true") return;
        $(this).attr("effect_recipePhoto_loaded", "true");

        var wrapper = "<div class=\"recipeBackground\"></div>";
        if ($(this).parent().get(0).tagName == "A") {
            $(this).parent().wrap(wrapper);
        }
        else {
            $(this).wrap(wrapper);
        }

    });


    //Fade Rollover Code

    $(".ui-fade-rollover").each(function() {
        if ($(this).attr("effect_loaded") == "true") return;
        $(this).attr("effect_loaded", "true");
        if ($(this).attr("alt") != null && curNavSection != "" && $(this).attr("alt").indexOf(curNavSection) != -1) {
            $(this).attr("src", $(this).attr("src").replace("_off", "_over"));
        }

        if ($(this).attr("alt") != null && curSubNavSection != "" && $(this).attr("alt").indexOf(curSubNavSection) != -1) {
            $(this).attr("src", $(this).attr("src").replace("_off", "_over"));
        }

        var wrapper = "<div style='display: block; height: auto; width: auto; background-repeat: no-repeat; background-image: url(" + $(this).attr("src").replace("_off", "_over") + ")'></div>";
        if ($(this).parent().get(0).tagName == "A") {
            $(this).parent().wrap(wrapper);
        }
        else {
            $(this).wrap(wrapper);
        }

        $(this).bind("mouseenter", function(e) {
            $(this).stop().animate({ opacity: 0 }, 300);
        });
        $(this).bind("mouseleave", function(e) {
            $(this).stop().animate({ opacity: 1 }, 300);
        });

    });
});


function signupNewUser() {
    showPopin($(".ui-popin-signup").attr("href"), "405", "388", "signup_popin_div");
    return false;
}

function PromptDelete() {
    
    return confirm("Are you sure you want to delete this item?");
}

function signUpAndAddToRecipeBox(in_id, in_servings) {
    showPopin("/RecipeBox/NewUser.aspx?SignupType=RECIPE&Display=AJAX&RecipeId=" + in_id + "&Servings=" + in_servings, "405", "388", "signup_popin_div");
    return false;
}

function loadDefaultSubNav() {

    if (curNavSection != undefined && curNavSection != "") {

        $("#navigation > ul > li > ul." + curNavSection).show();
    }
}