var rotatorElement = '#rotator-items';

$(function() {

  $(rotatorElement).cycle({
		fx:     	        'fade',
		speed:  	        750,
		timeout: 		    10000,
    	slideExpr:          '.rotator-item',
    	random:             false,
//		prev:    	    '#prev-button',
		next:    	    '.next-button',
		pager:   	        '#nav-items',
    	fastOnEvent:        100,
    	timeoutFn:          setSlideTimeout,
		before : function(cur, next, options, flag) {
			var index = $("#current-image").text();
			var newIndex = parseInt(index) + 1;
			if (newIndex > $("#rotator-items > div").size())
				newIndex = 1;
	
			$("#current-image").text(newIndex);
			return false;
		}
	});
	
	$("#pause-rotator").click(function(){
		$(rotatorElement).cycle("pause");
		$("#resume-rotator").show();
		$(this).hide();
		return false;
	});
	
	$("#resume-rotator").click(function(){
		$(rotatorElement).cycle("resume");
		$("#pause-rotator").show();
		$(this).hide();
		return false;
	});
  
  function setSlideTimeout(curr,next,opts,fwd) {
    currentClass = $(next).attr('class');
    if (currentClass != null && currentClass != "" && isNumeric(currentClass)) {
      return parseFloat(currentClass);
    } else {
      return opts.timeout;
    }
  }

  function isNumeric(data) {
    return parseFloat(data)==data;
  }

  function pauseRotator() {
    $(rotatorElement).cycle('pause');
    // $('#pause-button').hide();
    // $('#play-button').show();
  }
  
  function resumeRotator() {
    $(rotatorElement).cycle('resume', true);
    // $('#pause-button').show();
    // $('#play-button').hide();
  }
  
  $('#pause-button > img').click(function() { 
		// pauseRotator();
	});
	
	$('#play-button > img').click(function() { 
		// resumeRotator(); 
	});  
		
});
