/*
	--------------------------------
	更新日: 2010-07-27
	--------------------------------
*/



/* --------------------------------
	サイトルート
-------------------------------- */

var siteRoot = getSiteRoot('common/js/base.js');

function getSiteRoot(path) {
	var elms = document.getElementsByTagName('script');
	for (var i = elms.length - 1; i >= 0; i--) {
		var src = elms[i].src;
		if (new RegExp(path + '([\?].*|$)').test(src)) return src.split(path)[0];
	}
	return false;
}



/* --------------------------------
	ロールオーバー
-------------------------------- */

$(function() {
	rollover('.rollover', '_ov', '_ov');
});

function rollover(target, hover, active, focus) {
	$(target).each(function() {
		var isActive = active && new RegExp(active + '(\.gif|\.jpg|\.png)([\?].*|$)').test(this.src);
		if (isActive && !focus) return;
		this.src.match('(\.gif|\.jpg|\.png)([\?].*|$)');
		var ext = RegExp.$1;
		var search = (isActive && focus) ? active + ext : ext;
		var replace = (isActive && focus) ? focus + ext : hover + ext;
		var out = this.src;
		var over = this.src.replace(search, replace);

		// プレロード
		new Image().src = over;

		// イベントの追加
		$(this).bind('mouseout', function() {
			this.src = out;
		}).bind('mouseover', function() {
			this.src = over;
		});
	});
}



/* --------------------------------
	レイヤー表示
-------------------------------- */

$(function() {
	layerShow.init();
});

var layerShow = {
	
	//設定
	conf: {
		containerSelector: '.layer_article', //コンテナ
		balloonSelector: '.layer_section', //コンテンツ
		fadeTime: 300, //フェードの時間
		easing: 'linear' //フェードの種類
	},
	
	item: [],
	
	//初期化
	init: function() {
		var self = this;
		var conf = this.conf;
		
		$(conf.containerSelector).each(function() {
			
			var container = $(this);
			var index = self.item.length;
			
			var obj = {
				containerObj: container,
				balloonObj: container.find(conf.balloonSelector).css('opacity', 0)
			}
			
			self.item.push(obj);
			
			//アクション
			obj.containerObj.toggle(
				function() { self.show(index); },
				function() { self.hide(index); }
			);
			
		});
	},
	
	//表示
	show: function(index) {
		var obj = this.item[index];
		var balloonObj = obj.balloonObj;
		var self = this;
		balloonObj.stop().css({
			display: 'block'
		}).animate({
			opacity: 1
		}, {
			duration: this.conf.fadeTime,
			easing: this.conf.easing,
			complete: function(){
				if (self.isIE) this.style.removeAttribute('filter');
			}
		});
	},
	
	//非表示
	hide: function(index) {
		var obj = this.item[index];
		var balloonObj = obj.balloonObj;
		balloonObj.stop().animate({
			opacity: 0
		}, {
			duration: this.conf.fadeTime,
			easing: this.conf.easing,
			complete: function(){
				balloonObj.css('display','none');
			}
		});
	},
	
	// IE判定フラグ
	isIE: /msie ([0-9]+)/.test(navigator.userAgent.toLowerCase())
	
}



/* --------------------------------
	MM_Behavior
-------------------------------- */

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}







