function pageInit() {
    myCitiesInit();
    weatherInit();
    clockInit();
    try {
        currencyInit();
    } catch(e) { }
    try {
        eventsInit();
    } catch(e) { }
}

var MyCities;

function myCitiesInit() {
    MyCities = new myCities();
    try {
        MyCities.Init();
    } catch (e) { }

    $("li#myCitiesActionsRemove").click(function() {
        MyCities.DropAndSave();
    });

    $("li#myCitiesActionsGo").click(function() {
        MyCities.Go();
    })

    $("div#myCities").show();
}

function weatherInit() {
    if ($("div#weatherBoxes").get().length) {
        //set event handlers
        $("img.weatherButtonNext").click(function() {
            handleWeatherControl(this, 1);
        });

        $("img.weatherButtonBack").click(function() {
            handleWeatherControl(this, -1);
        })

        //set z-indexes
        $("div.weatherBox").each(function() {
            if (this.id.indexOf("weatherBox_") > -1) {
                this.style.zIndex = this.id.replace("weatherBox_", "");
            }
        });

        //show first box & parent box
        $("div#weatherBox_0").show();
        $("div#weatherBoxes").show();
    }
}

function handleWeatherControl(objArrow, intChange) {
    var sourceBox = objArrow.parentNode.parentNode.parentNode.parentNode.parentNode;
    if (intChange == 1) {
        var sourceIndex = parseInt(sourceBox.id.replace("weatherBox_", ""));
        var targetIndex = sourceIndex + intChange;
        var targetBox = $("div#weatherBox_" + targetIndex);
        targetBox.show("slide", { direction: "right", easing: "swing" }, "medium");
    } else {
        $("div#" + sourceBox.id).hide("slide", { direction: "right", easing: "swing" }, "medium");
    }
}

function clockInit() {
    if ($("div#guideClock").get().length !== 0) {
        var skyClockVars = { cityName: MyCities.CityList.getPropertyValue("linkname", citySelectionImport, "location"), timezone: cityTimeZoneImport };
        var skyClockParams = { bgcolor: "#FFFFFF", wmode: "transparent" };
        var skyClockAttributes = {};
        swfobject.embedSWF("/swf/skyClock.swf", "guideClock", "160", "120", "9.0.0", false, skyClockVars, skyClockParams, skyClockAttributes);

        $("#guideClock").show();
    }
}
