// ----------------------------------------------------------------------------
// Font Size Botton
// ----------------------------------------------------------------------------
jQuery(function($){
	function dispFontSizeBtn(){
		var aBODY = new Array();
		var sTmp = '';
		sTmp += '<span class="text"><img src="/common/images/en/textsize_tit.gif" width="48" height="9" alt="Font Size" /></span>';
		sTmp += '<ul class="textresizer">';
		sTmp += '<li class="largeText"><a href="javascript:void(0);" tabindex="100">L</a></li>';
		sTmp += '<li class="mediumText"><a href="javascript:void(0);" tabindex="100">M</a></li>';
		sTmp += '<li class="smallText"><a href="javascript:void(0);" tabindex="100">S</a></li>';
		sTmp += '</ul>';
		//sTmp += '<span class="help"><a href="/size/index.html" tabindex="100"><img src="/common/images/textsize_help.gif" width="21" height="21" alt="Changing text size" /></a></span>';
		//aBODY.push(sTmp);
		//var sBODY = aBODY.join("\n");
		var d_el = document.getElementById("textresizerEmbed");

		if( d_el != null ) {
			var sBODY = '';
			if( d_el.className == 'newWin' ){
				sTmp += '<span class="help"><a href="/size/index.html" tabindex="100" title="Opens a new browser window" rel="newWindow"><img src="/common/images/textsize_help.gif" width="21" height="21" alt="Changing text size" /></a></span>';
				aBODY.push(sTmp);
			}else{
				sTmp += '<span class="help"><a href="/size/index.html" tabindex="100"><img src="/common/images/textsize_help.gif" width="21" height="21" alt="Changing text size" /></a></span>';
				aBODY.push(sTmp);
			}
			sBODY = aBODY.join("\n");
			d_el.innerHTML = sBODY;
		}
	};
	dispFontSizeBtn();
});

// ----------------------------------------------------------------------------
// Font Size Switcher
// ----------------------------------------------------------------------------
jQuery(document).ready( function($) {
	jQuery( "ul.textresizer a" ).textresizer({
		target: "body",
		type: "cssClass",
		sizes: [
			"largeText",
			"mediumText",
			"smallText",
		],
		selectedIndex: 2
	});
});


// ----------------------------------------------------------------------------
// IMG Hover
// ----------------------------------------------------------------------------
jQuery(document).ready(function($) {
	var postfix = '-on';
	var postactive = '-active';
	$('img.rollover').not('[src*="'+ postfix +'."]').not('[src*="'+ postactive +'."]').each(function() {
		var img = $(this);
		var src = img.attr('src');
		var src_on = src.substr(0, src.lastIndexOf('.'))
		 + postfix
		 + src.substring(src.lastIndexOf('.'));
		$('<img>').attr('src', src_on);
		img.hover(
			function() {
				img.attr('src', src_on);
			},
			function() {
				img.attr('src', src);
			}
		).click(function() {
				img.attr('src', src);
		});;
	});
	$('input.rollover').not('[src*="'+ postfix +'."]').not('[src*="'+ postactive +'."]').each(function() {
		var inpt = $(this);
		var src = inpt.attr('src');
		var src_on = src.substr(0, src.lastIndexOf('.'))
		 + postfix
		 + src.substring(src.lastIndexOf('.'));
		$('<input>').attr('src', src_on);
		inpt.hover(
			function() {
				inpt.attr('src', src_on);
			},
			function() {
				inpt.attr('src', src);
			}
		).click(function() {
				inpt.attr('src', src);
		});;
	});
});


// ----------------------------------------------------------------------------
// Search Form
// ----------------------------------------------------------------------------
jQuery(document).ready(function($){
	$('#search')
	.blur(function(){
		var $$=$(this);
		if($$.val()=='' || $$.val()==$$.attr('title')){
		$$.css('color', '#676767')
			.val($$.attr('title'));
		}
	})
	.focus(function(){
		var $$=$(this);
		if($$.val()==$$.attr('title')){
		$(this).css('color', '#000')
				.val('');
		}
	})
	.parents('form:first').submit(function(){
		var $$=$('#search');
		if($$.val()==$$.attr('title')){
		$$.triggerHandler('focus');
		}
	}).end()
	.blur();
	});


