/*google.load("feeds", "1"); 
function initialize2() {
var d = new Date();
var dq = d.getMonth()+""+d.getDate()+""+d.getHours();

var feed = new google.feeds.Feed("http://rss.weather.yahoo.co.jp/rss/days/5020.xml?"+dq);
feed.setResultFormat(google.feeds.Feed.XML_FORMAT); 

feed.load(function(result) {
if (!result.error) {
	alert(result.xmlDocument.html())
}else{
	alert("失敗")
}
})
}
google.setOnLoadCallback(initialize2);
*/
// 画像切り替えスクリプト(IE6対応・クラスでの使用Fix版)

//使用方法
//①t_hover(tc_hoverと同義)・・マウスオーバーで透明度を変えます。カレントページの時も同様に透明度が変わります。
//②i_hover・・マウスオーバーで画像・もしくは背景画像を切り替えます。カレントページの時も同様に変わります。
//　　　　　　 背景画像、もしくは画像に使っている画像のファイル名の末尾に「_on」がついたものを使用します。
//③ic_hover・・上記画像切り替え時に、さらにカレントページの場合の画像は別途指定するときに使用します。
//　　　　　　　カレント用画像として末尾に「_cr」がついたものを使用します。


//透明度効果を使う場合(hover="t")の設定
//マウスオーバーした時の透明度(0～100)
var trans="70";


//画像＆背景画像切り替えを使う場合(hover="i")の設定
//切り替え画像のファイル名につく接尾語
var newhimg="_on";
//明示的なカレント画像を使う場合(hover="ic")のファイル名につく接尾語
var newhcrimg="_cr";


