﻿/**
 *
 */
// body の onload で実行
function init(){
	// 天気予報の設定
	// クッキーに地域情報が保持されていたら、その地域を表示する。
	var id = getCookie("atw_weather_prefs");
	for (i = 0; i < document.getElementById("pref").options.length; i = i +1){
		if(document.getElementById("pref").options[i].value==id){
			document.getElementById("pref").selectedIndex = i;
			create_source();
		}
	}
/* ############################################
	var id = $.cookie('atw_weather_prefs');
	var domPref = $('#pref');
	for (i = 0; i < domPref.size(); i = i +1){
		if(domPref.options[i].value==id){
			domPref.selectedIndex = i;
			create_source();
		}
	}
############################################ */
	// 占いの設定
	// クッキーに星座情報が保持されていたら、その星座の占いを表示
	var horoID = $.cookie('atw_horoscope');
	if(horoID) {
		$(".horo_bg" + horoID).css({'display':'block'});
		$("#horo_select").val(horoID);
	}
	else {
		$(".horo_bg1").css({'display':'block'});
	}
}


//myAccordion
$(document).ready(function() {
	$("#myAccordion").myAccordion({
		speed: "low", // low, medium, fast
		defautContent: 0 // 最初に開いている場所
	});
});
// myAccordion終わり
/*
// ライトボックス
	$(function() {
	    $('.w_single_photo a').lightBox();
	});
// ここまで
*/
// 文字サイズ用js
$(function(){
$('#txtbig').mouseover(function(ev) {
	 $(this).css('cursor','pointer');
});
$('#txtsmall').mouseover(function(ev) {
	 $(this).css('cursor','pointer');
});
$("#wrapper").css("font-size",$.cookie('fsize'));
});
function font(size){
$("#wrapper").css("font-size",size);
//$.cookie("fsize",size,{expires:30,path:'/'});
}
// ここまで


/**
 * 星座プルダウンを変更した時に実行される。
 * @param selection 選択した項目の値
 */
function setHoroscope(selection) {
	// 選択した星座の占い情報を表示する。
	$('.horo_box').css({'display':'none'});
	$('.horo_bg' + selection).css({'display':'block'});
	$.cookie('atw_horoscope', selection);
}


function create_source () {
	var pref_id = document.getElementById('pref').value;
	setCookie("atw_weather_prefs",pref_id,30);
	var source= '<script language="javascript" charset="euc-jp" type="text/javascript" src="http://weather.livedoor.com/plugin/common/forecast/' + pref_id + '.js"></script>' + "\n";
	if(pref_id) {
		document.getElementById('source').value = source;
		document.getElementById('js_sample').innerHTML = '<img src="http://image.weather.livedoor.com/component/img/plugin/weather_image/' + pref_id + '.gif" width="160" height="152" />';
	}
	else {
		document.getElementById('source').value = '都道府県を選択して下さい。';
		document.getElementById('js_sample').innerHTML = 'ここにお天気図が表示されます。';
	}
}

/**
 * Cookie のセッタ
 * @param key キー
 * @param val 値
 * @param exp 有効期間（日数）
 * @return
 */
function setCookie(key, val, exp) {
	var today = new Date;
	today.setTime(today.getTime() + (exp * 1000 * 60 * 60 * 24));
	expday = today.toGMTString();
	document.cookie = key + "=" + escape(val) + ";expires=" + expday;
}

/**
 * Cookie のゲッタ
 * @param key キー
 * @return key が示す値
 */
function getCookie(key) {
	if(typeof(key) == "undefined") {
		return "";
	}
	key = key + "=";
	val = "";
	myCookie = document.cookie + ";";
	start_length = myCookie.indexOf(key);
	if (start_length != -1){
		end_length = myCookie.indexOf(";", start_length);
		val = unescape(myCookie.substring(start_length + key.length, end_length));
	}
	return val;
}

