(function() {
		var $ = jQuery;

		var testing = document.location.href.indexOf('test.asp') > 0;
		
		$('.inNewWindow, a[href$=.pdf]').click(function(e) {
			var n = window.open();
			n.location = this.href;
			n.focus();
			e.preventDefault();
		});
		
		var newsItems = $('#newslist li');
		listItemRotation(newsItems, { currentIndex: Math.round(Math.random() * (newsItems.length - 1)) });
		
		var clientQuotes = $('#client-quotes p');
		listItemRotation(clientQuotes, { currentIndex: Math.round(Math.random() * (clientQuotes.length - 1)), showTime: 11000 });
		
		function listItemRotation(items, options)
		{
			options = $.extend({
				currentIndex: 0,
				fadeSpeed: 1500,
				showTime: 9500
			}, options);
			
			if (options.currentIndex >= items.length) {
				options.currentIndex = 0;
			}
			
			var maxItemHeight = 0;
			
			items.bind('start-fade', function() {
				var t = $(this);
				t.fadeIn(options.fadeSpeed, function() {
					setTimeout(function() {
						t.trigger('finish-fade');
					},
					options.showTime);
				});
			})
			.bind('finish-fade', function() {
				var t = $(this);
				t.fadeOut(options.fadeSpeed, function() {
					options.currentIndex = (options.currentIndex + 1) % items.length;
					items.eq(options.currentIndex).trigger('start-fade').end();
				});
			})
			.each(function() {
				maxItemHeight = Math.max(maxItemHeight, parseInt(this.offsetHeight));
			})
			.css('display', 'none');

			items.parent().css('height', (maxItemHeight + 15) + 'px');
			items.eq(options.currentIndex).trigger('start-fade').end();
		}
})();