/* 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();
}

/* closeWin */
function closeWin(){
	window.close();
}

// measures against flicker
try {
	document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}

$(function(){
	// 見出しの前にロケータがある場合
	$("div#mainContents div.locator h2:first-child").addClass("siblingA");//margin-top: 20px;
	$("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: 20px;
	$("div#mainContents div.locator + h3").addClass("siblingB");//margin-top: 10px;
	$("div#mainContents div.locator + h4").addClass("siblingB");//margin-top: 10px;
	
	// 見出しの前にサブナビがある場合
	$("div#mainContents div.subNav h2:first-child").addClass("siblingA");//margin-top: 20px;
	$("div#mainContents div.subNav + h2").addClass("siblingA");//margin-top: 20px;

	// 見出し要素の後ろにカラムがある場合
	$("div#mainContents h1 + div.locator h2:first-child").addClass("siblingC");//margin-top: 0;
	$("div#mainContents h2 + div.locator h3:first-child").addClass("siblingC");//margin-top: 0;
	
	// 見出しが連続する場合
	$("div#mainContents h1 + h2").addClass("siblingC");//margin-top: 0;
	$("div#mainContents h3 + h4").addClass("siblingC");//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");

	//Scroll 071127
	var pageUrl = location.href.split('#')[0];
	$('a[@href]').each(function() {
  		if (this.href.indexOf(pageUrl + '#') == 0) {
    		var id = this.href.split('#')[1];
    		$(this).click(function() {
      			$('#' + id).ScrollTo(300, 'easeout');
      			return false;
    		});  
  		}
	});
	
	//別窓ウインドウ
	$('#mainContents [@href^="http"]').click(function(){
		window.open(this.href, "_blank");
		return false;
	}).each(function() {
		$(this.parentNode).addClass('external');
	});
	
	$('#localNav [@href^="http"]').click(function(){
		window.open(this.href, "_blank");
		return false;
	}).each(function() {
		$(this.parentNode).addClass('external');
	});

	//Access地圖
	$('#mainContents a[@href$="/company/map.html"]').click(function(){
		window.open(this.href, "_blank");
		return false;
	});

	$('#localNav a[@href$="/company/map.html"]').click(function(){
		window.open(this.href, "_blank");
		return false;
	});

	//キャンペーン
	$('#mainContents a[@href$="campaign.html"]').click(function(){
		window.open(this.href, "_blank");
		return false;
	});

	$('#localNav a[@href$="/company/map.html"]').click(function(){
		window.open(this.href, "_blank");
		return false;
	});
	
	//PDF
	$('a[@href$=".pdf"]').click(function(){
		window.open(this.href, "_blank");
		return false;	
	}).each(function() {
		$(this.parentNode).addClass('pdf');
	});	

	urlEn = location.href.indexOf("/english/");
	if (urlEn == -1){
		$('[@href^="http"]').attr("title","別ウィンドウが開きます");
		$('a[@href$="/company/map.html"]').attr("title","別ウィンドウが開きます");
		$('a[@href$=".pdf"]').attr("title","別ウィンドウが開きます");
		var winIcon = '<img src="/tw/common/images/icon-win.gif" alt="別ウインドウ" class="icon">';
	} else {
		$('[@href^="http"]').attr("title","Another window opens.");
		$('a[@href$=".pdf"]').attr("title","Another window opens.");
		var winIcon = '<img src="/tw/common/images/icon-win.gif" alt="Another window" class="icon">';
	}
	$('div#mainContents a[@href^="http://"]').after(winIcon);
	$('div#mainContents a[@href$="/company/map.html"]').after(winIcon);
	$('div#mainContents a[@href^="javascript:winopen"]').after(winIcon);
	$('a[img] + img.icon').remove();
	
	//奇数、偶数を自動追加
	$('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');
	});
	
	//画像へ直リンクするとthickboxで表示(thickbox.js利用)
	tb_init('a[@href$=".jpg"], a[@href$=".gif"], a[@href$=".png"]');
});