// ----------------------------------------------------------------------------
// tab Setting
// ----------------------------------------------------------------------------
jQuery(document).ready(function($){
	var Tabs = $("ul#tab li a");
	var TabActive = "active";
	var TabContents = $("div#tabContents");
	$("div.hide" , TabContents).hide();

	$(Tabs).click(function(e){
		e.preventDefault();
		$("div.hide" , TabContents).hide();
		$($(this).attr("href")).fadeIn(250);
		$(Tabs).removeClass(TabActive);
		$(this).addClass(TabActive);
		$.cookie("contents", $(this).attr("href") , {expires: 365});
	});

	// クッキー読み込み
	var CookieName = $.cookie("contents");
	if (CookieName != null) {
		$(Tabs).removeClass(TabActive);
		$("a[href="+CookieName+"]").addClass(TabActive);
		$(CookieName).fadeIn(300);
	} else {
		$("#tab li a:first").addClass(TabActive);
		$("div:first" , TabContents).fadeIn(300);
	}
});


// ----------------------------------------------------------------------------
// Window Popup New Open
// ----------------------------------------------------------------------------
jQuery.fn.popupwindow = function(p)
{
	var profiles = p || {};
	return this.each(function(index){
		var settings, parameters, mysettings, b, a;
		// for overrideing the default settings
		if( jQuery(this).get(0).tagName.match(/area/i) ) {
			mysettings = (jQuery(this).attr("class") || "").split(",");
		}else{
			mysettings = (jQuery(this).attr("rel") || "").split(",");
		}

		settings = {
			height:600, // sets the height in pixels of the window.
			width:600, // sets the width in pixels of the window.
			toolbar:0, // determines whether a toolbar (includes the forward and back buttons) is displayed {1 (YES) or 0 (NO)}.
			scrollbars:0, // determines whether scrollbars appear on the window {1 (YES) or 0 (NO)}.
			status:0, // whether a status line appears at the bottom of the window {1 (YES) or 0 (NO)}.
			resizable:1, // whether the window can be resized {1 (YES) or 0 (NO)}. Can also be overloaded using resizable.
			left:0, // left position when the window appears.
			top:0, // top position when the window appears.
			center:0, // should we center the window? {1 (YES) or 0 (NO)}. overrides top and left
			createnew:1, // should we create a new window for each occurance {1 (YES) or 0 (NO)}.
			location:0, // determines whether the address bar is displayed {1 (YES) or 0 (NO)}.
			menubar:0 // determines whether the menu bar is displayed {1 (YES) or 0 (NO)}.
		};
		// if mysettings length is 1 and not a value pair then assume it is a profile declaration
		// and see if the profile settings exists
		if(mysettings.length == 1 && mysettings[0].split(":").length == 1)
		{
			a = mysettings[0];
			// see if a profile has been defined
			if(typeof profiles[a] != "undefined")
			{
				settings = jQuery.extend(settings, profiles[a]);
			}
		}
		else
		{
			// overrides the settings with parameter passed in using the rel tag.
			for(var i=0; i < mysettings.length; i++)
			{
				b = mysettings[i].split(":");
				if(typeof settings[b[0]] != "undefined" && b.length == 2)
				{
					settings[b[0]] = b[1];
				}
			}
		}
		// center the window
		if (settings.center == 1)
		{
			settings.top = (screen.height-(settings.height + 110))/2;
			settings.left = (screen.width-settings.width)/2;
		}
		
		parameters = "location=" + settings.location + ",menubar=" + settings.menubar + ",height=" + settings.height + ",width=" + settings.width + ",toolbar=" + settings.toolbar + ",scrollbars=" + settings.scrollbars  + ",status=" + settings.status + ",resizable=" + settings.resizable + ",left=" + settings.left  + ",screenX=" + settings.left + ",top=" + settings.top  + ",screenY=" + settings.top;
		
		jQuery(this).bind("click", function(){
			if( a != "newWindow" ){
				var name = settings.createnew ? "PopUpWindow" + index : "PopUpWindow";
				window.open(this.href, name, parameters).focus();
			}else{
				window.open(this.href).focus();
			}
			return false;
		});
	});
};


