/*!
 *
 * Copyright 2010
 *
 *
 * Date: Fri May 28 22:33:48 2010 -0900
 */
			
$(function(){
		   
	if(navigator.userAgent.match(/MSIE/))
	{
		$("p#slideshow").css("margin-left","0");
	}
//
// Image Rollover
//
	
	$("img[src*='_on']").addClass("current");
	$("img[src*='_on']").parent().parent().addClass('current');
	
	
		$("img,input").mouseover(function(){
			if ($(this).attr("src")){
				$(this).attr("src",$(this).attr("src").replace("_off.", "_on."));
			}
		});
	
		$("img[class!='current'],input").mouseout(function(){
				if ($(this).attr("src")){
					$(this).attr("src",$(this).attr("src").replace("_on.", "_off."));
				}
		});
		
		$("#global_navigation li a").mouseover(function(){
			if ($(this).children().attr("src")){
				$(this).children().attr("src",$(this).children().attr("src").replace("_off.", "_on."));
			}
		});
		$("#global_navigation li a").mouseout(function(){
			if ($(this).parent().attr("class") != "current"){
				$(this).children().attr("src",$(this).children().attr("src").replace("_on.", "_off."));
			}
		});
		
//
// External Link
//

	$("a[rel=external]").click(function(){
		window.open(this.href,"_blank");
		return false;
	});
//
// Trigger of Smooth
//
	  $.Smoothie();
});
		
		

(function($) {
  // 指定の id or name の要素までスクロール
  // 要素が存在すればスクロール実行後 true
  $.__smoothScroll = function(name, duration, delay) {
    if (!name) return false;
    if (!delay) delay = 0;
    
    var target = $('a[name="'+name+'"], [id="'+name+'"]');
    if (target.length == 0) return false;
    
    // delay ミリ秒後にスクロール実行
    setTimeout(function (obj, t) {return function () { 
      $($.browser.safari ? 'body' : 'html').animate({scrollTop: obj.offset().top}, t, 'swing');
    } }(target, duration), delay);

    return true;
  }
    
  // $('#top').Smoothie();
  // 動的に作成したリンクに適用したりとか
  $.fn.Smoothie = function(settings) {
    settings = jQuery.extend({duration: 1000, delay: 0}, settings);
    var anchorLink = this;
    anchorLink.click(function() {
      var anchor;
      if (this.hash.match(RegExp("^#(.+)$"))) anchor = RegExp.$1;
      var ret = $.__smoothScroll(anchor, settings.duration);
      return ret ? false : true;
    });
  };
  
  // なめらかに
  $.Smoothie = function(settings) {
    settings = jQuery.extend({duration: 1000, delay: 0}, settings);
    
    // 現在の location.hash を取得
    var anchor = location.hash;
    if (anchor) {
    	anchor = anchor.replace(/^#/, "");
    	anchor = $.browser.fx ? anchor : decodeURIComponent(anchor);
    } else {
      anchor = null;
    }
    
    // 現在のURLでアンカーが付いているならそこになめらかスクロール
    $.__smoothScroll(anchor, settings.duration, settings.delay);
    
    // ページ内アンカーリンクをクリックした際にスクロール
    $('a[href^=#]'+'a[rel!=tab]').Smoothie(settings);
    return true;
  };
})(jQuery);
	
// 文字列に「Firefox」が含まれている場合
if(navigator.userAgent.indexOf("Firefox") != -1){ 
	window.onpageshow  = function resetRollover() {
		if(document.getElementsByTagName) {
			var images = $("img[class!=current]");
			for(var i=0; i < images.length; i++) {
				if(images[i].getAttribute("src").match("_on.")) {
					images[i].setAttribute("src", images[i].getAttribute("src").replace("_on.", "_off."));
				}
			}
		}
	}
}


// windowsizeが1300pxを超えたときに実行
function ImageChange() {
	
	if($(window).width() > 1300) {
		$('body').addClass('wide');
		if(navigator.userAgent.match(/MSIE/)) imglarger();
	}
	else {
		$('body').removeClass('wide');
		if(navigator.userAgent.match(/MSIE/)) imgSmaller();
	}
	
	
	function imgSmaller()
	{
		var slideImg=$("p#slideshow").children();
		slideImg.each(function()
		{
			$('#slideshow').cycle('pause');
			$(this).hide();
			$('#loading').show();
			$(this).attr("src",$(this).attr("src").replace("_1300","_960")).load(function()
																						  {
																							  $('#loading').hide();
																							  $(this).show();
																							  $('#slideshow').cycle('resume');
																						  });
			
			$(this).attr("width","960");
		});
	}
	
	function imglarger()
	{
		var slideImg=$("p#slideshow").children();
		slideImg.each(function()
		{
			$('#slideshow').cycle('pause');
			$(this).hide();
			$('#loading').show();
			$(this).attr("src",$(this).attr("src").replace("_960","_1300")).load(function()
																						  {
																							  $('#loading').hide();
																							  $(this).show();
																							  $('#slideshow').cycle('resume');
																						  });
			$(this).attr("width","1300");
		});
	}
}
/*
window.onresize = ImageChange;
window.onload = ImageChange;
*/
if (window.addEventListener) { //for W3C DOM
  window.addEventListener("load", ImageChange, false);
} else if (window.attachEvent) { //for IE
  window.attachEvent("onload", ImageChange);
} else  {
  window.onload = ImageChange;
}

if (window.addEventListener) { //for W3C DOM
  window.addEventListener("resize", ImageChange, false);
} else if (window.attachEvent) { //for IE
  window.attachEvent("onresize", ImageChange);
} else  {
  window.onresize = ImageChange;
}

