// 画像切り替えスクリプト(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 hovertCss = {
"filter": "alpha(opacity=trans)",
"-moz-opacity":trans*0.01,
"opacity":trans*0.01
}
var houttCss = {
"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($('.lb').size() != 0){
	$(".lb").lightBox({fixedNavigation:true});
}
if($('#qatitle').size() != 0){//
	$('#qatitle').masonry();
}
	$(".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(hovertCss)
									 //a要素を削除
									 //aplace.replaceWith(aplace.html());
								 }else{
									 $(this).mouseover(function(){
																$(this).css(hovertCss)
																})
									 $(this).mouseout(function(){
																$(this).css(houttCss)
																})
								 }
								 
								//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 transadd="";
								 if(previmg.replace(/(.+?)(-trans)?(\.jpg|\.gif|\.png)/, "$2") == "-trans"){
									 previmg=previmg.replace(/(.+?)(-trans)?(\.jpg|\.gif|\.png)/, "$1$3")
									 transadd="-trans";
									 }
								 var newimg=previmg.replace(/(.+?)(\.jpg|\.gif|\.png)/, "$1"+newhimg+transadd+"$2")
								 var newcrimg=previmg.replace(/(.+?)(\.jpg|\.gif|\.png)/, "$1"+newhcrimg+transadd+"$2")
								 //if(previmg.replace(/(.+?)(-trans)?(\.jpg|\.gif|\.png)/, "$2") == "-trans"){alert(newimg)}
								 //画像をスワップ
								 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+'")');
															   })
									 }
								 }
							   }
							   })


//ここから、グローバルナビのプルダウン
	$.ajax({
	  url: "global.html",
	  cache: false,
	  dataType: "html",
	  success: function(html){
		  var topcss={"margin-left":"10px","margin-top":"-5px"};
		  var g1=$(html).find(".global1").css(topcss).hide();
		  var g2=$(html).find(".global2").css(topcss).hide();
		  var g3=$(html).find(".global3").css(topcss).hide();
		  var g4=$(html).find(".global4").css(topcss).hide();
		  var g5=$(html).find(".global5").css(topcss).hide();
		  var g6=$(html).find(".global6").css(topcss).hide();
		  var g7=$(html).find(".global7").css(topcss).hide();
		  var g8=$(html).find(".global8").css(topcss).hide();
		  var g9=$(html).find(".global9").css(topcss).hide();
		 $(".g1").append(g1).mouseover(function(){$(this).find(".global1").show()}).mouseout(function(){$(this).find(".global1").hide()});
		 $(".g2").append(g2).mouseover(function(){$(this).find(".global2").show()}).mouseout(function(){$(this).find(".global2").hide()});
		 $(".g3").append(g3).mouseover(function(){$(this).find(".global3").show()}).mouseout(function(){$(this).find(".global3").hide()});
		 $(".g4").append(g4).mouseover(function(){$(this).find(".global4").show()}).mouseout(function(){$(this).find(".global4").hide()});
		 $(".g5").append(g5).mouseover(function(){$(this).find(".global5").show()}).mouseout(function(){$(this).find(".global5").hide()});
		 $(".g6").append(g6).mouseover(function(){$(this).find(".global6").show()}).mouseout(function(){$(this).find(".global6").hide()});
		 $(".g7").append(g7).mouseover(function(){$(this).find(".global7").show()}).mouseout(function(){$(this).find(".global7").hide()});
		 $(".g8").append(g8).mouseover(function(){$(this).find(".global8").show()}).mouseout(function(){$(this).find(".global8").hide()});
		 $(".g9").append(g9).mouseover(function(){$(this).find(".global9").show()}).mouseout(function(){$(this).find(".global9").hide()});
		 
		 $(".g1:last").find(".global1").css({"margin-top":-50-$(".g1:last").find(".global1").height()+"px"});
		 $(".g2:last").find(".global2").css({"margin-top":-50-$(".g2:last").find(".global2").height()+"px"});
		 $(".g3:last").find(".global3").css({"margin-top":-50-$(".g3:last").find(".global3").height()+"px"});
		 $(".g4:last").find(".global4").css({"margin-top":-50-$(".g4:last").find(".global4").height()+"px"});
		 $(".g5:last").find(".global5").css({"margin-top":-50-$(".g5:last").find(".global5").height()+"px"});
		 $(".g6:last").find(".global6").css({"margin-top":-50-$(".g6:last").find(".global6").height()+"px"});
		 $(".g7:last").find(".global7").css({"margin-top":-50-$(".g7:last").find(".global7").height()+"px"});
		 $(".g8:last").find(".global8").css({"margin-top":-50-$(".g8:last").find(".global8").height()+"px"});
		 $(".g9:last").find(".global9").css({"margin-top":-50-$(".g9:last").find(".global9").height()+"px"});

}
	});
})

//相対＆絶対パスを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 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;
}
/*
window.onload=function (){
$('.nav').animate({left: "0px"}, 1500,"easeOutElastic" );
}
*/