var overtCss = {
"filter": "alpha(opacity=trans)",
"-moz-opacity":trans*0.01,
"opacity":trans*0.01
}
var outtCss = {
"filter": "alpha(opacity=100)",
"-moz-opacity":"1",
"opacity":"1"
}
var thisurl=location.href;
  $(document).ready(function(){


	if($('#planform').size()!=0){
		var date = new Date();
		var year = date.getYear();
		var month = date.getMonth()+1;
		var day = date.getDate();
		$('#year_month').val(fillZero(year,4)+"-"+fillZero(month,2));
		$('#day').val(fillZero(day,2));
		$('#date').val(fillZero(year,4)+"-"+fillZero(month,2)+"-"+fillZero(day,2));
		$('#year_month').change(function(){
			$('#date').val($('#year_month').val()+"-"+$('#day').val());
		})
		$('#day').change(function(){
			$('#date').val($('#year_month').val()+"-"+$('#day').val());
		})
	}


	if($('.section30 a').size() != 0){
	$('.section30 a').lightBox();
	}
	
	//月表示スクリプト
	var d;d=new Date();

	if($('#moon').size() !=0){
	var myear;myear=2010;
	var mmonth;mmonth=5;
	var mday;mday=12;var d;
	moonwrite(myear,mmonth)
	$('#mprevmonth').click(function(){
		d=new Date(myear,mmonth-2,1);
		myear=d.getFullYear();
		mmonth=d.getMonth()+1;
		moonwrite(myear,mmonth)
	})
	$('#mnextmonth').click(function(){
		d=new Date(myear,mmonth,1);
		myear=d.getFullYear();
		mmonth=d.getMonth()+1;
		moonwrite(myear,mmonth)
	})
	}
	//日の出表示スクリプト
	var ds;ds=new Date();

	if($('#sun').size() !=0){

//google.setOnLoadCallback(initialize);14130F


	var myear;syear=2010;
	var smonth;smonth=5;
	var sday;sday=12;var d;
	sunwrite(syear,smonth)
	$('.sunviewbn').live("mouseover",function(){
		$(this).css("background-color","#433C29")
	})
	$('.sunviewbn').live("mouseout",function(){
		$(this).css("background-color","#14130F")
	})
	$('.sunviewbn').live("click",function(){
		$(this).css("background-color","#14130F")
		var thiselm;thiselm=$(this);
		$.ajax({ url: 'phpload.php?thisy='+$(this).attr("year")+'&thism='+$(this).attr("month")+'&thisd='+$(this).attr("day"),
				error: function(){  alert("xmlファイルの読み込みに失敗しました"); }, 
				success: function(xml){
					thiselm.html('日の出:<br />'+$(xml).find("sunrise_hm").text()+'<br />日の入:<br />'+$(xml).find("sunset_hm").text())
				} 
		})
									 //alert($(this).attr("month"))
									// initialize($(this).attr("year"),$(this).attr("month"),$(this).attr("day"))
	})
	$('#sprevmonth').click(function(){
		ds=new Date(syear,smonth-2,1);
		syear=ds.getFullYear();
		smonth=ds.getMonth()+1;
		sunwrite(syear,smonth)
	})
	$('#snextmonth').click(function(){
		ds=new Date(syear,smonth,1);
		syear=ds.getFullYear();
		smonth=ds.getMonth()+1;
		sunwrite(syear,smonth)
	})
	}




//ここから、グローバルナビのプルダウン

	$.ajax({
	  url: "global.html",
	  cache: false,
	  dataType: "html",
	  success: function(html){
		  
		  var globalboxs;globalboxs=new Array();
		  var topcss={"margin-left":"10px","margin-top":"-5px"};
		  for(i=1;i<=$(html).find(".globals").size();i++){
			  if($(html).find(".global"+i+":parent").size() != 0){
				globalboxs[i]=$(html).find(".global"+i).css(topcss).hide();
				$(".g"+i).append(globalboxs[i]).mouseover(function(){$(this).find(".globals").show()}).mouseout(function(){$(this).find(".globals").hide()});
				$(".g"+i+":last").find(".globals").css({"margin-top":-50-$(".g"+i+":last").find(".globals").height()+"px"});
			  }
		  }
		}
	});





							 //$("#newslist").liScroll();
	$(".t_hover,.tc_hover,.i_hover,.ic_hover").each(function(){var newhimg="_on";var newhcrimg="_cr";

							   //リンク先の検索
							   var box=$(this);
							   var a_this="";
							   //var aplace=""
							   //外側にaがある場合
							   if($(this).parents('a').attr("href")){
								   a_this=$(this).parents('a').attr("href");
								   //aplace = $(this).parents('a');
							   //内側にaがある場合
							   }else if($(this).find("a").attr("href")){
								   a_this=$(this).find("a").attr("href");
								   //aplace = $(this).find("a");
							   }
							   if(a_this){
								   //このボタンのリンク先
								   var a_this=path2url(a_this);
								   //現在のページと同じ場合はカレントフラグ
								   if(a_this!=thisurl){a_this="";}
							   }
							   
							   //hover=tの挙動(透明度)
							   if($(this).hasClass("t_hover") || $(this).hasClass("tc_hover")){
								 //hover=tcでもtでもカレント表示
								 if(a_this!=""){
									 $(this).css(overtCss)
									 //a要素を削除
									 //aplace.replaceWith(aplace.html());
								 }else{
									 $(this).mouseover(function(){
																$(this).css(overtCss)
																})
									 $(this).mouseout(function(){
																$(this).css(outtCss)
																})
								 }
								 
								//hover=iの挙動(画像オーバー＆背景オーバー)
							   }else if($(this).hasClass("i_hover") || $(this).hasClass("ic_hover")){
								   //画像タイプか背景タイプか判断
								   if($(this).get(0).tagName.match(/^img$/i)){
									   //画像タイプの場合
									   //元画像を保存
									   var previmg=$(this).attr('src');
								   }else{
									   //背景タイプの場合
									   //元画像を保存
									   var previmg=$(this).css('background-image').replace(/url\(['"]?(.+?)['"]?\)/, "$1")
								   }
								 var newimg=previmg.replace(/(.+?)(\.jpg|\.gif|\.png)/, "$1"+newhimg+"$2")
								 var newcrimg=previmg.replace(/(.+?)(\.jpg|\.gif|\.png)/, "$1"+newhcrimg+"$2")
								 //画像をスワップ
								 var thisoverswap=new Image();
								 var thisoutswap=new Image();
								 if(document.images){
								 thisoverswap.src=newimg;
								 thisoutswap.src=previmg;
								 }
								 
								 
								 //画像タイプの場合の画像変更
								 if($(this).get(0).tagName.match(/^img$/i)){
									   //画像タイプの場合
									   //自動カレント表示
									   if(a_this!="" && $(this).hasClass("i_hover")){
										   $(this).attr('src', newimg);
										   //明示的なカレント表示の場合
									   }else if(a_this!="" && $(this).hasClass("ic_hover")){
										   $(this).attr('src', newcrimg);
									   }else{
										   $(this).mouseover(function(){
																  $(this).attr('src', newimg);
																  })
										   $(this).mouseout(function(){
																 $(this).attr('src', previmg);
																 })
									   }
									   
								//背景タイプの画像変更
								 }else{
									 if(a_this!="" && $(this).hasClass("i_hover")){
										 $(this).css('background-image', 'url("'+newimg+'")');
										 //明示的なカレント表示の場合
									 }else if(a_this!="" && $(this).hasClass("ic_hover")){
										 $(this).css('background-image', 'url("'+newcrimg+'")');
									 }else{
										 $(this).mouseover(function(){
																$(this).css('background-image', 'url("'+newimg+'")');
																})
										 $(this).mouseout(function(){
															   $(this).css('background-image', 'url("'+previmg+'")');
															   })
									 }
								 }
							   }
							   })



})

//相対＆絶対パスをURLに変換するfunction 拝借:http://blog.3ot.net/design/javascript/20090605000251.html
function path2url(path){
  if(path.match(/^\/.+$/)){
    path = location.protocol + '//' + location.hostname + path;
  }
  p = 0, arr = [];
  r = window.location.href;
  path = (path + '').replace('\\', '/');
  if(path.indexOf('://') !== -1){
    p = 1;
  }
  if(!p){
    path = r.substring(0, r.lastIndexOf('/') + 1) + path;
  }
  arr = path.split('/');
  path = [];
  for(k in arr){
    if (arr[k] == '.') {
      continue;
    }
    if (arr[k] == '..') {
      if (path.length > 3) {
        path.pop();
      }
      }else{
        if((path.length < 2) || (arr[k] !== '')){
        path.push(arr[k]);
      }
    }
  }
  return path.join('/').replace(/^file:\/\//, 'file:///');
}

function moonwrite(thisyear,thismonth){
	var d_1;d_1=new Date(thisyear,thismonth-1,1);
	var mmax;mmax=32 - new Date(thisyear,thismonth-1,32).getDate();
		$("#months").html("");
	for(i=1;i<=d_1.getDay();i++){
		$("#months").append('<div class="moonday"></div>');
	}
	for(i=1;i<=mmax;i++){//((thisyear-2000+2)*11+(i+thismonth)-1)%30
		var thisd;thisd=new Date(thisyear,thismonth-1,i,12,0,0);
		var moonage;moonage=Math.round(((thisd.getTime()/1E3-929332980)%2551442)/86400+0.4);
		if(moonage==30){moonage=0;}
		$("#months").append('<div class="moonday"><div class="moondaytext">'+i+'日</div><div class="moonimg"><img src="01module/images/m'+(moonage)+'.jpg" width="58" height="63" alt="" /></div><div class="moonage">月齢:'+moonage+'</div></div>');
		//$("#months").append("日付 = "+thisyear+"年"+thismonth+"月"+ i+"日"+"月齢は"+Math.round(((thisd.getTime()/1E3-929332980)%2551442)/86400+0.4)+"<br>");
	}
	$('#mthismonth').html(thisyear+"年"+thismonth+"月")
}
function sunwrite(thisyear,thismonth){
	var d_1;d_1=new Date(thisyear,thismonth-1,1);
	var mmax;mmax=32 - new Date(thisyear,thismonth-1,32).getDate();
		$("#months").html("");
	for(i=1;i<=d_1.getDay();i++){
		$("#months").append('<div class="moonday"></div>');
	}
	for(i=1;i<=mmax;i++){//((thisyear-2000+2)*11+(i+thismonth)-1)%30
		var thisd;thisd=new Date(thisyear,thismonth-1,i,12,0,0);
		$("#months").append('<div class="moonday"><div class="moondaytext">'+i+'日</div><div class="sunviewbn" month="'+thismonth+'" year="'+thisyear+'" day="'+i+'"><br />日の出時刻を表示<br /></div></div>');
		//$("#months").append("日付 = "+thisyear+"年"+thismonth+"月"+ i+"日"+"月齢は"+Math.round(((thisd.getTime()/1E3-929332980)%2551442)/86400+0.4)+"<br>");
	}
	$('#mthismonth').html(thisyear+"年"+thismonth+"月")
}

function fillZero( number, size ) {
  var s = Math.log( number ) * Math.LOG10E;
  for( i=1,n=size-s,str="";i<n;i++ ) str += "0";
  return str+number;
}
