	function status(s) {
	$("#status").html($("#status").html() + "<br />" + s);
}

function checkForm(form, selectors) {
	errors = 0;
	form.find(selectors).each(function() {
		$this = $(this);
		if ($this.val() == ""	// check for blank
			|| ($this.attr("name").indexOf("email") > -1 && !HERSHEYS.Utility.validate("email", $this.val()))	// validate email address
			|| ($this.attr("name").indexOf("_confirm") > -1 && form.find("input[name=" + $this.attr("name").replace("_confirm", "") + "]").val() != $this.val())	// check confirm field
		) {
			$this.prev("label").addClass("error");
			errors++;
		} else {
			$this.prev("label").removeClass("error");
		}
	});
	return errors;
}

function serializeForm(form) {
	$values = {};
	$form.find("input, select").each(function() {
		$this = $(this);
		if ($this.attr("name").indexOf("_confirm") > -1) {
			;
		} else if ($this.attr("type") == "checkbox")
			$values[$this.attr("var")] = $this.attr("checked");
		else
			$values[$this.attr("var")] = $this.val();

//			if ($this.attr("name").
//			alert($(this).attr("var"));
	});
	return $values;
}

var WEB_SERVICE_URL = '/celebrate/services/AjaxServices.ashx'; //TODO: timmy: are we using this celebrate.js? or the one under hersheys.com?
var rate = false;
var $form = {}
var d = 400;

