////////////////////////////////////////////////////////////////////////////////
// 月齢ガジェット
//   Copyright (C) 2008 - 2009 AAOh inc.
////////////////////////////////////////////////////////////////////////////////

/**
 * @fileOverview 月齢ガジェット
 * @author       $Author: fujishiro $
 */

(function () {
/**
 * moonage。
 *
 * @namespace
 */
moonage = {
}
})();

(function () {
/**
 * Control。
 *
 * @constructor
 */
moonage.Control = aaoh.kaze.Gadget.extend(
	aaoh.sora.ControlEx, function() {
	// Application名。
	this.APP_NAME    = 'moonage';
	this.APP_VERSION = '2.0.0.0';

	// Windowサイズ。
	this.WINDOW_ONDOCK_WIDTH         =  80 +  0;
	this.WINDOW_ONDOCK_HEIGHT        =  80 + 12;
	this.WINDOW_UNDOCK_WIDTH         = 370 + 0;
	this.WINDOW_UNDOCK_HEIGHT        = 550 + 12;
	this.WINDOW_ONDOCK_MOBILE_WIDTH  = this.WINDOW_ONDOCK_WIDTH;
	this.WINDOW_ONDOCK_MOBILE_HEIGHT = this.WINDOW_ONDOCK_HEIGHT;
	this.WINDOW_UNDOCK_MOBILE_WIDTH  = this.WINDOW_ONDOCK_MOBILE_WIDTH;
	this.WINDOW_UNDOCK_MOBILE_HEIGHT = this.WINDOW_ONDOCK_MOBILE_HEIGHT;
	this.WINDOW_OPTION_WIDTH         = 250 +  0;
	this.WINDOW_OPTION_HEIGHT        = 200 + 12;
	this.WINDOW_OPTION_MOBILE_WIDTH  = 230 +  0;
	this.WINDOW_OPTION_MOBILE_HEIGHT = 130 + 12;
	if (aaoh.kaze.Type.isSidebar()) {
		this.WINDOW_ONDOCK_WIDTH = 130;
	}

	// デフォルト値
	this.INTERVAL = 60 * 60 * 1000; // 再表示インターバル(msec)

	this.MONNAGE_VALUE  = 29.530588853;
	this.MONNAGE_NEW    = 1   * this.MONNAGE_VALUE; // 朔望に対する月齢
	this.MONNAGE_WAXING = 1 / 4 * this.MONNAGE_VALUE;
	this.MONNAGE_FULL   = 1 / 2 * this.MONNAGE_VALUE;
	this.MONNAGE_WANING = 3 / 4 * this.MONNAGE_VALUE;
})
})();

(function () {
/**
 * Model。
 *
 * @constructor
 */
moonage.Model = aaoh.kaze.Gadget.extend(
	aaoh.sora.ModelEx, function() {
	this.data.type = '1';
});
	/**
	 * 設定情報の読込み(iGoogle)。
	 */
	moonage.Model.prototype.
	readDataForIGoogle = function() {
		var type = aaoh.sora.App.control.storage.readString('type');

		if (type != null) {
			this.data.type = type;
		}
	}

	/**
	 * 設定情報の書込み(iGoogle)。
	 */
	moonage.Model.prototype.
	writeDataForIGoogle = function() {
		aaoh.sora.App.control.storage.writeString(
			'type', this.data.type
		);
	}
})();

(function () {
/**
 * App。
 *
 * @namespace
 */
aaoh.sora.App = {
	control: new moonage.Control(),
	model:   new moonage.Model(),
	main:    null,
	option:  null,

	/**
	 * 初期化。
	 *
	 * @param {String} target 初期化するターゲット
	 */
	init: function(target) {
		if (
			target != null && target == aaoh.sora.App.control.MAIN_NM
		) {
			aaoh.sora.App.main   = new moonage.Main();
			aaoh.sora.App.option = null;

		} else if (
			target != null && target == aaoh.sora.App.control.OPTION_NM
		) {
			aaoh.sora.App.main   = null;
			aaoh.sora.App.option = new moonage.Option();

		} else {
			aaoh.sora.App.main   = new moonage.Main();
			aaoh.sora.App.option = new moonage.Option();
		}

		// バージョンチェックを行う
		aaoh.sora.App.control.FLG_UPDATE = true;

		aaoh.sora.App.control.init();
	}
}
})();
