﻿/* Declare a namespace for the site */
var Site = window.Site || {};
/* Create a closure to maintain scope of the '$'
and remain compatible with other frameworks.  */
(function ($) {
	//same as $(document).ready();
	$(function () { });
	$(window).bind("load", function () { });
})(jQuery);

$(function () {
	//MENU DROPDOWN FUNCTIONS
	$('#main-header #primary-links li ul, #main-header #secondary-links li ul').css('visibility', 'visible').hide();
	$('#main-header #primary-links li, #main-header #secondary-links li').has('ul').addClass('haschildren').hover(function () {
		$(this).addClass('over').find('ul').show();
	}, function () {
		$(this).removeClass('over').find('ul').hide();
	});
	$('#main-header #primary-links > li > a').html('');
	//SECONDARY LINK SEPARATORS
	$('#secondary-links > li').before('<li class="separator">|</li>');
	//Hide the bottom cap of the page column, extend column full height
	var hdiff = $(window).height() - $('#pagewrapper').height();
	if (hdiff > 0) {
		if ($(window).height() > $('#pagewrapper').height()) {
			$('.bottomcap').height(hdiff);
		}
	}
	//LIMIT DISPLAY BY DATE/TIME
	//this is not a great way to do this, but it works
	$('.timedisplay').each(function () {
		var displayuntil = $(this).attr('data-displayuntil');
		var displayafter = $(this).attr('data-displayafter');
	});
	//PDF LINK LABELS - updated to load in lightboxes Sept 2011 (see next comment)
	$('#bodywrapper a[href*=".pdf"]').append('&nbsp;<img src="/media/pdf-icon.png" alt="PDF" class="inline-icon" />');
	//LIGHTBOX LINKS and PDF LINK LABELS - these need to be combined because the callbacks don't fire properly if loadJSFile is called twice on the same file
	if ($('a[target=_lightbox],a[href*=".pdf"]').length > 0) {
		loadJSFile('/libraries/jquery.colorbox-min.js', function () {
			$('a[target=_lightbox]').colorbox({ fixed: true, height: "100%", width: "85%", loop: false, opacity: 0.9 });
			$('a[target = _lightbox][href *= ".html"]').colorbox({ fixed: true, height: "100%", width: "592px", loop: false, iframe: false, opacity: 0.9 });
			$('a[href*=".pdf"]').colorbox({ fixed: true, height: "100%", width: "60%", loop: false, iframe: true, opacity: 0.9 });
		});
	}
	//hide and show .hideonoverlay objects to avoid interference with lightboxes
	$(document).bind('cbox_open', function () {
		$('.hideonoverlay').hide();
	});
	$(document).bind('cbox_closed', function () {
		$('.hideonoverlay').show();
	});
	//Unavailable Content
	$('.unavailable').each(function () {
		var height = $(this).height();
		var width = $(this).width();
		if (height < 310) {
			height = 310;
		}
		$(this).height(height).width(width).html('');
		if (width >= 500 && height >= 430) {
			$(this).addClass('big');
			if (height > 900) {
				$(this).addClass('tall');
			}
		} else if (height > 600) {
			$(this).addClass('tall');
		}
	});
	//LONG-FORM - Deprecated as of 2011 - still called by VIP account pages as of December 2011
	if ($('.long-form').length > 0) {
		loadCSSFile('/css/long-form.css');
	}
	//FORMS
	if ($('.input-form').length > 0) {
		$('.input-form').css('visibility', 'hidden');
		loadCSSFile('/css/input-form.css');
		loadJSFile('/scripts/input-form.js');
		loadjQueryUI();
	}
	//VIP Pages
	if ($('.vip-page').length > 0) {
		loadCSSFile('/css/vip-page.css');
		loadJSFile('/scripts/vip-page.js');
		loadjQueryUI();
	}
	//Spinning Counters
	if ($('.counterwrap').length > 0) {
		$('.counterwrap .spinner').each(function (index, Element) {
			$(Element).attr('data-stopnumber', $(Element).html())
			$(Element).html('<div class="swf"><object width="100%" height="100%" codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"><param value="/Media/flip-numbers-widget/spinner.swf" name="movie"/><param value="true" name="allowFullScreen"/><param value="transparent" name="wmode"/><param value="sameDomain" name="allowscriptaccess"/><embed width="100%" height="100%" wmode="transparent" allowfullscreen="true" allowscriptaccess="always" type="application/x-shockwave-flash" src="/Media/flip-numbers-widget/spinner.swf"/></object></div>');
			$(Element).delay(2700 - (index * 200)).queue(function () { $(this).html($(this).attr('data-stopnumber')) });
		});
	}
	//CHECK links for whether or not they are active
	//TODO: allow extra urls a link can match in its DATA-URL-EQUIVALENTS attribute
	var path = location.pathname.substring(1).toLowerCase();
	if (path) {
		$('a[href$="' + path + '"]').addClass('active');
	}
	//PLACEHOLDER TEXT
	if (!Modernizr.input.placeholder) {
		$('[placeholder]').focus(function () {
			var input = $(this);
			if (input.val() == input.attr('placeholder')) {
				input.val('');
				input.removeClass('placeholder');
			}
		}).blur(function () {
			var input = $(this);
			if (input.val() == '' || input.val() == input.attr('placeholder')) {
				input.addClass('placeholder');
				input.val(input.attr('placeholder'));
			}
		}).blur();
		$('[placeholder]').parents('form').submit(function () {
			$(this).find('[placeholder]').each(function () {
				var input = $(this);
				if (input.val() == input.attr('placeholder')) {
					input.val('');
				}
			})
		});
	}
	//Countdown Timers
	if ($('.countdowntimer').length > 0) {
		$(this).find('.countdowntimer.running, .countdowntimer .finished').hide();
		serverTime.countdownTimers = $('.countdowntimer');
		serverTime.updateCountdownTimers = function () {
			this.countdownTimers.each(function () {
				var target = new Date($(this).attr('data-target'));
				if (serverTime.isBefore(target)) {
					//countdown still running
					$(this).find('.running').show();
					$(this).find('.finished').hide();
					//fill out .timeremaining blocks
					$(this).find('.timeremaining').each(function () {
						var target = $(this).closest('.countdowntimer').attr('data-target');
						var fuzz = $(this).attr('data-fuzz');
						var maxGranularity = $(this).attr('data-maxgranularity');
						var minGranularity = $(this).attr('data-mingranularity');
						$(this).html(formatTime(serverTime.diff(target), minGranularity, maxGranularity, fuzz));
					});
				} else {
					//countdown complete
					$(this).find('.running').hide();
					$(this).find('.finished').show();
				}
			});
		}
		serverTime.updateCountdownTimers();
		setInterval('serverTime.updateCountdownTimers()', 1000);
	}
	//BETTER LISTBOXES and Fancy Buttons
	if ($('.betterlistbox').length > 0) {
		loadCSSFile('/css/jquery.selectBox.css');
		loadJSFile('/scripts/jquery.selectBox.min.js', function () {
			$('.betterlistbox').selectBox();
		});
	}
	if ($('.fancybutton').length > 0) {
		loadjQueryUI();
		$('.fancybutton').button();
	}
	//YOUTUBE PLAYLISTS
	if ($('.jquery-ytplaylist').length > 0) {
		loadjQueryUI();
		loadJSFile('/libraries/swfobject.js');
		loadJSFile('/scripts/jquery-ytplaylist.js');
		loadCSSFile('/css/jquery-ytplaylist.css');
	}
	//FAQ PAGES
	if ($('.layout-faq').length > 0) {
		if (!is_ie_6) {
			loadjQueryUI();
			loadJSFile('/scripts/layout-faq.js');
			loadCSSFile('/css/layout-faq.css');
		} else {
			$('#faq-search-box').hide();
		}
	}
	//TABBED LAYOUTS
	if ($('.layout-tabbed').length > 0) {
		loadjQueryUI();
	}
	//ENTRY PAGES - Deprecated as of 2011
	if ($('.layout-entry-page').length > 0) {
		loadCSSFile('/css/layout-entry-page.css');
	}
	//HISTORY PAGES
	if ($('.layout-history').length > 0) {
		loadJSFile('/scripts/layout-history.js');
	}
	//Ajax Popovers
	$('a[rel=popover]').click(function (event) {
		event.preventDefault();
		makePopOver(popOverLoadingHTML);
		$.ajax({
			url: $(this).attr('href'),
			success: function (data) { makePopOver(data) },
			error: function () { hidePopOver() }
		});
	});
	$('body').append('<div class="popover-overlay"><div class="popover-wrapper"><div class="popover-content"></div><div class="dismissalbutton"></div></div></div>');
	$('.popover-overlay').click(function () { hidePopOver() }).hide();
	var popOverLoadingHTML = '<div class="loading"></div>';
	function makePopOver(content) {
		$('body').addClass('overlay-active');
		$('.popover-content').html(content);
		$('.popover-overlay').css('top', $('body').scrollTop() + 'px').fadeIn('slow');
	}
	function hidePopOver() {
		$('.popover-overlay').fadeOut('slow');
		$('body').removeClass('overlay-active');
	}
	//WRAP TABLES IN A DIV
	$('table').wrap('<div>');
	//INLINE POPOVERS
	$('a[rel=popover-inline]').click(function (event) {
		event.preventDefault();
		$(this).after($(this).html() + '<div class="popover-inline"><div class="loading"></div></div>').hide().next('.popover-inline').load($(this).attr('href'));
	});
	//SCRATCHER PAGES
	if ($('.layout-scratchers').length > 0) {
		loadCSSFile('/css/layout-scratchers.css');
	}
	if ($('.layout-scratcher-single').length > 0) {
		loadCSSFile('/css/layout-scratcher-single.css');
	}
	//VIP Forms
	jQuery('.vip-form-confirmation').each(function () {
		$(this).attr('class', 'vip-form-confirmation-container');
		$(this).attr('style', '');
		$(this).html('<div class="vip-form-confirmation-jquery rounded"><div class="inner">' + $(this).html() + '</div></div><div class="vip-form-overlay"></div>');
		var leftPos = 0;
		leftPos += $(this).parent().width() / 2;
		leftPos -= $(this).children('.vip-form-confirmation-jquery').width() / 2;
		$(this).children('.vip-form-confirmation-jquery').attr('style', 'left:' + leftPos + 'px;top:45px;position:absolute;z-index:1000;');
		$(this).children('.vip-form-overlay').fadeTo('fast', 0.75);
		$(this).click(function () {
			$(this).children('.vip-form-confirmation-jquery').fadeOut('fast');
			$(this).fadeOut(2000);
		});
	});
	//Random Content picker
	jQuery('.randomcontent').each(function () {
		var contents = $(this).children('.content');
		var length = contents.length;
		if (length > 1) {
			//do nothing if there aren't multiple options
			//omit any that link to the current page
			//takes advantage of links' .active class, which is automatically set above
			contents.find('.active').parents('.randomcontent > .content').remove();
			var contents = $(this).children('.content');
			var length = contents.length;
			var selected = Math.floor(Math.random() * length);
			contents.hide();
			contents.eq(selected).show();
		}
	});
	//Entry Form Tool Tips
	$('ul #TicketNumberTB3').after('<img src="/media/tool-tip.png" alt="What is this?" class="iepngfix tooltip" height="30" width="30" />');
	$('ul.validation-form .tooltip').click(function () {
		$(this).hide();
		$(this).closest('li').find('.info').attr('style', 'visibility:visible;display:block;').show();
	});
	//IE6 Fixes
	if (is_ie_6) {
		//Dropdown windower
		//Keeps dropdowns above form fields by placing an invisible iframe behind them.
		//currently only needed on the past winning numbers page
		//activates if .layout-dropdown-windower
		if ($('.layout-dropdown-windower').length > 0) {
			var html1 =
				"<iframe style=\"position: absolute; display: block; " +
				"z-index:-1; width: 156px; height: 250px; top: 0; left: 0;" +
				"filter: mask(); background-color: #ffffff;border:2px solid #ccc;\"></iframe>";
			$('.windowed').prepend(html1);
			$('#main-header #primary-links li iframe, #main-header #secondary-links li iframe').hide();
			$('#main-header #primary-links li, #main-header #secondary-links li').has('ul').hover(function () {
				$(this).find('iframe').show();
			}, function () {
				$(this).find('iframe').hide();
			});
		}
	}
});

