$(document).ready(function() {
  $('#rotator-nav li ul').hide();
  var inners = $('#rotator > div').cycle().cycle('stop');
  var slideshow = $('#rotator').cycle({
    fx : 'scrollHorz',
    before : cycleInner,
    pager : '#rotator-nav',
    pagerAnchorBuilder : function(idx, slide) {
      return $('#rotator-nav > li:eq(' + idx + ')');
    },
    pause : 1,
    speed : 300,
    timeout : 0
  });

	function cycleInner() {
    inners.cycle('stop');
    $('#rotator-nav > li.activeSlide').animate({
      width: 205
    }).children('ul').animate({
      opacity: 0,
      width: 'toggle'
    })
    $('#rotator-nav li.activeSlide').removeClass('activeSlide');
    var thisID = $(this).attr('id');
    $('#' + thisID + '-nav').animate({
      width: 478
    }).children('ul').animate({
      opacity: 1,
      width: 'toggle'
    });
    $(this).cycle({
      fx : 'fade',
      autostop: true,
      end : function() {
        slideshow.cycle('next');
      },
	    pager : '#' + thisID + '-nav ul',
	    pagerAnchorBuilder : function(idx, slide) {
	      return '#' + thisID + '-nav li:eq('+ idx + ')';
	    },
	    pause : 1,
	    speed : 700,
	    timeout : 5500
    });
  }
});	

