// jQuery
$(function(){
/////////////////////////////////////////////////////////////////////////////////////////////


// Swap Image
$('img.hov').each(function(i){
	var before = $(this).attr('src');
	var after = (before.indexOf('gif') != -1) ? before.replace('.gif', '_hov.gif') : before.replace('.jpg', '_hov.jpg');
	
	var preload = new Image();
	preload.src = after;
	
	$(this).hover(function(){
		$(this).attr('src', after);
	},function(){
		$(this).attr('src', before);
	});
});		   


// Swap Image in the list of CATEGORY INDEX
if($('#categoryIndex').length > 0){
	$('#categoryIndex li').each(function(i){
		var target = $(this).find('dt img:not(.new)');
		var url = $(this).find('dd.more a').attr('href');
		
		var before = target.attr('src');
		var after = (before.indexOf('gif') != -1) ? before.replace('.gif', '_hov.gif') : before.replace('.jpg', '_hov.jpg');
		
		var preload = new Image();
		preload.src = after;
		
		$(this).hover(function(){
			target.attr('src', after);
		},function(){
			target.attr('src', before);
		});
		
		$(this).click(function(){
			location.href = url;
			return false;
		});
	});	
}


// Auto Scroll
$('.btn-pagetop a').click(function(){   
	$.scrollTo($('body'),500);
	return false;
});

//////////////// 2010追加 ////////////////

//  ロールオーバー2
$("img.hov2").hover(function(){
		$(this).queue([]).stop();
		$(this).fadeTo(300,0.5);
	},
function(){
	$(this).fadeTo(300,1.0);
});

//  カテゴリトップ　ランダムイメージ
$.fn.fadeTransition = function(options) {
    var options = $.extend({pauseTime: 4000, transitionTime: 0}, options);

    Trans = function(obj) {
      var timer = null;
      var current = 0;
      var els = $("> *", obj).css("display", "none").css("left", "0").css("top", "0").css("position", "absolute");
      $(obj).css("position", "relative");
      $(els[current]).css("display", "block");

      function transition() {
        var next = (current + 1) % els.length | 0;
        $(els[current]).fadeOut(options.transitionTime);
        $(els[next]).fadeIn(options.transitionTime);
        current = next;
        cue();
      };

      function cue() {
        if ($("> *", obj).length < 2) return false;
        if (timer) clearTimeout(timer);
        timer = setTimeout(transition, options.pauseTime);
      };

      cue();
    };

    return this.each(function() {
      var t = new Trans(this);
    });
  }

//  ポップアップ
$("a.popup").click(function() {
	var href = $(this).attr('href');																																	
	var lWin = window.open(href,'popupWin','width=700,height=580,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes');
	lWin.focus();
	return false;
 });

//  ポップアップ2
$("a.popup2").click(function() {
	var href = $(this).attr('href');																																	
	var lWin = window.open(href,'popupWin','width=760,height=580,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes');
	lWin.focus();
	return false;
 });


//  ポップアップ3(780)
$("a.popup3").click(function() {
	var href = $(this).attr('href');																																	
	var lWin = window.open(href,'popupWin','width=800,height=580,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes');
	lWin.focus();
	return false;
 });

/////////////////////////////////////////////////////////////////////////////////////////////	   
});