	var polls_answered = new Array();
	var inc_loaded = false;
	
	Event.observe(document, 'dom:loaded', function() {
		// navigation
		$$('#nav li a').each(function(x) {
			if ($(x).readAttribute('href') == '#') {
				x.onclick = function() {
					var container = $($(this).innerHTML.replace(/\s+/g, '-'));
					var uci = ($(this).up('li').identify() == 'uci');
					
					if (uci && !inc_loaded) return false;
					
					if ($(this).up('li').hasClassName('selected')) {
						$$('#nav li').invoke('removeClassName', 'selected');
						if (uci) $('cascading-inc').slideUp({ duration: .3 });
						else $('cascading').slideUp({ duration: .3 });
					} else {
						$$('#nav li').invoke('removeClassName', 'selected');
						$(this).up('li').addClassName('selected');
						
						if (uci) {
							if ($('cascading').visible()) {
								$('cascading').hide(); // hide the main cascading block if it's visible
								$('cascading-inc').show();
							} else $('cascading-inc').slideDown({ duration: .3 });
						} else {
							// show the correct section
							$$('#cascading .section').invoke('hide');
							container.show();
							
							if ($('cascading-inc').visible()) {
								$('cascading-inc').hide(); // hide the main cascading block if it's visible
								$('cascading').show();
							} else if (!$('cascading').visible()) $('cascading').slideDown({ duration: .3 });
						}
					}
					return false;
				}
			}
		});
		$('cascading-close').onclick = function() {
			$$('#nav li').invoke('removeClassName', 'selected');
			$('cascading').slideUp({ duration: .3 });
			return false;
		}
		$('cascading-inc-close').onclick = function() {
			$$('#nav li').invoke('removeClassName', 'selected');
			$('cascading-inc').slideUp({ duration: .3 });
			return false;
		}
		
		// popup calendars for "what to do"
		Calendar.setup({
			dateField: 'start-date',
			triggerElement: 'start-date-button'
		})
		Calendar.setup({
			dateField: 'end-date',
			triggerElement: 'end-date-button'
		})
		
		// home page accordion
		$$('.home-slide .overlay').each(function(x) {
			$(x).hide();
			if (!$(x).up('.home-slide').hasClassName('first')) {
				x.onclick = function() {
					if ($(this).up('.home-slide').hasClassName('collapsed')) {
						$(this).setOpacity(0);
						// open the slide
						$(this).up('.home-slide').setStyle({
							width: '909px'
						}).morph('height: 340px;', {
							duration: .3, 
							afterFinish: (function() {
								$(this).up('.home-slide').setStyle({ overflow: 'visible' });
							}).bind(this)
						});
						$(this).next('.location-image').morph('top: 0;', { duration: .3 });
						$(this).next('.location-image').next('.info').morph('margin-left: 645px;', { duration: .3, delay: .3 });
						$(this).up('.home-slide').removeClassName('collapsed');
					} else {
						// close the slide
						$(this).next('.location-image').next('.info').morph('margin-left: 381px;', {
							duration: .3,
							afterFinish: (function() {
								$(this).up('.home-slide').setStyle({ overflow: 'hidden' });
							}).bind(this)
						});
						$(this).up('.home-slide').morph('height: 125px;', {
							duration: .3, 
							delay: .3,
							afterFinish: (function() {
								$(this).up('.home-slide').setStyle({ width: '645px' });
								$(this).setOpacity(1);
							}).bind(this)
						});
						$(this).next('.location-image').morph('top: -40px;', { duration: .3, delay: .3 });
						$(this).up('.home-slide').addClassName('collapsed');
					}
				}
			}
		});
		
		// overlay on rollover
		$$('.home-slide').each(function(x) {
			x.observe('mouseenter', function() {
				if ($(this).hasClassName('collapsed')) $(this).down('.overlay').show();
			});
			x.observe('mouseleave', function() {
				if ($(this).hasClassName('collapsed')) $(this).down('.overlay').hide();
			});
		});
		
		// move the cascading uci nav to 81 and hide it
		setTimeout(function() {
			$('cascading-inc').setStyle({ top: '81px' }).hide();
			inc_loaded = true;
		}, 500);
		
		// match inc nav column heights
		var inc_height = 0;
		$$('#cascading-inc .column').each(function(x) { if ($(x).getHeight() > inc_height) inc_height = $(x).getHeight(); });
		$$('#cascading-inc .column').invoke('setStyle', { height: inc_height + 'px' });
		
		// match power footer column heights
		var max_height = 0;
		$$('#power-nav .column').each(function(x) { if ($(x).getHeight() > max_height) max_height = $(x).getHeight(); });
		$$('#power-nav .column').invoke('setStyle', { height: max_height + 'px' });
		
		// poll voting
		$$('#quick-poll input[type=radio]').each(function(x) {
			x.onclick = function() {
				var split = $(this).identify().split('-');
				var poll = split[1];
				var answer = split[2];
				
				if (polls_answered.indexOf(poll) == -1) {
					new Ajax.Request('/index.php', {
						method: 'post',
						parameters: {
							'action': 'poll-submission',
							'poll_id': poll,
							'answer': answer
						},
						onComplete: function(transport) {
							var width = 135;
							var most = 1;
							var responses = transport.responseText.evalJSON();
							for (var i = 1; i <= 5; i++) {
								responses['answer' + i] = parseInt(responses['answer' + i]);
								if (responses['answer' + i] > responses['answer' + most]) most = i;
								if ($('answer-' + poll + '-' + i)) {
									$('answer-' + poll + '-' + i).down('.fill').setStyle({ width: '0px' });
									$('answer-' + poll + '-' + i).down('.fill').morph('width: ' + (width * responses['answer' + i] / 100) + 'px;', { duration: .5 });
								}
							}
							$('answer-' + poll + '-' + most).down('p').addClassName('selected');
						}
					});
					polls_answered.push(poll);
				} else {
					alert("You have already responded to this poll.");
				}
			}
		});
		
		// page nav dropdowns
		$$('.page-nav li a').each(function(x) {
			if (x.next('ul')) {
				x.onclick = function() {
					$(this).next('ul').toggle();
					return false;
				}
			}
		});
		
		// set the position of the red sign up flag
		set_signup_pos();
		
		// home page featured events
		if ($('home-events')) {
			setInterval(function() {
				$('home-events').setStyle({ height: (get_window_height() - 750) + 'px' }).show();
			}, 1);
		}
		
		// search field focus/blur
		$('search_text').onfocus = function() { if (this.value == 'search') this.value = ''; }
		$('search_text').onblur = function() { if (this.value == '') this.value = 'search'; }
		
		// email address focus/blur
		$('email-address').onfocus = function() { if (this.value == 'your email address') this.value = ''; }
		$('email-address').onblur = function() { if (this.value == '') this.value = 'your email address'; }
	});	
	
	function set_signup_pos() {
		// set and position the "sign up" tag in the footer
		var offset = $('main').viewportOffset()[0];
		$('sign-up-label').setStyle({
			width: (60 + offset) + 'px',
			left: (-1 * offset) + 'px'
		}).show();
	}
	
	function fill_nav_dates(start, end) {
		$('start-date').value = start;
		$('end-date').value = end;
		
		// highlight the fields
		new Effect.Highlight('start-date', { duration: 1.5 });
		new Effect.Highlight('end-date', { duration: 1.5 });
		$('what-to-do-form').submit();
	}
	
	function nav_sub_categories(category_id) {
		new Ajax.Request('/inc/ajax.php?method=get-sub-categories&category_id=' + category_id, {
			onComplete: function(transport) {
				$('where-to-go-category2').update(transport.responseText);
				$('where-to-go-category2').disabled = false;
			}
		});
	}
	
	function show_uci_nav() {
		Effect.ScrollTo('header', {
			duration: 0, 
			afterFinish: function() {
				$('uci').down('a').simulate('click');
			}
		});
	}
	
	function submit_where() {
		if ($('where-to-go-keywords').value) {
			$('where-to-go-form').submit();
		} else if (!$('where-to-go-keywords').value && $('where-to-go-category').value) {
			// no keywords... do category url
			if ($('where-to-go-category2').value) location.href = '/locations/category/' + $('where-to-go-category2').value;
			else location.href = '/locations/category/' + $('where-to-go-category').value;
		}
	}
	
	function get_window_height() {
		var document_height, window_height;
		
		if (window.innerHeight && window.scrollMaxY) document_height = window.innerHeight + window.scrollMaxY;
		else if (document.body.scrollHeight > document.body.offsetHeight) document_height = document.body.scrollHeight;
		else document_height = document.body.offsetHeight;
		
		if (self.innerHeight) window_height = self.innerHeight;
		else if (document.documentElement && document.documentElement.clientHeight) window_height = document.documentElement.clientHeight;
		else if (document.body) window_height = document.body.clientHeight;
		
		return (document_height < window_height) ? window_height : document_height;
	}
	
	Event.observe(window, 'resize', function() { set_signup_pos(); });
