/* ぺぺぺぺ */

var BlogToy = Class.create();


BlogToy.Const = {
	signpost: {
		uid: 'ログインID',
		pw: 'パスワード'
	}
};


BlogToy.prototype = {
	initialize: function(callback, frequency) {

		this.initLoginForm();

		switch (document.body.className) {
			case 'partsIntro':
				this.initPartsIntro();
			break;

			case 'analytics':
				this.initAnalytics();
			break;

		}

		var bodyId = document.body.id;
		// top -> initTop
		var methodName = 'init' + bodyId.substr(0,1).toUpperCase() + bodyId.substr(1);
		// body.idがtop なら(あれば) this.initTop() する (あれば)
		bodyId && this[methodName] && this[methodName]();

/*

		if ($('btClip') && $('clipSWFWrapper')) {

			this.swfWrapper = 'clipSWFWrapper';
			this.swfId = 'clipSWF';
			this.swfPath = '/lib/external/swfclip/clipbrd.swf';

			this.codeId = 'stickyTag';

			var clipbrd_so = new SWFObject(
				this.swfPath, this.swfId, "1", "1", "8", "white");
			clipbrd_so.write(this.swfWrapper);

			if (navigator.appName.indexOf("Microsoft") != -1) {
				clipbrd = new Object();
				clipbrd.copyText = function(txt) {
				clipboardData.setData("Text", txt);
				}
			} else {
			 	clipbrd = document[this.swfId];
clipbrd.copyText(6);
			}

			Event.observe($('btClip'), 'click', this.clip.bind(this), false);
		}
*/


		if ($('btClip') && $('clipbrd_body_id')) {
			this.codeId = 'stickyTag';
			Event.observe($('btClip'), 'click', this.clip.bind(this), false);
		}


/*
		if ($('uid')) {
			$('pw').style.display = 'none';
			$('pwdw').innerHTML = '<input id="pwDummy" type="text" value="パスワード" class="loginData null" />';

			Event.observe($('uid'), 'focus', this.focusLogin, false);
			Event.observe($('pw'),  'focus', this.focusLogin, false);
			Event.observe($('pwDummy'), 'focus', this.focusLogin, false);

			Event.observe($('uid'), 'blur', this.unFocusLogin, false);
			Event.observe($('pw'),  'blur', this.unFocusLogin, false);
			Event.observe($('pwDummy'), 'blur', this.unFocusLogin, false);
		}
*/
	},

	initLoginForm: function() {

		/**
		 * (このへんの理由)
		 * ・JavaScriptオフでも、一応ログインだけはできるようにするため。
		 * ・ID/PW入力後、enterでもsubmitできるようにするため。
		 */

		if (! $('btLoginWrapper')) {
			return false;
		}

		var lw = $('btLoginWrapper');
/*
		var cid = document.getElementsByName('CID')[0];
		if (cid.value == '<!--CID-->') {
			lw.removeChild(cid);
		}
*/
		var input = lw.getElementsByTagName('input');
		for (var i=0; i<input.length; i++) {
			input[i].style.height = '1px';
			input[i].style.width = '1px';
			input[i].style.position = 'absolute';
			input[i].style.left = '-9999em';
		}

		var btLogin = document.createElement('a');
		btLogin.setAttribute('id', 'btLogin');
		btLogin.setAttribute('href', '/login');
		btLogin.onclick = function() { return false; };
		btLogin.appendChild(document.createTextNode('ログイン'));
		lw.appendChild(btLogin);

		Event.observe(btLogin, 'click', function() {
			$('login').submit();
		}, false);
	},

/*
	initTop: function() {
		var swfWrapper = $('recommendSWF');

		var s = document.createElement('script');
		s.setAttribute('charset', 'utf-8');
		s.setAttribute('type', 'text/javascript');
		s.setAttribute('src', 'http://sticky.blogtoy.dev.linkthink.jp/analog/5e8ff9bf55ba3508199d22e984129be6.js');
		swfWrapper.appendChild(s);
		var swAnc = $('swTabs').getElementsByTagName('a');
		for (var i=0; i<swAnc.length; i++) {
			swAnc[i].onclick = function() { return false };
			swAnc[i].setAttribute('href', '');
			Event.observe(swAnc[i], 'click', this.showCustomizeParts, false);
		}

		var sw = document.getElementsByName('swTab');

		for (var i=0; i<sw.length; i++) {
//			Event.observe(sw[i], 'click', this.showCustomizeParts, false);

			// 初回
			if (sw[i].getAttribute('checked')) {
				// sw[i].click();
				this.showCustomizeParts(sw[i].id.replace(/^rd/, 'tab'));
			}
		}
	},
*/


	initPartsIntro: function() {
		var stickIt = document.getElementsByClassName('stickIt');
		for (var i=0; i<stickIt.length; i++) {
			stickIt[i].onclick = function() {
				$('registerParts').submit()
				return false;
			};
		}

	},


	initParts: function() {
		if (! $('preview')) {
			return;
		}

		// flash書き出し (サンプルパーツ)
		//var swfMovie = this.fp_root + fp['path'] + dispType[this.fp_partsId].swfPath;

// alert(swfMovie);

		var so;
		so = new SWFObject(this.swfMovie, 'sampleParts', this.fp_swfWidth, this.fp_swfHeight, '7', this.fp_swfBG);

		so.addParam('useExpressInstall', true);
		so.addParam('quality', 'high');
		so.addParam('wmode', this.fp_swfWMode);
		so.addParam('loop', this.fp_swfLoop);
		so.addParam('menu', this.fp_swfMenu);
		so.addParam('AllowScriptAccess', this.fp_swfAllowScriptAccess);
		so.addParam('salign', 't');

		so.addVariable('domain', this.fp_domain);

		switch (document.body.id) {
			case 'analogSetting':
				so.addVariable('uid', this.fp_uid);

				so.addVariable('bgno', this.fp_bgno);
				so.addVariable('bgcolor', this.fp_bgcolor);
				so.addVariable('texcolor', this.fp_texcolor);

				so.addVariable('seccolor', this.fp_seccolor);
				so.addVariable('mincolor', this.fp_mincolor);
				so.addVariable('hourcolor', this.fp_hourcolor);

				so.addVariable('frame', this.fp_frame);
				so.addVariable('day', this.fp_day);
				so.addVariable('usebgimg', this.fp_usebgimg);
				this.fp_bgurl && so.addVariable('bgurl', this.fp_bgurl);
			break;

			case 'digitalSetting':
				so.addVariable('uid', this.fp_uid);

				so.addVariable('bgcolor', this.fp_bgcolor);
				so.addVariable('texcolor', this.fp_texcolor);

				so.addVariable('frame', this.fp_frame);
				so.addVariable('day', this.fp_day);
				so.addVariable('usebgimg', this.fp_usebgimg);
				this.fp_bgurl && so.addVariable('bgurl', this.fp_bgurl);
			break;

			case 'counterSetting':
				so.addVariable('uid', this.fp_uid);

				so.addVariable('backcolor', this.fp_backcolor);
				so.addVariable('textcolor', this.fp_textcolor);
				so.addVariable('c', this.fp_count);
			break;

			case 'weatherSetting':
				so.addVariable('uid', this.fp_uid);
				// ↓weatherの場合は http つき…
				//so.addVariable('domain', this.fp_root);
				so.addVariable('domain', this.fp_domain);
				so.addVariable('area_code', this.fp_area_code);
				so.addVariable('bgcolor', this.fp_back_color);
				so.addVariable('texcolor', this.fp_text_color);
				so.addVariable('usebgimg', this.fp_usebgimg);
				this.fp_bgurl && so.addVariable('bgurl', this.fp_bgurl);
			break;

			case 'picomeSetting':
				so.addVariable('uid', this.fp_uid);
				so.addVariable('back_id', this.fp_back_id);
				so.addVariable('bgcolor', this.fp_bgcolor);
				so.addVariable('c', this.fp_c);
				so.addVariable('usebgimg', this.fp_usebgimg);
				this.fp_bgurl && so.addVariable('bgurl', this.fp_bgurl);
			break;

			case 'bbsSetting':
				so.addVariable('uid', this.fp_uid);
				so.addVariable('back_color', this.fp_bgcolor);
				so.addVariable('comments', this.fp_comments);
				so.addVariable('usebgimg', this.fp_usebgimg);
				this.fp_bgurl && so.addVariable('bgurl', this.fp_bgurl);
			break;

			case 'accecySetting':
				so.addVariable('uid', this.fp_uid);
				so.addVariable('bgcolor', this.fp_bgcolor);
				so.addVariable('texcolor', this.fp_texcolor);
				so.addVariable('back_id', this.fp_back_id);
				so.addVariable('language', this.fp_language);
				so.addVariable('today', this.fp_today);
				so.addVariable('yesterday', this.fp_yesterday);
				so.addVariable('unique', this.fp_unique);
				so.addVariable('forecastpv', this.fp_forecastpv);
				so.addVariable('usebgimg', this.fp_usebgimg);
				this.fp_bgurl && so.addVariable('bgurl', this.fp_bgurl);
			break;

			case 'rankringSetting':
				so.addVariable('uid', this.fp_uid);
			break;

		}

		so.useExpressInstall('/lib/external/expressinstall.swf');
		so.write('preview');

	},


	initAnalogSetting: function() {

		this.fp_partsId = fp['partsId'];
		this.fp_swfWidth = fp['swfWidth'];
		this.fp_swfHeight = fp['swfHeight'];
		this.fp_swfBG = fp['swfBG'];

		this.fp_swfWMode = fp['swfWMode'];
		this.fp_swfLoop = fp['swfLoop'];
		this.fp_swfMenu = fp['swfMenu'];
		this.fp_swfAllowScriptAccess = fp['swfAllowScriptAccess'];

		this.fp_uid = fp['uid'];

		this.fp_bgno = fp['bgno'];
		this.fp_bgcolor = fp['bgcolor'];
		this.fp_texcolor = fp['texcolor'];
		this.fp_seccolor = fp['seccolor'];
		this.fp_mincolor = fp['mincolor'];
		this.fp_hourcolor = fp['hourcolor'];
		this.fp_frame = fp['frame'];
		this.fp_day = fp['day'];
		this.fp_bgurl = fp['bgurl'] ? fp['bgurl'] : '';
		this.fp_usebgimg = fp['usebgimg'];

		this.fp_domain = fp['domain'];
		this.fp_root = fp['root'];
		this.fp_path = fp['path'];

		this.swfMovie = this.fp_root + this.fp_path + dispType[this.fp_partsId].swfPath;


		if(this.fp_uid.substr(0,6) != "analog"){
		Event.observe($('clock_id'), 'change', this.changeSetting.bind(this), false);
		Event.observe($('back_id'), 'change', this.changeSetting.bind(this), false);
		Event.observe($('back_color'), 'change', this.changeSetting.bind(this), false);
		Event.observe($('frame'), 'change', this.changeSetting.bind(this), false);
		Event.observe($('text_color'), 'change', this.changeSetting.bind(this), false);
		Event.observe($('day_disp'), 'change', this.changeSetting.bind(this), false);
		}
/*
			alert($('clock_id').options[$('clock_id').selectedIndex].value);
			alert(BlogToy.prototype.domain);
		}, false);
*/


		this.initSettingForm( dispType[this.fp_partsId] );
		this.initParts();
	},

	initDigitalSetting: function() {
		this.fp_partsId = fp['partsId'];
		this.fp_swfWidth = fp['swfWidth'];
		this.fp_swfHeight = fp['swfHeight'];
		this.fp_swfBG = fp['swfBG'];

		this.fp_swfWMode = fp['swfWMode'];
		this.fp_swfLoop = fp['swfLoop'];
		this.fp_swfMenu = fp['swfMenu'];
		this.fp_swfAllowScriptAccess = fp['swfAllowScriptAccess'];

		this.fp_uid = fp['uid'];
/*
		this.fp_char = fp['char'];
*/
		this.fp_bgno = fp['bgno'];
		this.fp_bgcolor = fp['bgcolor'];
		this.fp_texcolor = fp['texcolor'];
		this.fp_frame = fp['frame'];
		this.fp_day = fp['day'];
		this.fp_bgurl = fp['bgurl'] ? fp['bgurl'] : '';
		this.fp_usebgimg = fp['usebgimg'];

		this.fp_domain = fp['domain'];
		this.fp_root = fp['root'];
		this.fp_path = fp['path'];

		this.swfMovie = this.fp_root + this.fp_path + dispType[this.fp_partsId].swfPath;


		if(this.fp_uid.substr(0,7) != "digital"){
			Event.observe($('clock_id'), 'change', this.changeSetting.bind(this), false);
			Event.observe($('back_color'), 'change', this.changeSetting.bind(this), false);
			Event.observe($('frame'), 'change', this.changeSetting.bind(this), false);
			Event.observe($('text_color'), 'change', this.changeSetting.bind(this), false);
			Event.observe($('day_disp'), 'change', this.changeSetting.bind(this), false);
		}
/*
			alert($('clock_id').options[$('clock_id').selectedIndex].value);
			alert(BlogToy.prototype.domain);
		}, false);
*/


		this.initSettingForm( dispType[this.fp_partsId] );
		this.initParts();
	},

	initCounterSetting: function() {
		this.fp_partsId = fp['partsId'];
		this.fp_swfWidth = fp['swfWidth'];
		this.fp_swfHeight = fp['swfHeight'];
		this.fp_swfBG = fp['swfBG'];
		this.fp_swfWMode = fp['swfWMode'];
		this.fp_swfLoop = fp['swfLoop'];
		this.fp_swfMenu = fp['swfMenu'];
		this.fp_swfAllowScriptAccess = fp['swfAllowScriptAccess'];

		this.fp_uid = fp['uid'];
		this.fp_backcolor = fp['backcolor'];
		this.fp_textcolor = fp['textcolor'];
		this.fp_length = fp['length'];
		this.fp_count = fp['count'];

		this.fp_domain = fp['domain'];
		this.fp_root = fp['root'];
		this.fp_path = fp['path'];


		/* そろばんの時は length 9 固定 */
		if (this['fp_partsId'] == 10) {
			this.fp_length = 9;
			this.fp_swfWidth = parseInt(dispType[this['fp_partsId']].flash_widthbase - 0 + (dispType[this['fp_partsId']].flash_widthinc * (this.fp_length - 4)) - 0);
		}

		var elmCount = $('count');
		elmCount.value = this.normalizeNum(elmCount.value);
		this.fp_count = elmCount.value;



		this.swfMovie = this.fp_root + this.fp_path + dispType[this.fp_partsId].swfPath.replace(/_\d+\.swf$/, '_' + this.fp_length + '.swf?' + (new Date()) + '&');




		Event.observe($('counter_id'), 'change', this.changeSetting.bind(this), false);
		Event.observe($('back_color'), 'change', this.changeSetting.bind(this), false);
		Event.observe($('text_color'), 'change', this.changeSetting.bind(this), false);
		Event.observe($('length'), 'change', this.changeSetting.bind(this), false);
		Event.observe($('count'), 'change', this.changeSetting.bind(this), false);
		Event.observe($('submitSetting'), 'click', this.submitSetting.bind(this), false);


		this.initSettingForm( dispType[this.fp_partsId] );
		this.initParts();
	},

	initWeatherSetting: function() {
		this.fp_partsId = fp['partsId'];
		this.fp_swfWidth = fp['swfWidth'];
		this.fp_swfHeight = fp['swfHeight'];
		this.fp_swfBG = fp['swfBG'];

		this.fp_swfWMode = fp['swfWMode'];
		this.fp_swfLoop = fp['swfLoop'];
		this.fp_swfMenu = fp['swfMenu'];
		this.fp_swfAllowScriptAccess = fp['swfAllowScriptAccess'];

		this.fp_uid = fp['uid'];
		this.fp_domain = fp['domain'];
		this.fp_root = fp['root'];
		this.fp_path = fp['path'];

		this.fp_weather_id = fp['weather_id'];
		this.fp_area_code = fp['area_code'];
		this.fp_back_color = fp['back_color'];
		this.fp_text_color = fp['text_color'];

		this.fp_bgurl = fp['bgurl'] ? fp['bgurl'] : '';
		this.fp_usebgimg = fp['usebgimg'];

		this.fp_cid = fp['cid'];

		this.swfMovie = this.fp_root + this.fp_path + dispType[this.fp_partsId].swfPath;



		Event.observe($('area_code'), 'change', this.changeSetting.bind(this), false);
		// Event.observe($('area_code'), 'change', this.changeWeather.bind(this), false);
		Event.observe($('weather_id'), 'change', this.changeSetting.bind(this), false);
		Event.observe($('back_color'), 'change', this.changeSetting.bind(this), false);
		Event.observe($('text_color'), 'change', this.changeSetting.bind(this), false);


		this.initSettingForm( dispType[this.fp_partsId] );
		this.initParts();
	},


	initPicomeSetting: function() {
		this.fp_partsId = fp['partsId'];
		this.fp_swfWidth = fp['swfWidth'];
		this.fp_swfHeight = fp['swfHeight'];
		this.fp_swfBG = fp['swfBG'];

		this.fp_swfWMode = fp['swfWMode'];
		this.fp_swfLoop = fp['swfLoop'];
		this.fp_swfMenu = fp['swfMenu'];
		this.fp_swfAllowScriptAccess = fp['swfAllowScriptAccess'];

		this.fp_uid = fp['uid'];
		this.fp_domain = fp['domain'];
		this.fp_root = fp['root'];
		this.fp_path = fp['path'];

		this.fp_back_id = fp['back_id'];
		this.fp_bgcolor = fp['bgcolor'];
		this.fp_c = fp['c'];
		this.fp_usebgimg = fp['usebgimg'];
		this.fp_cid = fp['cid'];

		this.swfMovie = this.fp_root + this.fp_path + dispType[this.fp_partsId].swfPath;




		Event.observe($('back_id'), 'change', this.changeSetting.bind(this), false);
		Event.observe($('back_color'), 'change', this.changeSetting.bind(this), false);
		Event.observe($('c'), 'change', this.changeSetting.bind(this), false);


		this.initSettingForm( dispType[this.fp_partsId] );
		this.initSettingFormForAccecyAndPicome();
		this.initParts();
	},


	initBbsSetting: function() {

		this.applyLineBreaker();

		this.fp_partsId = fp['partsId'];
		this.fp_swfWidth = fp['swfWidth'];
		this.fp_swfHeight = fp['swfHeight'];
		this.fp_swfBG = fp['swfBG'];

		this.fp_swfWMode = fp['swfWMode'];
		this.fp_swfLoop = fp['swfLoop'];
		this.fp_swfMenu = fp['swfMenu'];
		this.fp_swfAllowScriptAccess = fp['swfAllowScriptAccess'];

		this.fp_uid = fp['uid'];
		this.fp_domain = fp['domain'];
		this.fp_root = fp['root'];
		this.fp_path = fp['path'];

		this.fp_bgcolor = fp['bgcolor'];
		this.fp_comments = fp['comments'];
		this.fp_usebgimg = fp['usebgimg'];
		this.fp_cid = fp['cid'];

		this.swfMovie = this.fp_root + this.fp_path + dispType[this.fp_partsId].swfPath;

//		this.swfMovie += '?' + (new Date);
//alert(this.swfMovie);

		Event.observe($('back_color'), 'change', this.changeSetting.bind(this), false);
		Event.observe($('comments'), 'change', this.changeSetting.bind(this), false);


		this.initSettingForm( dispType[this.fp_partsId] );
		this.initParts();
	},


	initAccecySetting: function() {
		this.fp_partsId = fp['partsId'];
		this.fp_swfWidth = fp['swfWidth'];
		this.fp_swfHeight = fp['swfHeight'];
		this.fp_swfBG = fp['swfBG'];

		this.fp_swfWMode = fp['swfWMode'];
		this.fp_swfLoop = fp['swfLoop'];
		this.fp_swfMenu = fp['swfMenu'];
		this.fp_swfAllowScriptAccess = fp['swfAllowScriptAccess'];

		this.fp_uid = fp['uid'];
		this.fp_domain = fp['domain'];
		this.fp_root = fp['root'];
		this.fp_path = fp['path'];

		this.fp_back_id = fp['back_id'];
		this.fp_bgcolor = fp['bgcolor'];

		this.fp_texcolor = fp['texcolor'];
		this.fp_language = fp['language'];

		this.fp_today = fp['today'];
		this.fp_yesterday = fp['yesterday'];
		this.fp_unique = fp['unique'];
		this.fp_forecastpv = fp['forecastpv'];

		this.fp_usebgimg = fp['usebgimg'];
		this.fp_cid = fp['cid'];

		this.swfMovie = this.fp_root + this.fp_path + dispType[this.fp_partsId].swfPath;




		Event.observe($('back_id'), 'change', this.changeSetting.bind(this), false);
		Event.observe($('back_color'), 'change', this.changeSetting.bind(this), false);
		Event.observe($('text_color'), 'change', this.changeSetting.bind(this), false);
		Event.observe($('language'), 'change', this.changeSetting.bind(this), false);


		this.initSettingForm( dispType[this.fp_partsId] );
		this.initSettingFormForAccecyAndPicome();
		this.initParts();
	},


	initRankringSetting: function() {
		this.fp_partsId = fp['partsId'];
		this.fp_swfWidth = fp['swfWidth'];
		this.fp_swfHeight = fp['swfHeight'];
		this.fp_swfBG = fp['swfBG'];

		this.fp_swfWMode = fp['swfWMode'];
		this.fp_swfLoop = fp['swfLoop'];
		this.fp_swfMenu = fp['swfMenu'];
		this.fp_swfAllowScriptAccess = fp['swfAllowScriptAccess'];

		this.fp_uid = fp['uid'];
		this.fp_domain = fp['domain'];
		this.fp_root = fp['root'];
		this.fp_path = fp['path'];

		this.fp_bgcolor = fp['bgcolor'];
		this.fp_comments = fp['comments'];
		this.fp_usebgimg = fp['usebgimg'];
		this.fp_cid = fp['cid'];

		this.swfMovie = this.fp_root + this.fp_path + dispType[this.fp_partsId].swfPath;


		this.initSettingForm( dispType[this.fp_partsId] );
		this.initSettingForm();
		this.initParts();
	},


	initAnalytics: function(mode) {

		this.applyLineBreaker();

		var cal0;
		var startdate;

		cal0 = new JKL.Calendar("calView","calForm","calDate", false);
//		cal0.min_date = new Date('2007/01/01');

		cal0.max_date = new Date();

		cal0.mode = null;
		if (document.body.id == 'analyticsIndex') {
			cal0.mode = 'month';
		}



		var day = '';
//		if (mode != 'month') {
			location.href.match(/sdate=(\d{4})[\/\-](\d{1,2})[\/\-](\d{1,2})/) 
			//day = new Date(RegExp.$1, (RegExp.$2 - 1 - 0), RegExp.$3);
			day = RegExp.$1 +'/'+ RegExp.$2 +'/'+ RegExp.$3;
//		}

		cal0.write(day);


//__calView_td_2007/04/19
/*
			startdate = "<?=date("Y/m/d",strtotime($start_date))?>";
			Event.observe($('date'), 'click', function () {
				if(startdate != cal_0.getFormValue()){location.href = "?sdate="+cal_0.getFormValue();} 
			} );
			cal0.setFormValue(startdate);
			cal0.write();

		}, false);

*/
	},



	initNewentry_finish: function() {
		if ($('btWelcomeLogin')) {
			$('btWelcomeLogin').onclick = function() {
				$('welcomeLogin').submit();
				return false;
			}
		}


	},

	initReminder: function() {
		document.getElementById('mailad').focus()
		new Validation('fReminder');
	},

	changeSetting: function(ev) {
		var elm;

		if (typeof(ev) == 'string') {
			elm = $(ev);
		} else if ( !(elm = ev.srcElement) ) {
			elm = ev.currentTarget;
		}

		if (elm.nodeName.toUpperCase()  == 'SELECT') {
			this['fp_' + elm.id] = elm.options[elm.selectedIndex].value;
		} else {
			this['fp_' + elm.id] = elm.value;
		}

		switch (elm.id) {
			case fp['type'] + '_id':
				/* 時計のしゅるいがかわったよ */
				// this.fp_partsId = dispType[this.fp_clock_id].clock_idname;
				this.fp_partsId = this['fp_' + fp['type'] + '_id'];

				/* swf たてよこ */
				this.fp_swfWidth = dispType[this['fp_' + fp['type'] + '_id']].flash_width;
				this.fp_swfHeight = dispType[this['fp_' + fp['type'] + '_id']].flash_height;

				/* せっていこうもくon off */
				this.initSettingForm(dispType[this['fp_' + fp['type'] + '_id']]);

			break;

			case 'back_id':
//				this.fp_bgno = this.fp_back_id;
				if (document.body.id == 'digitalSetting') {
					this.fp_bgno = this.fp_back_id;
				}
				if (document.body.id == 'analogSetting') {
					this.fp_bgno = this.fp_back_id;
				}


				// ACCECY と PICOME の事情
				if (document.body.id == 'accecySetting' || document.body.id == 'picomeSetting') {
					/* せっていこうもくon off */
					this.initSettingFormForAccecyAndPicome();
				}
			break;

			case 'back_color':
				if (document.body.id != 'counterSetting') {
					this.fp_bgcolor = this.fp_back_color;
				} else {
					this.fp_backcolor = this.fp_back_color;
				}
			break;

			case 'text_color':
				if (document.body.id != 'counterSetting') {
					this.fp_texcolor = this.fp_text_color;
				} else {
					this.fp_textcolor = this.fp_text_color;
				}
			break;

			case 'day_disp':
				this.fp_day = this.fp_day_disp;
			break;

			case 'sec_color':
				this.fp_seccolor = this.fp_sec_color;
			break;

			case 'min_color':
				this.fp_mincolor = this.fp_min_color;
			break;

			case 'hour_color':
				this.fp_hourcolor = this.fp_hour_color;
			break;

			// カウンターの数字 -> 半角、数字以外 -> 消去
			case 'count':
				elm.value = this.normalizeNum(elm.value);
				this.fp_count = elm.value;
			break;

			// おてんき地域変更
			case 'area_code':
				this.changeWeather();
				return;
			break;
		}


		this.swfMovie = this.fp_root + this.fp_path + dispType[this.fp_partsId].swfPath;

		/* カウンターの場合のwidth と swfPath */
		if (document.body.id == 'counterSetting') {

/*
			alert(dispType[this['fp_' + fp['type'] + '_id']].flash_widthbase);
			alert(dispType[this['fp_' + fp['type'] + '_id']].flash_widthinc);
			alert(this.fp_length - 4);
*/
			// width
//alert(fp['type']);
			/* そろばんの時は length 9 固定 */
			if (this['fp_partsId'] == 10) {
				this.fp_length = 9;
			}

			this.fp_swfWidth = parseInt(dispType[this['fp_partsId']].flash_widthbase - 0 + (dispType[this['fp_partsId']].flash_widthinc * (this.fp_length - 4)) - 0);

//			this.fp_swfWidth = parseInt(dispType[this['fp_' + fp['type'] + '_id']].flash_widthbase - 0 + (dispType[this['fp_' + fp['type'] + '_id']].flash_widthinc * (this.fp_length - 4)) - 0);

			// swfPath
			this.swfMovie = this.swfMovie.replace(/_\d+\.swf$/, '_' + this.fp_length + '.swf?' + (new Date()) + '&');

		}


//alert(this.swfMovie);

		this.initParts();

//		alert(this[elm.id]);

	},

	// 設定画面submitされたとき
	submitSetting: function(ev) {
		// body.idによってふりわけちゃうぞ

		switch(document.body.id) {
			case 'counterSetting':
				var elm = $('count');
				elm.value = elm.value.toHankakuAscii();
				elm.value = elm.value.replace(/[^0-9]/g, '');
			break;

		}


	},

	initSettingForm: function(objClockId) {
		/* せっていこうもくon off */
		for (var obj in objClockId) {
			if ($(obj + '_wrapper')) {
				//alert(dispType[this.fp_clock_id][obj]);

				var temp;
				if (objClockId[obj]) {
					temp = '';
				} else {
					temp = 'none';
				}

				$(obj + '_wrapper').style.display = temp;
			}
		}

	},

	initSettingFormForAccecyAndPicome: function() {
		// ACCECY と PICOME の事情
		if (this.fp_back_id != 0) {
			$('back_color_wrapper').style.display = 'none';
			$('back_image_wrapper').style.display = 'none';

		} else {
			$('back_color_wrapper').style.display = '';
			$('back_image_wrapper').style.display = '';
		}

	},

	normalizeNum: function(n) {
		n = n+''.toHankakuAscii();
		n = n.replace(/[^0-9]/g, '');
		n = n.replace(/^0*/, '');
		if (n == '') {
			n = 0;
		}

		return n;
	},

	initCorner: function(type) {

		switch (type) {
			case 'setting':
				RUZEE.ShadedBorder.create({ corner:6 }).render('globalNavi');
				RUZEE.ShadedBorder.create({ corner:6 }).render('footer');
				RUZEE.ShadedBorder.create({ corner:8, border:5, edges:"tbl" }).render('contentNavi');

			break;
		}
	},


	showCustomizeParts: function(ev) {

		var elm;
		if (typeof(ev) == 'string') {
			elm = $(ev);
		} else if ( !(elm = ev.srcElement) ) {
			elm = ev.currentTarget;
		}


		// tabいろかえ
		var tabs = $('swTabs').getElementsByTagName('a');
		for (var i=0; i<tabs.length; i++) {
			tabs[i].setAttribute('class', '');
			tabs[i].setAttribute('className', '');
		}

		elm.setAttribute('class', 'swTabHi');
		elm.setAttribute('className', 'swTabHi');



		var targetName = elm.id.replace(/^tab/, '');
		var targetContentName = 'dp' + targetName;
		var targetRadioName = 'rd' + targetName;

		var contents = $('swBlock').getElementsByClassName('displayCustomizeParts');

		for (var i=0; i<contents.length; i++) {
			if (targetContentName != contents[i].id) {
				contents[i].style.display = 'none';
			} else {
				contents[i].style.display = 'block';
			}
		}


		// history記録用radio
		$(targetRadioName).click();

		return false;
	},

	changeWeather: function() {
/*
weather_id=1&
area_code=3&
back_color=FFFFFF&
back_image=&
text_color=000000&
CID=e1b72d2b.weather_check&
inp=update
*/
		var temp;
		temp = $('weather_id');
		this.fp_weather_id = temp.options[temp.selectedIndex].value;

		temp = $('area_code');
		this.fp_area_code = temp.options[temp.selectedIndex].value;


		var url = '/weather/setting';
		var pars =
			 'weather_id=' + this.fp_weather_id
			+'&area_code=' + this.fp_area_code
			+'&back_color=' + this.fp_back_color
			+'&text_color=' + this.fp_text_color
			+'&CID=' + this.fp_cid
			+'&inp=update'
			+'&caller=javascript'
		;

		//alert(pars);
		new Ajax.Request(
			url, {
				method: 'post', 
				parameters: pars, 
				onComplete: this.initParts.bindAsEventListener(this, false)
			}
		);

	},

	clip: function(ev) {
		if ($(this.codeId)) {
			$(this.codeId).select();
		}

		clipbrd.copyText($(this.codeId).value);
	},


	applyLineBreaker: function() {
		var s = document.createElement('script');
		s.setAttribute('charset', 'utf-8');
		s.setAttribute('type', 'application/x-javascript');
		s.setAttribute('src', '/lib/external/linebreak.js');
		document.body.appendChild(s);
	},

	focusLogin: function(ev) {
		var elm;
		if ( !(elm = ev.srcElement) ) {
			elm = ev.currentTarget;
		}

		if (elm.value == BlogToy.Const.signpost[elm.id]) {
			elm.value = '';
			BlogToy.prototype.classChanger(elm, 'loginData input');
		}

		if (elm.id == 'pwDummy') {
			elm.style.display = 'none';
			$('pw').style.display = 'inline';
			$('pw').focus();
		}
	},

	unFocusLogin: function(ev) {
		var elm;
		if ( !(elm = ev.srcElement) ) {
			elm = ev.currentTarget;
		}

		if (elm.value == '') {
			elm.value = BlogToy.Const.signpost[elm.id];
			BlogToy.prototype.classChanger(elm, 'loginData null');

			if (elm.id == 'pw') {
				elm.style.display = 'none';
				$('pwDummy').style.display = 'inline';
			}
		}
	},

	classChanger: function(elm, className) {
		elm.setAttribute('class', className);
		elm.setAttribute('className', className);
	}


}
var blogtoy;
Event.observe(window, 'load', function(){
	blogtoy = new BlogToy();
}, false);












function bgChanger(elm, color) {
	if (color == '') {
		return;
	}

	if (color.match(/[^0-9a-f]/i)) {
		return;
	}

	if (! color.match(/^#/)) {
		color = '#' + color;
	}

	elm.style.backgroundColor = color.substr(0, 7);
}


function setPicker(inputElm, sampleElm, arrowElm) {
	Event.observe(arrowElm, 'mouseover', function(){
		arrowElm.src='/lib/external/images/select_arrow_over.gif';
	}, false);

	Event.observe(arrowElm, 'mouseout', function(){
		arrowElm.src='/lib/external/images/select_arrow.gif';
	}, false);

	Event.observe(arrowElm, 'click', function(){
		showColorPicker(arrowElm,inputElm,sampleElm,false,'blogtoy.changeSetting');
	}, false);

	Event.observe(inputElm, 'change', function(){
		bgChanger(sampleElm, inputElm.value);
	}, false);

	bgChanger(sampleElm, inputElm.value);
}