// ----------------------------------------------------------------------------
// Popup Setting jQuery
// ----------------------------------------------------------------------------
var profiles =
{
	newWindow:
	{
		status:1,
		toolbar:1
	},

	rspeaker:
	{
		height:250,
		width:230,
		status:1,
		toolbar:1
	},

	window800:
	{
		height:800,
		width:800,
		status:1
	},

	window200:
	{
		height:200,
		width:200,
		status:1,
		resizable:0
	},

	windowCenter:
	{
		height:300,
		width:400,
		center:1
	},
	
	windowNotNew:
	{
		height:300,
		width:400,
		center:1,
		createnew:0
	}
};
jQuery(function($){
	$("a[rel],area[class*=newWindow]").popupwindow(profiles);
});

// ----------------------------------------------------------------------------
// Link Icon Auto Addition for IE
// ----------------------------------------------------------------------------
jQuery(function($){
	if ($.browser.msie && $.browser.version < 8.0) {
		$('a.external').each(function(){
			$(this).prepend('<span class="icon">&nbsp;</span>');
		});
		$('a.arrow').each(function(){
			$(this).prepend('<span class="icon">&nbsp;</span>');
		});
	}
});


// ----------------------------------------------------------------------------
// External Link Icon Auto Addition
// ----------------------------------------------------------------------------
jQuery(function($){
	var $target = $("body");
	var $p = $(".external", $target);
	$p.removeClass("external");
	$p.addClass("externalJS");
});


// ----------------------------------------------------------------------------
// Firefox Onkeypress
// ----------------------------------------------------------------------------
function keyPressFilter(evt,URL) {
	var keyCode;
	if (evt) {
		keyCode = evt.keyCode;
	} else {
		keyCode = event.keyCode;
	}
	if (keyCode != 10 && keyCode != 13) {
		return true;
	}
}


// ----------------------------------------------------------------------------
// SocialBookmark
// ----------------------------------------------------------------------------
jQuery(function($){
	function dispSbm(){
		var sCONT = new Array();
		var sSbp = '';
		var url;
		var hatenaSbm;
		var livedoorSbm;
		var buzzurlSbm;
		var newsingSbm;
		var deliciousSbm;
		var yahooBm;
		var pageTitle;
		this.url = encodeURIComponent(location.href); // URL取得&エンコード
		this.pageTitle = encodeURIComponent(document.title); // ページタイトル取得＆エンコード
		this.hatenaSbm = 'http://b.hatena.ne.jp/append?' + this.url; // はてなブックマーク
		this.livedoorSbm = 'http://clip.livedoor.com/clip/add?link=' + this.url + '&title=' + this.pageTitle; // livedoorクリップ
		this.buzzurlSbm = 'http://buzzurl.jp/config/add/conform?url=' + this.url; // Buzzurl
		this.newsingSbm = 'http://newsing.jp/add?title=' + this.pageTitle + '&url=' + this.url; // newsing
		this.yahooBm = 'http://bookmarks.yahoo.co.jp/bookmarklet/showpopup?u=' + this.url + '&t=' + this.pageTitle; //Yahoo!オンラインブックマーク
		sSbp += '<p>※新規ウインドウにてサービス提供サイトが開きます。</p>';
		sSbp += '<p>ブックマーク<span>';
		sSbp += '<a href="' + this.hatenaSbm + '" title="新規ウィンドウで開きます:このページをはてなブックマークに追加" onclick="window.open(this.href,\'\',\'\'); return false;" onkeypress="window.open(this.href,\'\',\'\'); return false;" tabindex="200"><img src="/common/images/icon_sbookmark_hatena.gif" alt="はてなブックマーク" width="16" height="16" /></a>';
		sSbp += '<!--end はてな-->';
		sSbp += '<a href="' + this.livedoorSbm + '" title="新規ウィンドウで開きます:このページをlivedoorクリップに登録" onclick="window.open(this.href,\'\',\'\'); return false;" onkeypress="window.open(this.href,\'\',\'\'); return false;" tabindex="200"><img src="/common/images/icon_sbookmark_livedoor.gif" alt="livedoorクリップ" width="16" height="16" /></a>';
		sSbp += '<!--end livedoorクリップ-->';
		sSbp += '<a href="' + this.buzzurlSbm + '" title="新規ウィンドウで開きます:このページをBuzzurlに登録" onclick="window.open(this.href,\'\',\'\'); return false;" onkeypress="window.open(this.href,\'\',\'\'); return false;" tabindex="200"><img src="/common/images/icon_sbookmark_buzzurl.gif" alt="Buzzurl" width="21" height="16" /></a>';
		sSbp += '<!--end Buzzurl-->';
		sSbp += '<a href="' + this.newsingSbm + '" title="新規ウィンドウで開きます:このページをnewsingに登録" onclick="window.open(this.href,\'\',\'\'); return false;" onkeypress="window.open(this.href,\'\',\'\'); return false;" tabindex="200"><img src="/common/images/icon_sbookmark_newsing.gif" alt="newsing it!" height="16" width="16" /></a>';
		sSbp += '<!--end newsing it!-->';
		sSbp += '<!--Yahoo/-->';
		sSbp += '<a href="' + this.yahooBm + '" title="新規ウィンドウで開きます:Yahoo!ブックマークに登録" onclick="window.open(this.href,\'\',\'\'); return false;" onkeypress="window.open(this.href,\'\',\'\'); return false;" tabindex="200"><img src="/common/images/icon_sbookmark_yahoo.gif" alt="Yahoo!ブックマーク" width="16" height="16" /></a>';
		sSbp += '<!--end Yahoo!ブックマーク-->';
		sSbp += '</span></p>';
		var s_el = $('.socialBookmark');
		sCONT.push(sSbp);
		aCONT = sCONT.join("\n");
		$(s_el).html(aCONT);
	};
	dispSbm();
});