/*
	Timekeeping
*/
serverTime.getDate = function () {
	if (!this.isCurrently) {
		var isCurrently = new Date();
		isCurrently.setTime(this.startDate.getTime() + this.ticks*1000);
		this.isCurrently = isCurrently;
		setTimeout('serverTime.clearCache()', this.cacheLifetime);
		return (new Date(isCurrently));
	} else {
		return (new Date(this.isCurrently));
	}
}
serverTime.clearCache = function () {
	this.isCurrently = null;
}
serverTime.timeString = function (seconds) {
	var isCurrently = serverTime.getDate();
	var output = (isCurrently.getHours() % 12 + 1) + ':' + strPad(isCurrently.getMinutes(), 2, '0');
	if (seconds) {
		output += ':' + strPad(isCurrently.getSeconds(), 2, '0');
	}
	if (isCurrently.getHours >= 11) {
		output += ' pm';
	} else {
		output += ' am';
	}
	return (output);
}
serverTime.dateString = function (year) {
	var isCurrently = serverTime.getDate();
	var output = this.months[isCurrently.getMonth()] + ' ' + isCurrently.getDate();
	if (year) {
		output += ', ' + isCurrently.getFullYear();
	}
	return (output);
}
serverTime.fullString = function (year, seconds) {
	return (this.dateString(year) + ' ' + this.timeString(seconds));
}
serverTime.isBefore = function (input) {
	var isCurrently = serverTime.getDate();
	input = new Date(input);
	if (input > isCurrently) {
		return (true);
	}
	return (false);
}
serverTime.isAfter = function (input) {
	var isCurrently = serverTime.getDate();
	input = new Date(input);
	if (input <= isCurrently) {
		return (true);
	}
	return (false);
}
serverTime.diff = function (input) {
	input = new Date(input);
	var isCurrently = serverTime.getDate();
	var output = 0;
	output = Math.round((input.getTime() - isCurrently.getTime()) / 1000);
	return (output);
}

