/// <reference path="lib/jquery-1.3.2.js" />

var CCI; if (!CCI) { CCI = {}; }
if (!CCI.Pages) { CCI.Pages = {}; }
if (!CCI.Pages.Home) { CCI.Pages.Home = {}; }

var ServerProperties;

CCI.Pages.Home.LoadSWF = function() {
    if (ServerProperties && ServerProperties.RootPath && ServerProperties.Partner) {
        var flashvars = {};
        flashvars.signUpTodayURL = ServerProperties.RootPath + "Cart";
        var params = { wmode: "opaque" };
        var attributes = {};
        attributes.id = "homeswf";
        swfobject.embedSWF(ServerProperties.RootPath + "Content/swf/Home-" + ServerProperties.Partner + ".swf", "swfHolder", "950", "288", "9.0.0", false, flashvars, params, attributes);
    }
}

CCI.Pages.Home.BindContact = function() {
    if (BoundData.SmartForm && BoundData.SmartForm.Step1) {
        if (BoundData.SmartForm.Step1 == 1) {
            if (BoundData.SmartForm.Step2) {
                $("#step2").fadeIn("slow");
                if (!BoundData.SmartForm.Step3) {
                    $("#inputForm").fadeOut("slow", function() { $("#inputForm").hide(); });
                    $("#step3").fadeOut("slow", function() {
                        CCI.Utility.RenderPartial("step3", "SmartFormQuestions", "Home", null, $("#pageForm").serialize(), function() {
                            $("#step3").fadeIn("slow");
                        });
                    });
                } else {
                    if (!$("#answer_" + BoundData.SmartForm.Step3).is(":visible")) {
                        if ($(".answerBox div.answerBoxAnswer").is(":visible")) {
                            $(".answerBox div.answerBoxAnswer").hide();
                            $("input[name='PrintAnswer'][value='true']").removeAttr("checked");
                            $("input[name='PrintAnswer'][value='false']").attr("checked", "checked");
                            BoundData.SmartForm.WasAnswered = null;
                            BoundData.Bound(true);
                        }
                        $("#answer_" + BoundData.SmartForm.Step3).show();
                        CCI.Utility.CMPageviewTag('Smart Form Answer ' + BoundData.SmartForm.Step3, '250' + BoundData.SmartForm.Step3, '2500');
                    }

                    $("#SmartFormAnswer").fadeIn("slow");

                    if (BoundData.SmartForm.WasAnswered === "true") {
                        $("#inputForm").fadeOut("slow", function() {
                            $("#NextSteps").fadeIn("slow");
                        });
                    } else if (BoundData.SmartForm.WasAnswered === "false") {
                        $("#NextSteps").fadeOut("slow", function() {
                            $("#NextSteps").hide();
                            $("#inputForm").fadeIn("slow");
                        });
                    } else if (BoundData.SmartForm.WasAnswered === null) {
                        $("#NextSteps").fadeOut("slow");
                        $("#inputForm").fadeOut("slow");
                    }
                }
            } else {
                $("#inputForm").fadeOut("slow", function() {
                    $("#step2").fadeIn("slow");
                });
            }
        } else {
            BoundData.SmartForm.WasAnswered = null;
            $("#step3").fadeOut("slow");
            $("#step2").fadeOut("slow", function() {
                $("#step2").hide();
                BoundData.SmartForm.Step2 = 0;
                $("#inputForm").fadeIn("slow");
            });
        }
    }
}




CCI.Pages.Home.AARPInit = function() {
    CCI.Pages.Home.MBVidInit();
}

CCI.Pages.Home.AAAInit = function() {
    CCI.Pages.Home.MBVidInit();
}

CCI.Pages.Home.IndexInit = function() {
    CCI.Pages.Home.LoadSWF();
    CCI.Map.Init();
}

CCI.Pages.Home.ContactInit = function() {
    $("#PrintAnswer").live("click", function() {
        if ($(this).val() === "true") {
            window.print();
        }
    });

    $("#SmartForm_HasAnotherQuestion-yes").live("click", function() {
        BoundData.SmartForm = null;
        BoundData.Bound();
    });

    $("#SmartForm_Step2").change(function() {
        if (BoundData.SmartForm.Step3) {
            BoundData.SmartForm.Step3 = null;
        }
    });

    $("input[name='SmartForm.SendingEmail']").remove();
    $("input[name='SmartForm.LastStep1']").remove();
    
    BoundData.OnBound.push(CCI.Pages.Home.BindContact);
    CCI.Pages.Home.BindContact();
}


