
(function($) {

	$(function() {
		$.rdojo.rollover();
		$.rdojo.Pagetop();
		$.rdojo.Popup();
		
	});

	//---------------------------------------------------------------------
	$.rdojo = {
		
		//ロールオーバー
		rollover: function() {
				var preLoad = new Object();
				$('img.rollover,input.rollover').not("[src*='_o.']").each(function(){
					var imgSrc = this.src;
					var fType = imgSrc.substring(imgSrc.lastIndexOf('.'));
					var imgName = imgSrc.substr(0, imgSrc.lastIndexOf('.'));
					var imgOver = imgName + '_o' + fType;
					preLoad[imgSrc] = new Image();
					preLoad[imgSrc].src = imgOver;
					$(this).hover(
						function (){ this.src = imgOver; },
						function (){ this.src = imgSrc; }
					);
				});
		},
		
		//ページ内リンク
		Pagetop: function(){ 
			$('a[href^=#]').click(function () {
				$(this).blur();
				var href = $(this).attr("href");
				var topPx = $(href).offset().top;
				$('html,body').animate({ scrollTop: topPx }, 500, "swing");
				return false;
        	});
		},
		
		//popup設定
		Popup: function(){
			$(".popup").click(function() {
			var popup = window.open(this.href, "popWin", "scrollbars=1, resizable=1, width=800, height=700");
			popup.focus();
			return false;
			});
		}
		
	};
	
	// スライドショー
	$.fn.slideshow = function(){
		var $this = this,
			$mains = $this.find(".main li"),
			$thumbs = $this.find(".thumb li"),
			i = 0,
			duration = 1000,
			timerId,
			slideChange;
		
		slideChange = function(i){
			$thumbs.find(".target").stop(true).fadeTo(duration, 0).end()
				.eq(i).find(".target").stop(true).fadeTo(duration, 1);
			$mains
				.filter(function(index){ return index != i; }).fadeOut(duration).end()
				.eq(i).fadeIn(duration, function(){
					i = i === $mains.length - 1 ? 0 : i + 1;
					clearTimeout(timerId);
					timerId = setTimeout(function(){ $thumbs.eq(i).click(); }, duration * 2);
				});
		};
		
		$thumbs.each(function(){
			var $target = $("<div>", { "class": "target" });
			$(this).append($target);
		}).click(function(){
			clearTimeout(timerId);
			slideChange($(this).index());
		}).hover(
			function(){ $(this).addClass("current").find("img").css("opacity", 1); },
			function(){ $thumbs.removeClass("current").find("img").css("opacity", 0.6); }
		);
	
		$thumbs.eq(0).click();
	};

})(jQuery);