// a handful of utility functions
function strPad(input, padLength, padString, padDirection) {
	input = input + '';
	padString = padString + '';
	output = input;
	padStrPos = padString.length - 1;
	if (!padDirection) {
		padDirection = 'right';
		padStrPos = 0;
	}
	while (output.length < padLength) {
		if (padDirection == 'right') {
			output = output + padString.substr(padStrPos, 1);
			padStrPos++;
		} else {
			output = padString.substr(padStrPos, 1) + output;
			padStrPos--;
		}
		if (padStrPos < 0) {
			padStrPos = padString.length - 1;
		}
		if (padStrPos > padString.length - 1) {
			padStrPos = 0;
		}
	}
	return (output);
}
function arrIndexOf(needle, haystack) {
	for (current in haystack) {
		if (haystack[current] == needle) {
			return (current);
		}
	}
	return (-1);
}
function formatTime(seconds, minGranularity, maxGranularity, fuzz, returnObject) {
	var granularities = ['seconds', 'minutes', 'hours', 'days', 'weeks', 'months', 'years'];
	minGranularity = arrIndexOf(minGranularity, granularities);
	maxGranularity = arrIndexOf(maxGranularity, granularities);
	if (!fuzz) {
		fuzz = 4;
	}
	if (fuzz < 2) {
		fuzz = 2;
	}
	if (minGranularity == -1) {
		minGranularity = 0;
	}
	if (maxGranularity == -1) {
		maxGranularity = 3;
	}
	if (maxGranularity < minGranularity) {
		maxGranularity = minGranularity;
	}
	var timeObject = new Object();
	timeObject.seconds = 0;
	timeObject.minutes = 0;
	timeObject.hours = 0;
	timeObject.days = 0;
	timeObject.weeks = 0;
	timeObject.months = 0;
	timeObject.years = 0;
	var grains = 0;
	if (minGranularity <= 4 && maxGranularity >= 4 && seconds > 0 && grains < fuzz) {
		timeObject.weeks = Math.floor(seconds / (60 * 60 * 24 * 7));
		if (timeObject.weeks > 0) {
			grains++;
		}
		if (minGranularity == 4 || fuzz == grains) {
			timeObject.weeks++;
		}
		seconds = seconds - (60 * 60 * 24 * 7) * timeObject.weeks;
	}
	if (minGranularity <= 3 && maxGranularity >= 3 && seconds > 0 && grains < fuzz) {
		timeObject.days = Math.floor(seconds / (60 * 60 * 24));
		if (timeObject.days > 0) {
			grains++;
		}
		if (minGranularity == 3 || fuzz == grains) {
			if (timeObject.days < 6) {
				timeObject.days++;
			}
		}
		seconds = seconds - (60 * 60 * 24) * timeObject.days;
	}
	if (minGranularity <= 2 && maxGranularity >= 2 && seconds > 0 && grains < fuzz) {
		timeObject.hours = Math.floor(seconds / (60 * 60));
		if (timeObject.hours > 0) {
			grains++;
		}
		if (minGranularity == 2 || fuzz == grains) {
			if (timeObject.hours < 23) {
				timeObject.hours++;
			}
		}
		seconds = seconds - (60 * 60) * timeObject.hours;
	}
	if (minGranularity <= 1 && maxGranularity >= 1 && seconds > 0 && grains < fuzz) {
		timeObject.minutes = Math.floor(seconds / 60);
		if (timeObject.minutes > 0) {
			grains++;
		}
		if (minGranularity == 1 || fuzz == grains) {
			if (timeObject.minutes < 59) {
				timeObject.minutes++;
			}
		}
		seconds = seconds - 60 * timeObject.minutes;
	}
	if (minGranularity <= 0 && maxGranularity >= 0 && seconds > 0 && grains < fuzz) {
		timeObject.seconds = Math.floor(seconds);
	}
	if (returnObject) {
		return (timeObject);
	} else {
		var timeString = '';
		if (timeObject.years > 0) {
			timeString += timeObject.years + ' year' + pluralS(timeObject.years) + ' ';
		}
		if (timeObject.months > 0) {
			timeString += timeObject.months + ' month' + pluralS(timeObject.months) + ' ';
		}
		if (timeObject.weeks > 0) {
			timeString += timeObject.weeks + ' week' + pluralS(timeObject.weeks) + ' ';
		}
		if (timeObject.days > 0) {
			timeString += timeObject.days + ' day' + pluralS(timeObject.days) + ' ';
		}
		if (timeObject.hours > 0) {
			timeString += timeObject.hours + ' hour' + pluralS(timeObject.hours) + ' ';
		}
		if (timeObject.minutes > 0) {
			timeString += timeObject.minutes + ' minute' + pluralS(timeObject.minutes) + ' ';
		}
		if (timeObject.seconds > 0) {
			timeString += timeObject.seconds + ' second' + pluralS(timeObject.seconds) + ' ';
		}
		return (timeString);
	}
}
function pluralS(input) {
	if (input != 1) {
		return ('s');
	} else {
		return ('');
	}
}

