﻿
/// <reference path="../MapUtils.js" />
/// <reference path="../AgilityData.js" />



Agility.RegisterNamespace("Subaru.WelcomeScreen");

(function(WelcomeScreen) {

    var NotHereDialog = null;

    WelcomeScreen.OnInit = function(DialogID, swfFile) {
        NotHereDialog = $("#" + DialogID).dialog({
            autoOpen: false,
            modal: true,
            closeText: 'hide',
            dialogClass: 'NotHereDialog',
            title: "",
            resizable: false
        });

        WelcomeScreen.LoadWelcomeScreen(swfFile);
    }

    WelcomeScreen.Close = function() {
        try {
            $("#WelcomeScreenContent").hide();
        }
        catch (e) { }
        try {
            //Subaru.MapUtils.DeleteYouAreHereLayer();
        } catch (e) { }


    }

    WelcomeScreen.ShowNotHereDialog = function(closeWelcomeScreen) {
    
        NotHereDialog.dialog("open");
    
        if (closeWelcomeScreen) {
            WelcomeScreen.Close();
        }

        Subaru.AgilityData.LoadContentItem("EnterLocationPanel", WelcomeScreen.ShowNotHereDialogCallback);

    }

    WelcomeScreen.ShowNotHereDialogCallback = function(data) {
        var panel = $("#NotHereDialogArea");
        var templateUrl = Agility.ResolveUrl("~/ClientTemplates/FindLocation.htm");
        panel.setTemplateURL(templateUrl);
        panel.setParam("IntroText", Subaru.AgilityData.FindContentItemProperty(data, "IntroText"));
        panel.setParam("CityLabel", Subaru.AgilityData.FindContentItemProperty(data, "CityLabel"));
        panel.setParam("ProvinceLabel", Subaru.AgilityData.FindContentItemProperty(data, "ProvinceLabel"));
        panel.setParam("PostalCodeLabel", Subaru.AgilityData.FindContentItemProperty(data, "PostalCodeLabel"));
        panel.setParam("FindMeButton", Subaru.AgilityData.FindContentItemProperty(data, "FindMeButton"));


        panel.processTemplate(Subaru.AgilityData.Provinces);


        RefreshRollOvers();



        $("#NotHereDialogArea").keydown(function(event) {
            if (event.keyCode == 13) {
                Subaru.WelcomeScreen.SetLocation('txtCityLocation', 'ddlProvince', 'txtPostalCodeLocation');
                return false;
            }
        });
    }

    WelcomeScreen.SetLocation = function(txtCityLocation, ddlProvince, txtPostalCodeLocation) {
        var city = $("#" + txtCityLocation).val();
        var province = $("#" + ddlProvince).val();
        var postalCode = $("#" + txtPostalCodeLocation).val();



        Subaru.MapUtils.SetLocation(city, province, postalCode);
        $("#NotHereDialogArea").unbind("keydown", null);
        NotHereDialog.dialog("close");


    }


    WelcomeScreen.LoadWelcomeScreen = function(fileURL) {
        var so = new SWFObject(fileURL, "videoplayer", "481", "300", "8", "#ffffff");

        so.addParam("wmode", "transparent");
        so.addParam("AllowScriptAccess", "always");
        so.write("WelcomeScreenContent");
    }

})(Subaru.WelcomeScreen);


function CloseWelcomeScreen() {
    Subaru.WelcomeScreen.Close();
}