$(document).ready(function () {
    $('#ctl00_search_tm_SearchBox1_ctl00_ctl00_searchButton').val('');
	if (document.getElementById('rotating_banner')) {
		startSlideShow('rotating_banner','rotating_text');
	}
	if (document.getElementById('small_rotating_banner')) {
		startSlideShow('small_rotating_banner');
	}
});

function startSlideShow(id, textId) {
	$('#' + id).after('<div id="nav" class="nav">').cycle({
		fx:     'fade',
		speed:  'slow',
		timeout: 8000,
		pager:  "#nav",
		before: onBefore
    });
	function onBefore() {
		if (textId) { 
			var html = $(this);
			$('#' + textId).html("<p>" + decode(html.attr('alt')) + "</p>");
		}
    }
	addPauseButton(id);
}

function decode(data) {
	return data.replace(/&amp;/g,'&').replace(/&lt;/g,'<').replace(/&gt;/g,'>').replace(/&quot;/g, '"');
}

function addPauseButton(id) {
	$("#nav").append("<a href='#' id='pause'>ll</a>");
	$('#pause').click(function() { 
		var html = ($(this).html() == 'll') ? '>' : 'll';
		var event = ($(this).html() == 'll') ? 'pause' : 'resume';
		$('#' + id).cycle(event);
		$(this).html(html);		
		return false;
	});
}