/*
Debugging features
use the URL bar to enable or disable with "javascript:enablejsdebug()" or "javascript:disablejsdebug()"
*/
function enablejsdebug() {
	createCookie('jsdebug', 'enabled');
	alert('debugging enabled');
}
function disablejsdebug() {
	createCookie('jsdebug', 'disabled');
	alert('debugging disabled');
}
function debug(message) {
	if (readCookie('jsdebug') == 'enabled') {
		if ($('#debugwindow').length > 0) {
			$('#debugwindow').append('<div>' + message + '</div>');
		} else {
			//create the debug box
			$('body').append('<div style="position:absolute;top:0;right:0;background:#fff;padding:5px;" id="debugwindow"><strong>debug messages</strong><div class="log"></div></div>');
			debug(message);
		}
	}
}

function loadjQueryUI() {
	if ($('.jqueryui-loaded').length == 0) {
		/*$.ajax({
		url: 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.min.js',
		dataType:'script',
		async:false
		});*/
		loadCSSFile('/css/jquery-ui/jquery-ui-1.8.16.custom.css');
		$('body').addClass('jqueryui-loaded');
	}
}
function loadJSFile(filePath, callBack) {
	$.getScript(filePath, callBack);
}

function loadCSSFile(filePath) {
	$('head').append('<link>');
	var css = $('head').children(':last');
	css.attr({
		rel: "stylesheet",
		type: "text/css",
		href: filePath
	});
}

