var trophies = []; var a = 0;
function startShow() {
	$(trophies[a]).hide();
	if(a == trophies.length - 1) { a = 0; } else { a++; }
	$(trophies[a]).show();
	setTimeout("startShow()", 10000);
}

function hideNow() {
	$('#alert_up').fadeOut("slow");
	setTimeout("showNow();", 1000);
}
function showNow() {
	$('#alert_up').fadeIn("slow");
	setTimeout("hideNow();", 1000);
}


(function($) {
	$(function() {
		$(document).ready(function() {
			if($("#accordion")) { $("#accordion").accordion({ autoHeight: false, navigation: true, collapsible: true, active: false }); }
			if($("#tabs")) { $("#tabs").tabs(); }
			$('#trophy_box_wrap a').lightBox({ imageLoading: themeurl + '/images/loading.gif', imageBtnClose: themeurl + '/images/close.gif', imageBtnPrev: themeurl + '/images/prev.gif', imageBtnNext: themeurl + '/images/next.gif' });

			//State Selector
			if($('#retailers')) {
				var select  = $('#retailers').find('select').get(0);
				$(select).change(function() {
					var state = $(this).val();
					var statestr = serverurl + '/retailers/?state=' + state;
					window.location = statestr;
				});
			}

			//Home side rotate
			if($('.trophy_box')) {
				$(".trophy_box").each(function() { trophies.push(this); });
				setTimeout("startShow()", 10000);
			}

			if($('#alert')) { setTimeout("hideNow();", 2000); }


			if($('#trophy_right')) {
				var rows = $('.trophy_row').length - 1;
				var position = 0;
				$('#trophy_box_wrap').css("width", (rows + 1) * 617);


				$('#trophy_right').click(function() {
					if(position < rows) {
						position++;
						$('#trophy_box_wrap').animate({"left": "-" + position * 617 + "px"}, 1000);
					}
				});

				$('#trophy_left').click(function() {
					if(position <= rows && position != 0) {
						position--;
						$('#trophy_box_wrap').animate({"left": "-" + position * 617 + "px"}, 1000);
					}
				});
			}

		});
	});
})(jQuery);