// ----------------------------------------------------------------------------
// Tab Focus
// ----------------------------------------------------------------------------
jQuery(function($){
	var navSpeak = "div#navSpeak";
	var navSpeakHash;
	$("a", navSpeak).each(function(){
		$(this).focus(function(){
			$(navSpeak).addClass("navSpeakShow");
		});
		$(this).blur(function(){
			$(navSpeak).removeClass("navSpeakShow");
		});
		$(this).click(function(e){
			e.preventDefault();
			$(navSpeak).removeClass("navSpeakShow");
			navSpeakHash = $(this).attr("href");
			navSpeakHash = navSpeakHash.substr(1, navSpeakHash.length)
			location.hash = navSpeakHash;
		});
	});
});


// ----------------------------------------------------------------------------
// Page Scroll
// ----------------------------------------------------------------------------
var cast = {
  findAllLink: function() {
    var collectLinks = document.getElementsByTagName('a');
    for (var i=0;i<collectLinks.length;i++) {
      var lnk = collectLinks[i];
      if ((lnk.href && lnk.href.indexOf('#') != -1) && ( (lnk.pathname == location.pathname) ||
         ('/'+lnk.pathname == location.pathname) ) && (lnk.search == location.search)) {
        if(lnk.href.indexOf('anchorPageTop') == -1 && lnk.parentNode.parentNode.getAttribute("id") != "tab" && lnk.href.indexOf('anchorContents') == -1 && lnk.href.indexOf('anchorLocalNav') == -1 && lnk.href.indexOf('anchorGlobalNav') == -1 && lnk.href.indexOf('anchorFooter') == -1){
          cast.addEvent(lnk,'click',cast.innerScroll);
		}
      }
    }
  },
  addEvent: function(element, action, work, capture) {
    if (element.addEventListener){
      element.addEventListener(action, work, capture);
      return true;
    } else if (element.attachEvent){
      var rest = element.attachEvent("on"+action, work);
      return rest;
    }
  }, 
  getNowLocate: function() {
    if (document.body && document.body.scrollTop){
      return document.body.scrollTop;
    }
    if (document.documentElement && document.documentElement.scrollTop){
      return document.documentElement.scrollTop;
	 }
    if (window.pageYOffset){
      return window.pageYOffset;
	 }
    return 0;
  },
  actWindow: function(measure,lmPoint,turnPoint,anchorPoint) {
    chkPoint = cast.getNowLocate();
    chkFlag = (chkPoint < lmPoint);
	if(lmPoint>turnPoint){
		if(lmPoint < 200){ slowPoint = 200; }else{ slowPoint = lmPoint*0.7; }
	}else{
		if(turnPoint < 200){ slowPoint = 200; }else{ slowPoint = turnPoint*0.7; }
	}
	if(Math.abs(lmPoint-chkPoint) < slowPoint){
		
		measure = ((lmPoint-chkPoint)/cast.SPEED);
		if(Math.abs(measure) < 1 ){
			if(measure < 0){
				measure = -1;
		   }else if(measure > 0){
				measure = 1;
			}
		}
	}
    window.scrollTo(0,chkPoint + measure);
    nowPoint = cast.getNowLocate();
    chkFlagNow = (nowPoint < lmPoint);
		if ((chkFlag != chkFlagNow) || (chkPoint == nowPoint)) {
      window.scrollTo(0,lmPoint);
      clearInterval(cast.INTERVAL);
		return false;
    }
  },
  innerScroll: function(e) {
    if (window.event) {
      target = window.event.srcElement;
    } else if (e) {
      target = e.target;
    } else return;
    if (target.nodeName.toLowerCase() != 'a') {
      target = target.parentNode;
    }
    if (target.nodeName.toLowerCase() != 'a') return;
    anchorPoint = target.hash.substr(1);
    var collectLinks = document.getElementsByTagName('a');
    var landmarkLink = null;
    for (var i=0;i<collectLinks.length;i++) {
      var lnk = collectLinks[i];
      if (lnk.name && (lnk.name == anchorPoint)) {
        landmarkLink = lnk;
        break;
      }
    }
    if (!landmarkLink) landmarkLink = document.getElementById(anchorPoint);
    if (!landmarkLink) return true;
    var landmark_x = landmarkLink.offsetLeft; 
    var landmark_y = landmarkLink.offsetTop;
    if( navigator.userAgent.indexOf("MSIE") != -1 ){
    	var val = landmarkLink.childNodes.length;
	   for (i =0 ; i< val ; i++){
        if(landmarkLink.childNodes[i].nodeType == 3){
          landmark_y = landmark_y - 5;
        }
      }
    }else{
      if(landmarkLink.text){
        landmark_y = landmark_y -5;
      }
    }
    if(document.all && !window.opera){
      var winH = document.documentElement.offsetHeight;
      var docH = document.body.scrollHeight;
    }else{
      var winH = window.innerHeight;
      var docH = document.height;
    }
    if(winH > (docH-landmark_y))landmark_y -= landmark_y - (docH-winH);
    var thisNode = landmarkLink;
    while (thisNode.offsetParent && (thisNode.offsetParent != document.body)) {
      thisNode = thisNode.offsetParent;
      landmark_x += thisNode.offsetLeft;
      landmark_y += thisNode.offsetTop;
    }
    clearInterval(cast.INTERVAL);
    turnPoint = cast.getNowLocate();
    movesize = parseInt((landmark_y-turnPoint)/cast.SPEED);
	 if(Math.abs(movesize) < cast.SPEED){
	 	if( movesize < 0 ){
		 	movesize = parseInt(0 - cast.SPEED);
		}else if( movesize > 1 ){
		 	movesize = parseInt(cast.SPEED);
		}
	 }else if(Math.abs(movesize) > cast.LIMIT_SPEED){
	 	if( movesize < 0 ){
		 	movesize = parseInt(0 - cast.LIMIT_SPEED);
		}else if( movesize > 1 ){
		 	movesize = parseInt(cast.LIMIT_SPEED);
		}
	} 
    cast.INTERVAL = setInterval('cast.actWindow('+movesize+','+landmark_y+','+turnPoint+',"'+anchorPoint+'")',15);
    if (window.event) {
      window.event.cancelBubble = true;
      window.event.returnValue = false;
    }
    if (e && e.preventDefault && e.stopPropagation) {
      e.preventDefault();
      e.stopPropagation();
    }
  }
}
cast.SPEED =6;
cast.LIMIT_SPEED =1000;
cast.addEvent(window,"load",cast.findAllLink);