//Cookie functions
function createCookie(name, value, seconds) {
	if (seconds) {
		var date = new Date();
		date.setTime(date.getTime() + (seconds * 1000));
		var expires = "; expires=" + date.toGMTString();
	}
	else var expires = "";
	document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for (var i = 0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0) == ' ') c = c.substring(1, c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name, "", -1);
}

//Legacy code to support non-youtube carousels
function getElementsByClass(searchClass, node, tag) {
	var classElements = new Array();
	if (node == null)
		node = document;
	if (tag == null)
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)" + searchClass + "(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if (pattern.test(els[i].className)) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}
//Cross Browser Event Listener fix
//Written by Peter Wilkinson of http://dynamic-tools.net
function addEvent(elem, eventType, handler) {
	if (!elem.eventHandlers) elem.eventHandlers = [];
	if (!elem.eventHandlers[eventType]) {
		elem.eventHandlers[eventType] = [];
		if (elem['on' + eventType]) elem.eventHandlers[eventType].push(elem['on' + eventType]);
		elem['on' + eventType] = handleEvent;
	}
	elem.eventHandlers[eventType].push(handler);
}
function removeEvent(elem, eventType, handler) {
	var handlers = elem.eventHandlers[eventType];
	for (var i in handlers) if (handlers[i] == handler) delete handlers[i];
}
function handleEvent(e) {
	var returnValue = true;
	if (!e) e = fixEvent(event);
	var handlers = this.eventHandlers[e.type]
	for (var i in handlers) {
		this.$$handleEvent = handlers[i];
		returnValue = !((returnValue && this.$$handleEvent(e)) === false);
	}
	return returnValue;
}

