// JavaScript Document
function init_rotator() {
	if (!$('#rotator').length) {
		return;
	}
	var speed = 2500;
	
	var pause = false;
	
	function rotate(element) {
		if (pause) {
			return;
		}
		var $next_li = $(element).next('li').length ?
						$(element).next('li') :
						$('#rotator li:first');
						
		var $next_a = $('#rotator_controls a.current').parent('li').next('li').length ?
						$('#rotator_controls a.current').parent('li').next('li').find('a') :
						$('#rotator_controls a:first');
						
						
		$('#rotator_controls a.current').removeClass('current');
		$next_a.addClass('current');
	
		
		function doIt () {
			rotate($next_li);
		}
		
	$(element).fadeOut(speed);
	
	$($next_li).fadeIn(speed, function() {
		setTimeout(doIt, speed);
	});
		
		
	}
	$('#rotator_controls a').click(function() {
		$('#rotator_play_pause').html('Play');
		$($(this).attr('href')).show().siblings('li').hide();
		$(this).addClass('current').parent('li').siblings('li')
			.find('a').removeClass('current');
			
			pause = true;
			
			this.blur();
			return false;
	});
			
	$('#rotator_play_pause').click(function(){
		if ($(this).html() === 'Pause') {
			pause = true;
			
			$(this).html('Play');
			$(this).addClass('width');
			
		} else {
			pause = false;
			
		rotate('#rotator li:visible:first');
		$(this).html('Pause');
		$(this).removeClass('width');
		}
		
		this.blur();
		return false;
	});
	
	
	$('#rotator li:first').siblings('li').hide();
	$(window).load(function() {
		rotate($('#rotator li:visible:first'));
	});
	}
	
	$(document).ready(function() {
		init_rotator();
	});// JavaScript Document
