/*
Copyright (c) 2007, KITAMURA Akatsuki

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/

jQuery.changeLetterSize={handlers:[],interval:1000,currentSize:0};(function(e){var c=e.changeLetterSize;var d=e("<ins>M</ins>").css({display:"block",visibility:"hidden",position:"absolute",padding:"0",top:"0"});var b=function(){d.appendTo("body");var f=d[0].offsetHeight;d.remove();if(c.currentSize==f){return false}c.currentSize=f;return true};e(b);var a=function(){if(!b()){return}e.each(c.handlers,function(f,g){g()})};c.addHandler=function(f){c.handlers.push(f);if(c.handlers.length==1){setInterval(a,c.interval)}}})(jQuery);(function(c){var b=[];var a=function(e){var d=0;e.each(function(){var f=this.offsetHeight;if(f>d){d=f}});e.css("height",d+"px")};jQuery.fn.flatHeights=function(){if(this.length>1){a(this);b.push(this)}return this};c.changeLetterSize.addHandler(function(){c.each(b,function(){this.height("auto");a(this)})})})(jQuery);


/*

$(function() {
    $('#unit02 li.block').flatHeights();	
});
$(function() {
$("body.contact")
.find("#maincol ul.alert_list:has(li)").wrap('<div class="alert"></div>').end()
});

$(function() {
$("ul.gateway")
.find("li:nth-child(even)").addClass("even").end()
.find("li:nth-child(odd)").addClass("odd").end();
});

*/

$(function() {
$("#maincol .topics_area dl")
.find("dd:last").addClass("last-child").end()
});

$(function() {
$("#footer .fnav")
.find("li:last").addClass("last-child").end()
});

$(function() {
$(".conclusion")
.find("p:last").addClass("last-child").end()
.find("dl:last").addClass("last-child").end()
});

$(function() {
$("#maincol div#gateway")
.find("div.item:nth-child(even)").addClass("even").end()
.find("div.item:nth-child(odd)").addClass("odd").end();
});

$(function(){
	$("#subcol div.local li").hover(function(){
		$(this).addClass("hover");
	},function(){
		$(this).removeClass("hover");
	})
})

/*  
$(function(){
$("#subcol h3").hover(function(){
	$(this).addClass("hover");
},function(){
	$(this).removeClass("hover");
})
})
*/


/* Get Directory
------------------------------------------*/

function GetDir(){
	var scriptSrc = document.getElementsByTagName('script')[0].getAttribute('src');
	var commonJS = 'js/jquery.js';
	var path = scriptSrc.replace(commonJS, '');
	return path;
}


$(function(){
	ReadCookie();
	FontSizeClick();
	PageTopSet();
	if(document.getElementById("slide_list")){
    slide();
}
});



/* Font-Size Changer
------------------------------------------*/

function setFontsize(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
	  setCookie("style", title, 365);

      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
  fontsizeimg(title);
}

function getFontsize() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreFontsize() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function setCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

function ReadCookie() {
  var cookie = getCookie("style");
  var title = cookie ? cookie : getPreFontsize();
  setFontsize(title);
}

window.onunload = function(e) {
  var title = getFontsize();
  setCookie("style", title, 365);
}

var cookie = getCookie("style");
var title = cookie ? cookie : getPreFontsize();
setFontsize(title);

function fontsizeimg(title){
  var thispath = GetDir();
  var currentstyle = title;
  var area = document.getElementById("fsizechange");
  if (area){
  var imgtag = area.getElementsByTagName("img");
  var m = imgtag[1];
  var l = imgtag[2];
  var fname = "/imgs/b_style_";
  switch(currentstyle)
  {
  case "default":
      l.src=fname+"l.gif";
      m.src=fname+"m_on.gif";
      break;
  case "medium":
      l.src=fname+"l.gif";
      m.src=fname+"m_on.gif";
      break;
  case "large":
      l.src=fname+"l_on.gif";
      m.src=fname+"m.gif";
      break;
  default:
      l.src=fname+"l.gif";
      m.src=fname+"m_on.gif";
      break;
  }
  }

}

function FontSizeClick(){
	$("#fsizechange dd.fontL").click(function(){
    setFontsize("large");
	return false;
	});
	$("#fsizechange dd.fontM").click(function(){
    setFontsize("default");
	return false;
	});
}


/* PAGETOP
------------------------------------------*/

function PageTopSet(){
	PageTop(".page_top a","#wrapper");
	}
function PageTop(target,target2){
$(function () {
    //if (! $.browser.safari) {
		$target = $(target);	
		$target2 = $(target2);	
        $($target).click(function () {
			$(this).blur();
			var targetOffset = $(target2).offset().top;

            $('html,body').animate({ scrollTop: targetOffset }, 'normal');

            return false;
        });
    //}
});
}




//ロールオーバー

$(function(){
    $("img.ovr").mouseover(function(){
        $(this).attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_on$2"))
    }).mouseout(function(){
        $(this).attr("src",$(this).attr("src").replace(/^(.+)_on(\.[a-z]+)$/, "$1$2"));
    }).each(function(){
        $("<img>").attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_on$2"))
    })
})

$(function(){
$("html:has(body.pop)").css("background","none");
});


$.fn.extend({
  inlineBgFix: function() {
    if ($.browser.msie && $.browser.version < 8.0) {
      $(this)
        .addClass('inline-bg-fix')
        .prepend('<span class="bg-l">&nbsp;</span>')
        .append('<span class="bg-r">&nbsp;</span>');
    }
  }
});

$(function() {
  $('a.pdf').inlineBgFix();
});
$(function() {
  $('a.opw').inlineBgFix();
});



$(function() {
	$('a[rel=1]').addClass('item1'); 
});

$(function() {
	$('body.plaza #subcol li:nth-child(4) a').prepend('<img src="/plaza/imgs/m_new.gif" alt="NEW" class="new" />'); 
});