function fixEvent(event) {
	// add W3C standard event methods
	event.preventDefault = fixEvent.preventDefault;
	event.stopPropagation = fixEvent.stopPropagation;
	return event;
};

fixEvent.preventDefault = function () {
	this.returnValue = false;
};

fixEvent.stopPropagation = function () {
	this.cancelBubble = true;
};
carouselControl = function (obj, tid) {
	//alert('building carousel control');
	this.obj = obj;
	this.obj.className = 'carousel-activated';
	this.cycletime = this.obj.getAttribute('data-cycletime');
	if (this.cycletime == null | this.cycletime == '') {
		this.cycletime = '5000';
	}
	items = this.obj.getElementsByTagName('LI');
	this.items = new Array();
	this.itemscycles = new Array();
	for (i in items) {
		if (items[i].parentNode == this.obj) {
			this.items[this.items.length] = items[i];
			cyclecount = items[i].getAttribute('data-cyclecount');
			if (!cyclecount || cyclecount == '0') {
				cyclecount = -1;
			}
			this.itemscycles[this.itemscycles.length] = cyclecount;
		}
	}
	this.currentitem = -1;
	this.tid = tid;

	this.itemCycle = function () {
		var cycletime = this.cycletime;
		if (this.currentitem !== -1) {
			//iterate after first item
			this.currentitem++;
			if (this.currentitem >= this.items.length) {
				this.currentitem = 0;
			}
		} else {
			//start from the beginning
			this.currentitem = 0;
		}
		if (this.items[this.currentitem].getAttribute('data-cycletime')) {
			cycletime = this.items[this.currentitem].getAttribute('data-cycletime');
		}
		//alert('cycled to '+this.currentitem);
		if (this.itemscycles[this.currentitem] != 0) {
			if (this.itemscycles[this.currentitem] > 0) {
				this.itemscycles[this.currentitem]--;
			}
			this.itemSelect(this.currentitem);
			setTimeout('carouselControls[' + this.tid + '].itemCycle()', cycletime);
		} else {
			this.itemCycle();
		}
	}
	this.itemSelect = function (itemid) {
		for (i in this.items) {
			if (i == itemid) {
				this.currentitem = i;
				//this is the item to display, display it and resize this.obj to match
				this.items[i].style.visibility = 'visible';
				this.items[i].style.zIndex = '1';
				//set the innerHTML to force a restart of any animated content
				//only works outside IE6
				//only needs to be done for items containing an OBJECT tag
				if (this.items[i].getElementsByTagName('OBJECT').length > 0) {
					if (!is_ie6 | 1 == 1) {
						this.items[i].innerHTML = this.items[i].innerHTML;
					}
				}
			} else {
				//this is not the item to display, hide it
				if (this.items[i].style) {
					this.items[i].style.visibility = 'hidden';
					this.items[i].style.zIndex = '0';
				}
			}
		}
	}

	this.itemCycle();
}
var carouselControls = new Array();
function makecarousels() {
	uls = getElementsByClass('carousel', null, 'ul');
	for (i in uls) {
		carouselControls[carouselControls.length] = new carouselControl(uls[i], i);
	}
}
addEvent(window, 'load', makecarousels);
