/* =======================================

	Common Javascript

 -----------------------------------------
	INDEX
 -----------------------------------------

========================================== */

/* Mouse Over
========================================== */
$(function() {
  var image_cache = new Object();
  $(".swap").each(function(i) {
    var imgsrc = this.src;
    var dot = this.src.lastIndexOf('.');
    var imgsrc_on = this.src.substr(0, dot) + '_on' + this.src.substr(dot, 4);
    image_cache[this.src] = new Image();
    image_cache[this.src].src = imgsrc_on;
    $(this).hover(
      function() { this.src = imgsrc_on; },
      function() { this.src = imgsrc; });
  });
});


/* CSSのロールオーバーでIEで砂時計が出るのを回避
========================================== */
try {
document.execCommand('BackgroundImageCache', false, true);
}catch(e){}


/* Smooth Scroll
========================================== */
$(function(){
	$('a[href^=#]:not(a[href$=#])').click(function(){
		var href= this.hash;
		var $target = $(href == '#_top' ? 'body' : href);
		
		// アンカーリンクがあるページでだけ以下を実行
		if($target.size()){
			var top = $target.offset().top;
			$($.browser.safari ? 'body' : 'html').animate({scrollTop:top}, 500, 'swing');
		}
		return false;
	});
});


/* Link
=========================================== */
$(function(){
	
	// Blank Link
	$('#contents a[href^="http"]').not(':has(img)').addClass('linkBlank').append('<img src="/images/common/ico_blank_01.gif" alt="新規ウィンドウ" class="iconBlank" />');
	
	$('#contents p.detailLink a[href^="http"]').closest('p.detailLink').css('background','none');
	
	// Document Download Link
	$('#contents a').each(function(){
		var linkIconHref = $(this).attr('href').lastIndexOf('.');
		var linkIconType = $(this).attr('href').substr(linkIconHref, 4);
		
		// Excel
		if(linkIconType == '.xls'){
			$(this).addClass('linkExcel').append('<img src="/images/common/ico_excel_01.gif" alt="Excel" class="iconExcel" />');
		
		// PowerPoint
		}else if(linkIconType == '.ppt'){
			$(this).addClass('linkPowerpoint').append('<img src="/images/common/ico_ppt_01.gif" alt="Powerpoint" class="iconPowerpoint" />');
				
		// PDF
		}else if(linkIconType == '.pdf'){
			$(this).addClass('linkPDF').append('<img src="/images/common/ico_pdf_01.gif" alt="PDF" class="iconPDF" />');
		
		// Word
		}else if(linkIconType == '.doc'){
			$(this).addClass('linkWord').append('<img src="/images/common/ico_word_01.gif" alt="Word" class="iconWord" />');
		}
	});
	
	// History Back
	$('ul.pageNavi > li.prev > a').click(function(){
		window.history.back();
		return false;
	});
});



/* Index List
=========================================== */
$(function(){
	$('#contents .indexList').each(function(){
		// unitの数を取得
		indexListSize = $(this).find('.unit').size();
		
		// 奇数の場合背景繰り返しなし
		if(indexListSize % 2 == 1) {
			$(this).css('background-repeat','no-repeat');
		}
	});
});