$(document).ready(function () {

    //alert('celebrate.js location.hash: ' + location.hash);

    var myUrl = window.location;
    // Recipes section pages
    if (myUrl.toString().indexOf("recipes") > -1) {
        $('#content-wrapper').addClass('recipes');
    }
    if (myUrl.toString().indexOf("recipedetail.aspx") > -1) {
        $('#content-wrapper').addClass('recipes');
    }

    // Crafts section pages
    if (myUrl.toString().indexOf("crafts") > -1) {
        $('#content-wrapper').addClass('crafts');
    }
    if (myUrl.toString().indexOf("craftdetail.aspx") > -1) {
        $('#content-wrapper').addClass('crafts');
    }

    // Products section pages
    if (myUrl.toString().indexOf("products") > -1) {
        $('#content-wrapper').addClass('products');
    }
    if (myUrl.toString().indexOf("productdetail.aspx") > -1) {
        $('#content-wrapper').addClass('products');
    }

    // Search results section pages
    if (myUrl.toString().indexOf("searchresults.aspx") > -1) {
        $('#content-wrapper').addClass('recipes');
    }

    // Fun Stuff section pages
    if (myUrl.toString().indexOf("fun-stuff") > -1) {
        $('#content-wrapper').addClass('fun-stuff');
        $('body').addClass('fun-stuff');
    }

    // Videos section pages
    if (myUrl.toString().indexOf("videos") > -1) {
        $('#content-wrapper').addClass('videos');
        $('body').addClass('videos');
    }

    $(".subnav").each(function () {
        $(this).hide();
    });
    $(".pod .popup").each(function () {
        $(this).attr("h", $(this).height());
        $(this).css({ bottom: "-" + (parseInt($(this).attr("h")) - 33) + "px" });
    });
    $(".pod").hover(function () {
        $(this).find(".popup").stop(true, true).delay(d).animate({ bottom: 0 });
    }, function () {
        $popup = $(this).find(".popup");
        $popup.stop(true, true).delay(d).animate({ bottom: "-" + (parseInt($popup.attr("h")) - 33) + "px" });
    });

    $("#nav > li").hover(function () {
        //if ((HERSHEYS.CURRENT_SEASON == "valentines" || HERSHEYS.CURRENT_SEASON == "holidays") && $(this).hasClass("crafts"))
        //    return false;
        if ($(this).hasClass("crafts") && $("#nav .crafts ul.subnav li").length == 0) {
            return false;
        }

        $(this).children("ul.subnav").stop(true, true).delay(d).slideDown();
    }, function () {
        $(this).children("ul.subnav").stop(true, true).delay(d).slideUp();
    });
    $("ul.subnav").hover(function (e) {
        $(this).stop(true, true);
    }, function () {
        $(this).stop(true, false).delay(d).slideUp();
    });

    $("#header .searchTextBox").focus(function () {
        $(this).addClass("focus");
    });
    $("#header .searchTextBox").blur(function () {
        if ($(this).val() == "Search")
            $(this).removeClass("focus");
    });


    $("#header #search-but").click(function () {
        //window.location.href = "/celebrate/searchresults.aspx?KW=" + $("#header .searchTextBox").val();
        window.location.href = "/celebrate/" + HERSHEYS.CURRENT_SEASON + "/searchresults.aspx?KW=" + $("#header .searchTextBox").val();
        return false;
    });

    ratingsOverlay = {
        show: function (type) {
            $("#review-this-" + type).animate({ left: "0" });
            $("#reviews-wrapper").animate({ left: "100%" }, 150);
            $("#rate-this").css("visibility", "hidden");
        },
        hide: function (type) {
            $("#review-this-" + type).animate({ left: "-100%" }, 150);
            $("#reviews-wrapper").animate({ left: "0" });
            $("#rate-this").css("visibility", "visible");
        }
    }

    /* if not logged in, bind rating links */
    if (HERSHEYS.IsLoggedIn) {
        $(".recipes #rate-this").click(function () {
            ratingsOverlay.show("recipe");
            return false;
        });

        $(".crafts #rate-this").click(function () {
            ratingsOverlay.show("craft");
            return false;
        });

        $(".recipes #view-rating-details-fb").click(function () {
            ratingsOverlay.hide("recipe");
            return false;
        });

        $(".crafts #view-rating-details-fb").click(function () {
            ratingsOverlay.hide("craft");
            return false;
        });
    }

    /* FANCYBOX INITS */
    /* global */
    $("#ad-alert").fancybox({
        "padding": 0,
        "onStart": function () {
            $("#fancybox-wrap").removeClass("green").addClass("blue");
        }
    });
    $("#leaving").fancybox({
        "padding": 0,
        "onStart": function () {
            $("#fancybox-wrap").removeClass("green").addClass("blue");
        }
    });

    //////    if (location.protocol.toLowerCase() != 'https:') {
    //////        alert('not https');
    //////        $("#signup, #login").click(function () {
    //////            window.location = window.location.href.replace("http:", "https:").replace("#fb-login", "") + "#fb-login";
    //////        });
    //////    }
    //////    else {
    //////        alert('https');
    //////        $("#signup, #login").fancybox({
    //////            "padding": 0,
    //////            "onStart": function () {
    //////                $("#fancybox-wrap").removeClass("green").addClass("blue");
    //////            }
    //////        });
    //////    }
    $("#signup, #login").fancybox({
        "padding": 0,
        "onStart": function () {
            $("#fancybox-wrap").removeClass("green").addClass("blue");
        }
    });

    $("#forgot-username, #forgot-password").fancybox({
        "padding": 0,
        "onStart": function () {
            $("#fancybox-wrap").addClass("blue");
        }
    });
    $("#profile").fancybox({
        "padding": 0,
        "onStart": function () {
            HERSHEYS.Services.getprofile({
                "success": function (data) {
                    userInfo = {};
                    q = data.split("&");
                    for (var i = 0; i < q.length; i++) {
                        eval("userInfo." + q[i].split('=')[0] + " = q[i].split('=')[1]");
                    }
                    for (key in userInfo) {
                        $this = $("#fb-profile").find("[var=" + key + "]");
                        if ($this.attr("type") == "checkbox" && eval("userInfo." + key) == "True")
                            $this.attr("checked", "checked");
                        else
                            $this.val(eval("userInfo." + key));
                    }
                },
                "failure": function () {
                    /*  alert("There was an retrieving your profile info, please try again."); */
                    $.fancybox($("#fb-failProfile"));
                }
            });
            $("#fancybox-wrap").removeClass("green").addClass("blue");
        }
    });
    /* crafts */
    $(".crafts #view-ratings, .crafts #view-rating-details").fancybox({
        "padding": 0,
        "onStart": function () {
            $("#fancybox-wrap").removeClass("blue").addClass("green");
            ratingsOverlay.hide("craft");
        }
    });
    $(".crafts #review-craft").fancybox({
        "href": HERSHEYS.IsLoggedIn ? "#rate-craft" : "#fb-login",
        "padding": 0,
        "onStart": function () {
            $("#fancybox-wrap").removeClass("blue").addClass("green");
            if (HERSHEYS.IsLoggedIn)
                ratingsOverlay.show("craft");
            else {
                $("#fancybox-wrap").removeClass("green").addClass("blue");
                rate = true;
            }
        }
    });
    $(".crafts #share-this-craft").fancybox({
        "padding": 0,
        "onStart": function () {
            $("#fancybox-wrap").addClass("green");
        }
    });
    $(".videos #share-this-video").fancybox({
        "padding": 0,
        "onStart": function () {
            $("#fancybox-wrap").addClass("green");
        }
    });
    $(".recipes #share-this-recipe").fancybox({
        "padding": 0,
        "onStart": function () { }
    });
    /* recipes */
    $(".recipes #view-ratings, .recipes #view-rating-details").fancybox({
        "padding": 0,
        "onStart": function () {
            $("#fancybox-wrap").addClass("blue");
            ratingsOverlay.hide("recipe");
        }
    });
    $(".recipes #review-recipe").fancybox({
        "href": HERSHEYS.IsLoggedIn ? "#rate-recipe" : "#fb-login",
        "padding": 0,
        "onStart": function () {
            $("#fancybox-wrap").addClass("blue");
            if (HERSHEYS.IsLoggedIn)
                ratingsOverlay.show("recipe");
            else {
                //				$("#fancybox-wrap").removeClass("green").addClass("blue");
                rate = true;
            }
        }
    });

    /* if not logged in, rebind rating links */
    if (!HERSHEYS.IsLoggedIn) {
        $("#review-recipe, #rate-this").attr("href", "#fb-login");
        $(".recipes #rate-this").click(function () {
            $.fancybox($("#fb-login"));
            rate = true;
        });
        $(".crafts #rate-this").click(function () {
            $.fancybox({
                href: "#fb-login",
                onClosed: function () {
                    rate = false;
                }
            });
            $("#fancybox-wrap").addClass("blue").removeClass("green");
            rate = true;
        });
    }

    /* sort of utility functions */
    $("#refresh-captcha, #refresh-captcha-profile").click(function () {
        $('.pr_form_captcha_img').attr('src', '/celebrate/services/captcha.aspx?' + Math.random());
        return false;
    });

    $("#logout").click(function () {
        HERSHEYS.Services.logout({
            "success": function () {
                //alert("/" + HERSHEYS.CURRENT_PAGE + ".aspx");
                //window.location.href = "/" + HERSHEYS.CURRENT_PAGE + ".aspx";
                window.location.href = "/" + HERSHEYS.CURRENT_PAGE;
            },
            "failure": function () {
                alert("There was an error logging you out, please try again.");
                $.fancybox($("#fb-logoutError"));
            }
        });
        return false;
    });

    /* FORM SUBMIT BINDS */
    /* login */
    $("#submit-login").click(function () {
        //alert('submit-login');

        //        if (location.protocol.toLowerCase() != 'https:') {
        //            window.location = window.location.href.replace("http:", "https:") + "#fb-login";
        //        }

        $form = $(".form-login");
        $values = {
            username: $form.find("#username").val(),
            password: $form.find("#password").val()
        };
        if (!checkForm($form, "input")) {
            HERSHEYS.Services.login({
                "username": $values.username,
                "password": $values.password,
                "success": function () {
                    if (rate) {
                        window.location.hash = "#rate-" + page;
                        window.location.reload();
                    } else
                    //alert("/" + HERSHEYS.CURRENT_PAGE + ".aspx" + (rate ? "#rate" : ""));
                    //window.location = "/" + HERSHEYS.CURRENT_PAGE + ".aspx" + (rate ? "#rate" : "");

                    //////                    if (location.protocol.toLowerCase() == 'https:') {
                    //////                        window.location = window.location.href.replace("https:", "http:").split('#')[0] + (rate ? "#rate" : "");
                    //////                    }
                    //////                    else {
                    //////                        window.location = "/" + HERSHEYS.CURRENT_PAGE + (rate ? "#rate" : "");
                    //////                    }
                        window.location = "/" + HERSHEYS.CURRENT_PAGE + (rate ? "#rate" : "");

                },
                "failure": function () {
                    alert("There was an error logging you in, please try again.");
                    $.fancybox($("#fb-loginError"));
                }
            });
        }
        return false;
    });
    /* sign up - DOB */
    $("#submit-signup-dob").click(function () {
        $form = $(".form-signup-dob");
        $values = {
            day: $form.find(".dob-day option:selected").val(),
            month: $form.find(".dob-month option:selected").val(),
            year: $form.find(".dob-year option:selected").val()
        };
        if (!checkForm($form, "select")) {
            HERSHEYS.Services.agecheck({
                "day": $values.day,
                "month": $values.month,
                "year": $values.year,
                "success": function () {
                    $.fancybox($("#fb-signup"));
                },
                "failure": function () {
                    $.fancybox($("#fb-underage"));
                }
            });
        }
        return false;
    });
    /* sign up - full form */
    $("#submit-signup").click(function () {
        //alert('submit-signup');
        $form = $("#fb-signup");
        errors = 0;
        if (!checkForm($form, "input, select")) {
            $values = serializeForm($form);
            HERSHEYS.Services.signup({
                "firstname": $values.firstname,
                "lastname": $values.lastname,
                "username": $values.username,
                "password": $values.password,
                "email": $values.email,
                "address": $values.address,
                "city": $values.city,
                "state": $values.state,
                "zip": $values.zip,
                "captcha": $values.captcha,
                "optinHersheys": $values.optinHersheys,
                "optinNewsletter": $values.optinNewsletter,
                "success": function () {
                    //					alert("loggin in with " + $values.username + "/" + $values.password);
                    HERSHEYS.Services.login({
                        "username": $values.username,
                        "password": $values.password,
                        "success": function () {
                            if (rate) {
                                window.location.hash = "#rate-" + page;
                                window.location.reload();
                            } else
                            ////alert("/" + HERSHEYS.CURRENT_PAGE + ".aspx" + (rate ? "#rate" : ""));
                            //window.location = "/" + HERSHEYS.CURRENT_PAGE + ".aspx" + (rate ? "#rate" : "");
                                window.location = "/" + HERSHEYS.CURRENT_PAGE + (rate ? "#rate" : "");
                        },
                        "failure": function () {
                            /*  alert("There was an error logging you in, please try again.");  */
                            $.fancybox($("#fb-loginError"));
                        }
                    });
                    //				$.fancybox($("#fb-signup"));
                },
                "failure": function (data) {
                    //refresh CAPTCHA in the event of an error
                    $('.pr_form_captcha_img').attr('src', '/celebrate/services/captcha.aspx?' + Math.random());
                    alert("There was an error signing you up: " + data.replace("0=", ""));
                    //				$.fancybox($("#fb-underage"));
                }
            });
        } else {
            //refresh CAPTCHA in the event of an error
            $('.pr_form_captcha_img').attr('src', '/celebrate/services/captcha.aspx?' + Math.random());
            alert("Please correct the highlighted fields.");
        }

        return false;
    });
    /* edit profile */
    $("#submit-edit").click(function () {
        $form = $("#fb-profile");
        errors = 0;
        if (!checkForm($form, "input, select")) {
            $values = serializeForm($form);
            //return false;
            HERSHEYS.Services.editprofile({
                "firstname": $values.firstname,
                "lastname": $values.lastname,
                "password": $values.password,
                "email": $values.email,
                "address": $values.address,
                "city": $values.city,
                "state": $values.state,
                "zip": $values.zip,
                "captcha": $values.captcha,
                "optinHersheys": $values.optinHersheys,
                "optinNewsletter": $values.optinNewsletter,
                "success": function () {
                    $.fancybox($("#fb-updated"));
                },
                "failure": function (data) {
                    //refresh CAPTCHA in the event of an error
                    $('.pr_form_captcha_img').attr('src', '/celebrate/services/captcha.aspx?' + Math.random());
                    alert("There was an error updating your profile: " + data.replace("0=", ""));
                }
            });
        } else {
            //refresh CAPTCHA in the event of an error
            $('.pr_form_captcha_img').attr('src', '/celebrate/services/captcha.aspx?' + Math.random());
            alert("Please correct the highlighted fields.");
        }

        return false;
    });
    /* review recipe */
    $("#rate-recipe-submit").click(function () {
        $form = $("#review-this-recipe");
        $values = {
            recipeID: $form.find("input[name='recipeID']").val(),
            overallrating: $form.find("input[name='overall']:checked").val(),
            tasterating: $form.find("input[name='taste']:checked").val(),
            difficultyrating: $form.find("input[name='difficulty']:checked").val(),
            appearancerating: $form.find("input[name='appearance']:checked").val(),
            reviewtext: $form.find("#review-recipe-text").val()
        };
        HERSHEYS.Services.reviewRecipe({
            "recipeID": $values.recipeID,
            "overallrating": $values.overallrating,
            "tasterating": $values.tasterating,
            "difficultyrating": $values.difficultyrating,
            "apperancerating": $values.appearancerating,
            "reviewtext": $values.reviewtext,
            "success": function () {
                alert("Review submitted succesfully.");
                ////alert("/" + HERSHEYS.CURRENT_PAGE + ".aspx");
                //window.location.href = "/" + HERSHEYS.CURRENT_PAGE + ".aspx";
                window.location.href = "/" + HERSHEYS.CURRENT_PAGE;
            },
            "failure": function () {
                alert("There was an error submitting your review, please try again.");
            }
        });
        return false;
    });
    /* share recipe */
    $("#submit-share-recipe").click(function () {
        $form = $("#share-recipe");
        if (!checkForm($form, "input")) {
            $values = serializeForm($form);
            $.fancybox.showActivity();
            HERSHEYS.Services.shareRecipe({
                "recipeid": $values.recipeID,
                "name": $values.name,
                "email": $values.email,
                "friendname": $values.friendname,
                "friendemail": $values.friendemail,
                "src": $values.src,
                "success": function () {
                    $.fancybox($("#fb-shared"));
                },
                "failure": function () {
                    alert("There was an error sending, please try again.");
                    $.fancybox.hideActivity();
                }
            });
        } else
            alert("Please correct the highlighted fields.");
        return false;
    });
    /* review craft */
    $("#submit-rate-craft").click(function () {
        $form = $("#review-this-craft");
        $values = {
            craftID: $form.find("input[name='craftID']").val(),
            overallrating: $form.find("input[name='overall']:checked").val(),
            reviewtext: $form.find("#review-craft-text").val()
        };
        HERSHEYS.Services.reviewCraft({
            "craftID": $values.craftID,
            "overallrating": $values.overallrating,
            "reviewtext": $values.reviewtext,
            "success": function () {
                alert("Review submitted succesfully.");
                ////alert("/" + HERSHEYS.CURRENT_PAGE + ".aspx");
                //window.location.href = "/" + HERSHEYS.CURRENT_PAGE + ".aspx";
                window.location.href = "/" + HERSHEYS.CURRENT_PAGE;
            },
            "failure": function () {
                alert("There was an error submitting your review, please try again.");
            }
        });
        return false;
    });
    /* share craft */
    $("#submit-share-craft").click(function () {
        $form = $("#share-craft");
        if (!checkForm($form, "input")) {
            $values = serializeForm($form);
            $.fancybox.showActivity();
            HERSHEYS.Services.shareCraft({
                "craftID": $values.craftID,
                "name": $values.name,
                "email": $values.email,
                "friendname": $values.friendname,
                "friendemail": $values.friendemail,
                "success": function () {
                    $.fancybox($("#fb-shared"));
                },
                "failure": function () {
                    alert("There was an error sending, please try again.");
                    $.fancybox.hideActivity();
                }
            });
        } else
        /*  alert("Please correct the highlighted fields.");  */
            $.fancybox($("#fb-highlightedFields"));
        return false;
    });

    /* share video */
    $("#submit-share-video").click(function () {

        $form = $("#share-video");
        if (!checkForm($form, "input")) {
            $values = serializeForm($form);
//            alert($values.videoURL + " , " + $values.videoName + " , " + $values.name + "," + $values.email + "," + $values.friendname + "blah");
            $.fancybox.showActivity();
           
            HERSHEYS.Services.shareVideo({
                "videoURL": $values.videoURL,
                "videoName": $values.videoName,
                "name": $values.name,
                "email": $values.email,
                "friendname": $values.friendname,
                "friendemail": $values.friendemail,
                "success": function () {
                    $.fancybox($("#fb-shared"));
                },
                "failure": function () {
                    alert("There was an error sending, please try again.");
                    $.fancybox.hideActivity();
                }
            });
        } else
        /*  alert("Please correct the highlighted fields.");  */
            $.fancybox($("#fb-highlightedFields"));
        return false;
    });

    /* forgot username/password */
    $("#submit-forgot").click(function () {
        $form = $("#fb-forgot");
        $.fancybox.showActivity();
        HERSHEYS.Services.forgotpassword({
            "email": $form.find("input#forgot").val(),
            "success": function () {
                $.fancybox($("#fb-reminder-sent"));
            },
            "failure": function () {
                alert("There was an error sending, please try again.");
                $.fancybox.hideActivity();
            }
        });
        return false;
    });

    /* share */
    HERSHEYS.ShareThis.init();
    $(".share_button").html("Share <span>+</span>");

    /* HERSHEYS additional methods */
    /* review craft */
    HERSHEYS.Services.reviewCraft = function (opts) {
        var post = {
            craftID: opts['craftID'] || 0,
            reviewtext: opts['reviewtext'] || '',
            overallrating: opts['overallrating'] || 0
        };

        var success = opts['success'] || function () { };
        var failure = opts['failure'] || function () { };

        $.post(WEB_SERVICE_URL + '?method=submitcraftreview', post, function (data) {
            if (data == 1) {
                success();
            } else {
                failure();
            }
        });
    };

    /* share craft */
    HERSHEYS.Services.shareCraft = function (opts) {
        var post = {
            craftID: opts['craftID'] || 0,
            name: opts['name'] || '',
            email: opts['email'] || '',
            friendname: opts['friendname'] || '',
            friendemail: opts['friendemail'] || ''
        };

        var success = opts['success'] || function () { };
        var failure = opts['failure'] || function () { };

        $.post(WEB_SERVICE_URL + '?method=sharecraft', post, function (data) {
            if (data == 1) {
                success();
            } else {
                failure();
            }
        });
    };

    /* share video */
    HERSHEYS.Services.shareVideo = function (opts) {
        var post = {
            videoURL: opts['videoURL'] || '',
            videoName: opts['videoName'] || '',
            name: opts['name'] || '',
            email: opts['email'] || '',
            friendname: opts['friendname'] || '',
            friendemail: opts['friendemail'] || ''
        };

        var success = opts['success'] || function () { };
        var failure = opts['failure'] || function () { };

        $.post(WEB_SERVICE_URL + '?method=sharevideo', post, function (data) {
            if (data == 1) {
                success();
            } else {
                failure();
            }
        });
    };





    /* logout */
    HERSHEYS.Services.logout = function (opts) {
        var success = opts['success'] || function () { };
        var failure = opts['failure'] || function () { };

        $.get(WEB_SERVICE_URL + '?method=logout', function (data) {
            if (data == 1) {
                HERSHEYS.IsLoggedIn = false;
                success();
            } else {
                failure();
            }
        });
    };
    /* forgot */
    HERSHEYS.Services.forgotpassword = function (opts) {
        var post = {
            email: opts['email'] || ''
        }
        var success = opts['success'] || function () { };
        var failure = opts['failure'] || function () { };

        $.post(WEB_SERVICE_URL + '?method=forgotpassword', post, function (data) {
            if (data == 1) {
                HERSHEYS.IsLoggedIn = false;
                success();
            } else {
                failure();
            }
        });
    };
    /* get profile */
    HERSHEYS.Services.getprofile = function (opts) {
        var success = opts['success'] || function () { };
        var failure = opts['failure'] || function () { };

        $.get(WEB_SERVICE_URL + '?method=getprofile', function (data) {
            if (data != "1=No info found") {
                success(data);
            } else {
                failure();
            }
        });
    };
    /* signup */
    HERSHEYS.Services.signup = function (opts) {
        var post = {
            firstname: opts['firstname'] || '',
            lastname: opts['lastname'] || '',
            username: opts['username'] || '',
            password: opts['password'] || '',
            email: opts['email'] || '',
            address: opts['address'] || '',
            city: opts['city'] || '',
            state: opts['state'] || '',
            zip: opts['zip'] || 0,
            captcha: opts['captcha'] || '',
            optinHersheys: opts['optinHersheys'] || false,
            optinNewsletter: opts['optinNewsletter'] || false
        };

        var success = opts['success'] || function () { };
        var failure = opts['failure'] || function () { };

        $.post(WEB_SERVICE_URL + '?method=signup', post, function (data) {
            if (data == 1) {
                success();
            } else {
                failure(data);
            }
        });
    };
    /* edit profile */
    HERSHEYS.Services.editprofile = function (opts) {
        var post = {
            firstname: opts['firstname'] || '',
            lastname: opts['lastname'] || '',
            password: opts['password'] || '',
            email: opts['email'] || '',
            address: opts['address'] || '',
            city: opts['city'] || '',
            state: opts['state'] || '',
            zip: opts['zip'] || 0,
            captcha: opts['captcha'] || '',
            optinHersheys: opts['optinHersheys'] || false,
            optinNewsletter: opts['optinNewsletter'] || false
        };

        var success = opts['success'] || function () { };
        var failure = opts['failure'] || function () { };

        $.post(WEB_SERVICE_URL + '?method=editprofile', post, function (data) {
            if (data == 1) {
                success();
            } else {
                failure(data);
            }
        });
    };

    /* other */
    if (window.location.hash.indexOf("#rate-recipe") > -1) {
        $("#fancybox-wrap").addClass("blue");
        ratingsOverlay.show("recipe");
        $.fancybox($(window.location.hash));
    } else if (window.location.hash.indexOf("#rate-craft") > -1) {
        $("#fancybox-wrap").addClass("green");
        ratingsOverlay.show("craft");
        $.fancybox($(window.location.hash));
    }
    //////    else if (window.location.hash.indexOf("#fb-login") > -1) {
    //////        //$("#fancybox-wrap").addClass("green");
    //////        //ratingsOverlay.show("craft");
    //////        $.fancybox($(window.location.hash));
    //////    }

    $(".preview").click(function () {
        var flashvars = {};
        var attributes = {};
        var param = {};
        $("#description").hide();
        $(".ssaver").show();
        swfobject.embedSWF("/assets/swf/celebrate/" + $(this).attr("rel") + ".swf", "ssavercontainer", "500", "373", "10.0.0", "/assets/swf/expressInstall.swf", flashvars, param, attributes, function (e) {
        });
        return false;
    });

    $(".showdownload").click(function () {
        $(".ssaver").hide();
        $("#description").show();
        return false;
    });

    // Adjust the footer to be the same width as its content
    var footerwidth = 0;
    $("#footer ul li").each(function () {
        if ($(this).css("display") != "none") {
            footerwidth += parseInt($(this).width());
        }
    });
    $("#footer").css("width", footerwidth);
});

