// 画像のロールオーバー

(function() {
  if (!document.getElementsByTagName) return;

  var addEvent, switchImage, init;
  addEvent = function(obj, type, func) {
    if (obj.addEventListener) {
      obj.addEventListener(type, func, false);
    }
    else if (obj.attachEvent) {
      obj.attachEvent('on' + type, func);
    }
  };
  switchImage = function(event) {
    var img = event.target || event.srcElement;
    img.src = (img.src == img.srcOff) ? img.srcOn : img.srcOff;
  };
  init = function() {
    var imgs = document.getElementsByTagName('img');
    var loaded = {}, img;
    for (var i = 0, len = imgs.length; i < len; i++) {
      img = imgs[i];
      if ( !img.src.match(/^(.*_)off(\..*)$/) ) continue;
      img.srcOff = img.src;
      img.srcOn = RegExp.$1 + 'on' + RegExp.$2;
      addEvent(img, 'mouseover', switchImage);
      addEvent(img, 'mouseout', switchImage);
      if (loaded[img.srcOn]) continue;
      loaded[img.srcOn] = true;
      (new Image).src = img.srcOn;
    }
  };

  addEvent(window, 'load', init);
})();

// ポップアップウインドウ
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}

// スライドショー
$(function(){
	var setId = '#slideshow';
	var fadeTime = 1000;
	var delayTime = 5000;

	$(setId + ' div div').each(function(i){
		$(this).attr('id','view' + (i + 1).toString());
		$(setId + ' div div').css({zIndex:'98',opacity:'0'});
		$(setId + ' div div:first').css({zIndex:'99'}).stop().animate({opacity:'1'},fadeTime);
	});

	$(setId + ' ul li').click(function(){
		clearInterval(setTimer);

		var connectCont = $(setId + ' ul li').index(this);
		var showCont = connectCont+1;

		$(setId + ' div div#view' + (showCont)).siblings().stop().animate({opacity:'0'},fadeTime,function(){$(this).css({zIndex:'98'})});
		$(setId + ' div div#view' + (showCont)).stop().animate({opacity:'1'},fadeTime,function(){$(this).css({zIndex:'99'})});

		$(this).addClass('active');
		$(this).siblings().removeClass('active');

		timer();

	});

	$(setId + ' ul li:not(.active)').hover(function(){
		$(this).stop().animate({opacity:'1'},200);
	},function(){
		$(this).stop().animate({opacity:'0.5'},200);
	});

	$(setId + ' ul li').css({opacity:'0.5'});
	$(setId + ' ul li:first').addClass('active');

	timer();

	function timer() {
		setTimer = setInterval(function(){
			$('li.active').each(function(){
				var listLengh = $(setId + ' ul li').length;
				var listIndex = $(setId + ' ul li').index(this);
				var listCount = listIndex+1;

				if(listLengh == listCount){
					$(setId + ' ul li:first').click()
				} else {
					$(this).next('li').click();
				};
			});
		},delayTime);
	};
});
