$(function(){ $('#mainVisual h1 a').prependTo('#mainVisual ul').wrap('
  • '); $('#mainVisual ul').carousel({ time: 800, // fade speed(msec) interval: 3000, // fade interval(msec) navi_src: '/home_rdz/img/navi/tip_off.gif', navi_w: 10, navi_h: 10, navi_hover: true }); }); $.fn.carousel = function(option) { return this.each(function() { if(1 < $(this).children().length) { var carousel = new $.carousel(this, option); } }, arguments); } $.carousel = function(element, option) { var target = this; this.element = element; this.current = 0; option.time = isNaN(option.time) ? '' : option.time; option.interval = isNaN(option.interval) ? '' : option.interval; this.option = $.extend({ time : 1500, interval : 3500 }, option); var navi = $(document.createElement('ol')).attr('class', 'mainNavi'); $(element).children().each(function() { navi.append('
  • ' + $(this).find('img').attr('alt') + '
  • '); }); $(element).children().hide().eq(0).show(); if(option.navi_hover) { $(navi).children().eq(0).find('img').attr('src', option.navi_src.replace('_off.', '_on.')); } var timer = setInterval(function() {target.change();}, option.interval); this.navi = navi.insertAfter($(element)); navi.children().hover(function() { clearInterval(timer); target.change($(this).index()); }, function() { timer = setInterval(function() {target.change();}, option.interval); }); } $.extend($.carousel.prototype, { change : function(jumpto) { var children = $(this.element).children(); jumpto = isNaN(jumpto) ? (this.current + 1) % children.length : jumpto; if(this.current == jumpto) { return; } children.stop(true, true); children.fadeOut(this.option.time); children.eq(jumpto).fadeIn(this.option.time); if(this.option.navi_hover) { $(this.navi).children().find('img').attr('src', this.option.navi_src); $(this.navi).children().eq(jumpto).find('img').attr('src', this.option.navi_src.replace('_off.', '_on.')); } this.current = jumpto; } });