/*
	基本のJS
	作成日：080211
	更新日：080723
*/

/* ちらつき回避 */
try {
	document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}

/* popup */
function popup(win_url,win_width,win_height) {
	var win_date = "location=yes,menubar=no,status=yes,scrollbars=yes,resizable=yes," + win_width + "," + win_height;
	WinOpen = window.open(win_url,'popup',win_date);
	WinOpen.focus();
}

/* クローズボタン */
function closeWin(){
	window.close();
}

$(function(){
	// 見出しの前にロケータがある場合
	$("div#mainContents div.locator h2:first-child").addClass("siblingA");//margin-top: 10px;
	$("div#mainContents div.locator h3:first-child").addClass("firstChild");//margin-top: 10px;
	$("div#mainContents div.locator h4:first-child").addClass("firstChild");//margin-top: 10px;
	$("div#mainContents div.locator + h2").addClass("siblingA");//margin-top: 10px;
	$("div#mainContents div.locator + h3").addClass("siblingA");//margin-top: 10px;
	$("div#mainContents div.locator + h4").addClass("siblingA");//margin-top: 10px;

	// 見出し要素の後ろにカラムがある場合
	$("div#mainContents h2 + div.locator h3:first-child").addClass("siblingB");//margin-top: 0;

	// 見出しが連続する場合
	$("div#mainContents h2 + h3").addClass("siblingB");//margin-top: 0;
	$("div#mainContents h3 + h4").addClass("siblingB");//margin-top: 0;

	// lastChild
	$("div#platform p:last-child").addClass("lastChild");
	$("div#platform ul:last-child").addClass("lastChild");
	$("div#platform ol:last-child").addClass("lastChild");
	$("div#platform li:last-child").addClass("lastChild");
	$("div#platform dl:last-child").addClass("lastChild");
	$("div#platform dt:last-child").addClass("lastChild");
	$("div#platform dd:last-child").addClass("lastChild");
	$("div.inner > :last-child").addClass("directLastChild");

	$("div#mainContents p.symbol + ul").addClass("symbol");

	//別窓ウインドウ
	$('[@href^="http"]').not('[@href*="'+document.domain+'"]').click(function(){
		window.open(this.href, "_blank");
		return false;
	}).each(function() {
		$(this.parentNode).addClass('external');
	});
	
	//お問い合わせ
	$('a[@href$="/contact/"]').click(function(){ 
		window.open(this.href, "_blank");
		return false;
	}).each(function() {
		$(this.parentNode).addClass('external');
	});

	//PDF
	$('a[@href$=".pdf"]').click(function(){
		window.open(this.href, "_blank");
		return false;	
	}).each(function() {
		$(this.parentNode).addClass('pdf');
	});	

	//Word
	$('a[@href$=".doc"]').each(function() {
		$(this.parentNode).addClass('word');
	});	

	//Excel
	$('a[@href$=".xls"]').each(function() {
		$(this.parentNode).addClass('excel');
	});	

	//PPT
	$('a[@href$=".ppt"]').each(function() {
		$(this.parentNode).addClass('ppt');
	});	
	
	//zip
	$('a[@href$=".zip"]').each(function() {
		$(this.parentNode).addClass('zip');
	});

	//exe
	$('a[@href$=".exe"]').each(function() {
		$(this.parentNode).addClass('exe');
	});
	
	//MailTo
	$('a[@href^="mailto"]').each(function() {
		$(this.parentNode).addClass('mailTo');
	});	

	urlEn = location.href.indexOf("/en/");
	if (urlEn == -1){
		$('[@href^="http"]').filter('[@href!*="'+document.domain+'"]').attr("title","別ウィンドウが開きます");
		$('a[@href$=".pdf"]').attr("title","別ウィンドウが開きます");
	
		//プリントボタン
		$('p.printBtn img').click(function(){
			window.open("/print.html?"+location.href);
		});		
	} else {
		$('[@href^="http"]').filter('[@href!*="'+document.domain+'"]').attr("title","Another window opens.");
		$('a[@href$=".pdf"]').attr("title","Another window opens.");
		
		//プリントボタン
		$('p.printBtn img').click(function(){
			window.open("/en/print.html?"+location.href);
		});	
	}
	
	//奇数、偶数を自動追加
	$('ul').each(function(){
		$(this).find('li:odd').addClass('even');
		$(this).find('li:even').addClass('odd');
	});
	$('table').each(function(){
		$(this).find('tr:odd').addClass('even');
		$(this).find('tr:even').addClass('odd');
	});
	
	//注釈リスト
	$('.notes li:nth-child(3)').addClass('nthChild');

	//簡単カレント表示
	$('div#localNav a[@href]').each(function(){
		if (this.href == location.href) {
			$(this.parentNode).addClass('current');
		}
	});
	
	//Scroll
	//$('a[@href*="#"]').click(function() {
	//	if(this.href != location.href) {
	//		var id = this.href.substring(this.href.indexOf('#'),this.href.length);
	//		$(id).ScrollTo(300, 'easeout');
	//		return false;
	//	}
	//});
});  