
var Local = {

    onCommentReply: function(id) {
		Comments.openReply(id);
	},

    onCancelReply: function(id) {
		Comments.closeReply();
	}

};

(function() {
	Array.prototype.in_array = function (obj) {
		var len = this.length;
		for ( var x = 0 ; x <= len ; x++ ) {
			if ( this[x] == obj ) return true;
		}
		return false;
	}
	
	var $ = jQuery

	var body_bg_height = 181

	jQuery.ie6 = false

	if(jQuery.browser.msie && jQuery.browser.version < 7) {
		jQuery.ie6 = true
	}
	
	$(document).ready(
		function() {
			fix_height()
			$('body').css({backgroundPosition: '0px 0px'})
			map_hovers()
			zebra()
			forms()
			tour_cdm()
			photo_viewer()
			tour_popups()
			map_popups()
			photo_popups()
			popups_fix()
			ie_hr_fix()
			nav()
			calendar_tables()
			calendar()
			//below_the_fold()
			h3_fix()
			$('#main h3').each(
				function() {
					if($(this).prev('hr').size() || ($(this).parent('div.page-content').parent('div').prev('hr').size() && $(this).is(':first-child'))) {
						$(this).addClass('first')
					}
				}
			)
			$('#main h3 + h4').addClass('first')
			$('#whats-happening').click(
				function() {
					if($(this).find('a').size()) {
						window.location = $(this).find('a').attr('href')
					}
				}
			).css({cursor: 'pointer'})
			$('a').click(function() {$(this).blur()})
			$('ul.navigation li:first-child').addClass('first')
		}
	)

	$(window).load(
		function() {
			scrolling_background()
			fix_height()
			preload_hovers()
			press_photos()
			//setTimeout("reset_below_the_fold()", 10000)
		}
	)

	$(window).resize(
		function() {
			fix_height()
		}
	)

	function fix_height() {
		if($('body').height() < $('html').height()) {
			$('body').height($('html').height())
		}
		if($('#wrapper').outerHeight() < $('body').height()) {
			$('#wrapper').height($('body').height() - ($('#wrapper').outerHeight(true) - $('#wrapper').height()))
		}
	}

	function scrolling_background() {
		if(jQuery.ie6) {
			return
		}
		setInterval(
			function() {
				var bg_pos = $('body').css('backgroundPosition')
				bg_pos = bg_pos.split(' ')
				bg_pos = {x: parseInt(bg_pos[0], 10), y: parseInt(bg_pos[1], 10)}
				if(Math.abs(bg_pos.y) < body_bg_height) {
					$('body').css({backgroundPosition: bg_pos.x + 'px ' + (bg_pos.y - 1) + 'px'})
				} else {
					$('body').css({backgroundPosition: '0px 0px'})
				}
			}, 80
		)
	}

	function map_hovers() {
		$('div.map a[rel], div.legend a[rel]').each(
			function() {
				var link = $(this)
				var rel = $(this).attr('rel')
				link.hover(
					function() {
						$('a[rel=' + rel + ']').addClass('hover')
					},
					function() {
						$('a[rel=' + rel + ']').removeClass('hover')
					}
				)
			}
		)
	}

	function zebra() {
		$('tr').each(
			function(line) {
				if(line % 2) {
					$(this).addClass('even')
				} else {
					$(this).addClass('odd')
				}
			}
		)
		var pages = new Array('trip-tips')
		if(pages.in_array($('html').attr('id'))) {
			var content = $('div.content')
			
			content.each(function() {
				var h3s = content.find('h3')
				
				h3s.each(function(i) {
					var h3 = $(this)
					var item = $(jQuery('<div class="item"></div>'))
					item.addClass(i % 2 ? 'item-even' : 'item-odd')
					var sibs = h3.nextAll()
					var foundOne = false
					sibs.each(function() {
						var elem = $(this)
						var tag = this.tagName.toLowerCase()
						if(tag == 'h3') {
							foundOne = true
						}
						if(!foundOne) {
							elem.appendTo(item)
						}
					})
					h3.clone(true).prependTo(item)
					h3.replaceWith(item)
				})
			})
		}
	}
	
	function forms() {
		$('.form-type-radio label, .form-type-checkbox label').click(function() { $(this).siblings('input.input-radio, input.input-checkbox').click() })
		var inputs = $('input.input-text')
		inputs.each(
			function() {
				if($(this).val() == '' && $(this).prev('label').size() && !$(this).parent('div').hasClass('corporate-acknowledgment')) {
					var default_val = $(this).prev('label').html()
					$(this).val(default_val).attr({title: default_val})
					$(this).prev('label').remove()
				}
				default_val = $(this).val()
				$(this).focus(
					function() {
						if($(this).val() == default_val) {
							$(this).val('')
						}
					}
				)
				$(this).blur(
					function() {
						if($(this).val() == '') {
							$(this).val(default_val)
						}
					}
				)
			}
		)
		$('fieldset.recipient input[type=radio][value="Yes"]').click(function() { $('fieldset.recipient-address').slideDown()})
		$('fieldset.recipient input[type=radio][value="No"]').click(function() { $('fieldset.recipient-address').slideUp()})
		$('fieldset.recipient-address').hide()
		$('fieldset.matching-question input[type=radio][value="Yes"]').click(function() { $('fieldset.matching-info').slideDown()})
		$('fieldset.matching-question input[type=radio][value="No"]').click(function() { $('fieldset.matching-info').slideUp()})
		$('fieldset.matching-info').hide()
		$('fieldset.gift input[type=radio][value="Yes"]').click(function() { $('div.giver-info').slideDown()})
		$('fieldset.gift input[type=radio][value="No"]').click(function() { $('div.giver-info').slideUp()})
		$('div.giver-info').hide()
		$('div.third-adult input[type=text]').attr({disabled: 'disabled'}).addClass('disabled')
		$('div.third-adult').slideUp()
		$('.form-type-membership-package input[value*=+ 1]').click(
			function() {
				$('div.third-adult input[type=text]').removeAttr('disabled').removeClass('disabled')
				$('div.third-adult').slideDown()
			}
		)
		$('.form-type-membership-package input:not([value*=+ 1])').click(
			function() {
				$('div.third-adult input[type=text]').attr({disabled: 'disabled'}).addClass('disabled')
				$('div.third-adult').slideUp()
			}
		)
	}
	
	function tour_cdm() {
		if(!$('html#tour-creative-discovery-museum').size() && !$('html#mini-tour').size()) {
			return
		}
		var legend = $('div.legend')
		var list = legend.find('ul')
		var exhibits = legend.find('li.permanent-exhibits, li.and-more, li.arts-alley')
		var rooms = legend.find('li.rooms')
		var misc = legend.find('li.misc')
		misc.each(
			function() {
				$(this).html($(this).find('a').html())
				$(this).find('a').remove()
			}
		)
		if(exhibits.size()) {
			legend.append(
					$(jQuery('<ul />'))
						.addClass('exhibits')
						.append(exhibits)
				)
		}
		if(rooms.size()) {
			legend.append(
				$(jQuery('<ul />'))
					.addClass('rooms')
					.append(rooms)
			)
		}
		if(misc.size()) {
			legend.append(
				$(jQuery('<ul />'))
					.addClass('misc')
					.append(misc)
			)
		}
		list.remove()
		legend.append($(jQuery('<div class="clear"></div>')))
		$('li.permanent-exhibits.arts-alley, li.permanent-exhibits.and-more, li.and-more.creation-station, li.and-more.discovery-library, li.back-alley-theatre, li.arts-studio').remove()
	}
	
	function photo_viewer(hide_list) {
		if(hide_list == undefined) {
			hide_list = false
		}
		var lists = $('ul.all-attachments')
		
		if(!lists.size()) {
			return
		}

		if(!$('#large-popup').size()) {
			var popup = $('<div />')
			popup.attr({id: 'large-popup'})
			popup.css({display: 'none'})
			$('body').append(popup)
		} else {
			var popup = $('#large-popup')
		}
		
		popups_fix()
		
		lists.each(
			function() {
				var list = $(this)
				var images = list.find('img')
				if(!images.size()) {
					return
				}
				var container = $(jQuery('<div />'))
				list.parent().append(container)
				if(hide_list) {
					container.hide()
				}
				container.addClass('photo-viewer')
				images.each(
					function(count) {
						$(this).attr({number: count})
						$(this).click(
							function() {
								popup.empty().hide()
								var target = $(jQuery('<div />'))
								target.addClass('target')
								target.addClass('photo')
								var silly_ie_annoyance = $('<div />')
								silly_ie_annoyance.addClass('inner')
								silly_ie_annoyance.append(
										target
										.append($(this).clone(true))
										.append(
											$(jQuery('<a />'))
												.attr({href: '#'})
												.addClass('close')
												.text('Close')
												.click(
													function(c) {
														c.preventDefault()
														popup.fadeOut('fast')
													}
												)
										)
									)
								popup.append(silly_ie_annoyance)
								popup.fadeIn('fast')
							}
						)
					}
				)
				images.hide()
				$(images[0]).show().attr({current: 'current'})
				container.append(images)
				if(images.size() > 1) { // We need navigation
					var prev = $(jQuery('<div />'))
					var next = $(jQuery('<div />'))
					container.prepend(prev)
					container.append(next)
					prev
						.addClass('prev')
						.click(
							function() {
								var current_img = parseInt(container.find('img[current]').attr('number'), 10)
								if(container.find('img[number=' + (current_img - 1) + ']').size()) {
									container.addClass('loading')
									container.find('img[current]').fadeOut('slow',
										function() {
											container.find('img[current]').removeAttr('current')
											container.find('img[number=' + (current_img - 1) + ']')
												.fadeIn('slow',
													function() {
														container.removeClass('loading')
													}
												)
												.attr({current: 'current'})
										}
									)
								}
								if(container.find('img[number=' + (current_img - 2) + ']').size()) {
									prev.css({visibility: 'visible'})
								} else {
									prev.css({visibility: 'hidden'})
								}
								next.css({visibility: 'visible'})
							}
						)
						.css({visibility: 'hidden'})
					next
						.addClass('next')
						.click(
							function() {
								var current_img = parseInt(container.find('img[current]').attr('number'), 10)
								if(container.find('img[number=' + (current_img + 1) + ']').size()) {
									container.addClass('loading')
									container.find('img[current]').fadeOut('slow',
										function() {
											container.find('img[current]').removeAttr('current')
											container.find('img[number=' + (current_img + 1) + ']')
												.fadeIn('slow',
													function() {
														container.removeClass('loading')
													}
												)
												.attr({current: 'current'})
										}
									)
								}
								if(container.find('img[number=' + (current_img + 2) + ']').size()) {
									next.css({visibility: 'visible'})
								} else {
									next.css({visibility: 'hidden'})
								}
								prev.css({visibility: 'visible'})
							}
						)
				}
				list.remove()
			}
		)
	}
	
	function tour_popups() {
		var links = $('.map a, .legend a')
		links.each(
			function() {
				var link = $(this)
				if(!link.parents('.permanent-exhibits,.and-more,.arts-alley,.exhibits,.tour-downtown-chattanooga').size()) {
					link.css({cursor: 'default'})
					link.removeAttr('href')
					return
				}
				link.click(
					function(c) {
						c.preventDefault()
						var url = link.attr('href')
						if(!$('#ajax-loader').size()) {
							$('body').append(
								$(jQuery('<div />'))
									.attr({id: 'ajax-loader'})
									.css({
										position: 'absolute',
										top: '-10000px',
										left: '-10000px',
										height: '0px',
										width: '0px'
									})
							)
						}
						if(!$('#popup').size()) {
							$('body').append(
								$(jQuery('<div />'))
									.attr({id: 'popup'})
							)
						} else {
							$('#popup').empty()
						}
						popups_fix()
						var popup = $('#popup')
						var top = $(jQuery('<div />'))
						top.addClass('top')
						popup.append(top)

						var content = $(jQuery('<div />'))
						content.addClass('middle')
						popup.append(content)
						
						var container = $(jQuery('<div />'))
						container.addClass('loading')
						container.addClass('container')
						container.addClass(link.parent('li').attr('class'))
						content.append(container)

						var bottom = $(jQuery('<div />'))
						bottom.addClass('bottom')
						popup.append(bottom)
						popup.fadeIn(
							'fast',
							function() {
								var temp = $('#ajax-loader')
								temp.load(
									url + ' #content',
									{},
									function() {
										png_fix()
										ie_hr_fix()
										var h2 = temp.find('h2')
										if(h2.size()) {
											container
												.append(
													$(jQuery('<h2 />'))
														.hide()
														.html(
															h2.html()
														)
												)											
										}
										var teaser = temp.find('.teaser')
										if(teaser.size()) {
											container
												.append(
													$(jQuery('<p />')).html(teaser.html()).hide()
												)
										}
										var attachments = temp.find('ul.all-attachments')
										if(attachments.size()) {
											container
												.append(
													attachments.hide()
												)
											photo_viewer(true)
										}
										var external_link = temp.find('p.link')
										if(external_link.size()) {
											container.append(external_link.hide())
										}
										top
											.append(
												$(jQuery('<a />'))
													.hide()
													.attr({href: url})
													.addClass('full-view')
													.text('Read More')
											)
											.append(
												$(jQuery('<a />'))
													.hide()
													.attr({href: '#'})
													.addClass('close')
													.text('Close')
													.css({display: 'block'})
													.click(
														function(c) {
															c.preventDefault()
															popup.fadeOut('fast')
														}
													)
											)
										container.children().fadeIn()
										top.find('a').fadeIn()
										$(container).removeClass('loading')
									}
								)
							}
						)
					}
				)
			}
		)
	}
	
	function map_popups() {
		if(!$('html#tickets-and-planning-your-visit').size()) {
			return
		}
		
		if(!$('#large-popup').size()) {
			var popup = $('<div />')
			popup.attr({id: 'large-popup'})
			popup.css({display: 'none'})
			$('body').append(popup)
		} else {
			var popup = $('#large-popup')
		}
		popups_fix()
		
		$('a#directions-button,a#parking-button').click(
			function(c) {
				c.preventDefault()
				popup.hide()
				var url = $(this).attr('href')
				if(!$('#ajax-loader').size()) {
					$('body').append(
						$(jQuery('<div />'))
							.attr({id: 'ajax-loader'})
							.css({
								position: 'absolute',
								top: '-10000px',
								left: '-10000px',
								height: '0px',
								width: '0px'
							})
					)
				}
				var temp = $('#ajax-loader')
				temp.empty()
				popup.empty()
				var silly_ie_annoyance = $('<div />')
				silly_ie_annoyance.addClass('inner')
				popup.append(silly_ie_annoyance)
				var target = $(jQuery('<div />'))
				target.addClass('target')
				target.addClass('loading')
				target.addClass('yui-g')
				target.addClass(String($(this).attr('id')).replace(/-button/,''))
				silly_ie_annoyance.append(target)
				$('#large-popup').fadeIn('fast')
				temp.load(
					url + ' #main',
					{},
					function() {
						png_fix()
						ie_hr_fix()
						target
							.append(
								$(jQuery('<a />'))
									.attr({href: '#'})
									.addClass('close')
									.append(
										$(jQuery('<img />'))
											.attr({src: '/images/clear.gif'})
									)
									.click(
										function(c) {
											c.preventDefault()
											$('#large-popup').fadeOut('fast')
										}
									)
							)
							.append(
								temp.find('h2').hide()
							)
							.append(
								temp.find('.teaser').children().hide()
							)
							.append(
								temp.find('.content').children().hide()
							)
							.removeClass('loading')
							.children().fadeIn('fast')
					}
				)
			}
		)
	}

	function photo_popups() {
		$('li.thumb').each(
				function(i) {
					if(String(i/4).split('.').length == 1) {
						$(this).addClass('row-first')
					}
					if(String((i+1)/4).split('.').length == 1) {
						$(this).addClass('row-last')
					}
					$(this).hover(
						function() {
							$(this).addClass('thumb-hover')
						},
						function() {
							$(this).removeClass('thumb-hover')
						}
					)
					if($(this).find('div').size()) {
						var child = $(this).find('div')
						child.css({
							padding: Math.round(($(this).height() - child.height()) / 2) + 'px 0'
						})
					}
				}
			)
		if(!$('#large-popup').size()) {
			var popup = $('<div />')
			popup.attr({id: 'large-popup'})
			popup.addClass('photo-popup')
			popup.css({display: 'none'})
			$('body').append(popup)
		} else {
			var popup = $('#large-popup')
		}
		popups_fix()
		$('a[rel*=photo-popup]').click(
			function(c) {
				c.preventDefault()
				$('a[rel*=photo-popup][current]').removeAttr('current')
				$(this).attr({current: 'current'})
				popup.empty()
				var silly_ie_annoyance = $('<div />')
				silly_ie_annoyance.addClass('inner')
				popup.append(silly_ie_annoyance)
				var target = $(jQuery('<div />'))
				target.addClass('target')
				target.addClass('loading')
				silly_ie_annoyance.append(target)
				$('#large-popup').fadeIn('fast')
				png_fix()
				ie_hr_fix()
				if($('a[rel*=photo-popup]').size() > 1) {
					if($(this).parent('li.thumb').prev('li.thumb').find('a[rel*=photo-popup]').size()) {
						var prev = $(jQuery('<div />'))
						prev.addClass('prev')
						prev.click(
							function() {
								$('a[rel*=photo-popup][current]').parent('li.thumb').prev('li.thumb').find('a[rel*=photo-popup]').click()

							}
						)
						popup.append(prev)
					}
					if($(this).parent('li.thumb').next('li.thumb').find('a[rel*=photo-popup]').size()) {
						var next = $(jQuery('<div />'))
						next.addClass('next')
						next.click(
							function() {
								$('a[rel*=photo-popup][current]').parent('li.thumb').next('li.thumb').find('a[rel*=photo-popup]').click()
							}
						)
						popup.append(next)
					}
				}
				target
					.append(
						$(jQuery('<a />'))
							.attr({href: '#'})
							.addClass('close')
							.append(
								$(jQuery('<span />'))
									.text('Close')
							)
							.append(
								$(jQuery('<img />'))
									.attr({src: '/images/clear.gif'})
							)
							.click(
								function(c) {
									c.preventDefault()
									$('#large-popup').fadeOut('fast')
								}
							)
					)
					.append(
						$(jQuery('<h2 />')).html(String($(this).attr('title')).replace(/-/,' '))
					)
					.append(
						$(this).find('img').clone('true').hide()
					)
					.children().fadeIn('fast', function() {
						target.removeClass('loading')
					})
			}
		)
	}
	
	function popups_fix() {
		if(!jQuery.ie6) {
			return
		}
		var browser_height	=	document.documentElement.clientHeight
		var scroll_offset	=	document.documentElement.scrollTop
		$('#popup,#large-popup').css({
			top: (scroll_offset + 25) + 'px',
			marginTop: 0,
			position: 'absolute'
		})
		$(window).scroll(
			function() {
				var browser_height	=	document.documentElement.clientHeight
				var scroll_offset	=	document.documentElement.scrollTop
				$('#popup,#large-popup').css({
					top: (scroll_offset + 25) + 'px',
					marginTop: 0,
					position: 'absolute'
				})
			}
		)
		$(window).resize(
			function() {
				var browser_height	=	document.documentElement.clientHeight
				var scroll_offset	=	document.documentElement.scrollTop
				$('#popup,#large-popup').css({
					top: (scroll_offset + 25) + 'px',
					marginTop: 0,
					position: 'absolute'
				})
			}
		)
	}
	
	function ie_hr_fix() {
		if(jQuery.browser.msie) {
			$('hr').replaceWith($(jQuery('<div />')).addClass('rule'))
		}
	}
	
	function nav() {
		var links = $('#header ul.navigation li a, #header #buttons li a')
		links.each(
			function() {
				var link = $(this)
				if(link.parent('li').hasClass('selected') || link.parent('li').hasClass('ancestor')) {
					link.addClass('selected')
				}
			}
		)
		$('.tour #main ul.navigation a').each(
			function() {
				if($(this).parent('li').hasClass('selected') || $(this).parent('li').hasClass('ancestor')) {
					$(this).addClass('selected')
				}
			}
		)
	}
	
	function png_fix() {
		if (jQuery.ie6) {}
	}
	
	function calendar_tables() {
		if(!$('table.calendar').size()) {
			return
		}
		var rows = $('table.calendar tr').filter(function() {return $(this).find('td').size() })
		var table = rows.parents('table.calendar')
		var wrapper = $(jQuery('<div />'))
		wrapper.addClass('table-wrapper')
		wrapper.css({overflow: 'visible'})
		table.wrap(wrapper)
		if(rows.size() > 10) {
			var count = 0
			var group_no = 1
			rows.each(
				function() {
					if(count == 10) {
						count = 0
						group_no++
					}
					$(this).attr({group: group_no})
					count++
				}
			)

			$('table.calendar tr td:first-child').each(
				function() {
					var prev = $(this).parent('tr').prev('tr').find('td:first-child')
					if(prev.html() == $(this).html() && prev.parent('tr').attr('group') == $(this).parent('tr').attr('group')) {
						$(this).addClass('remove')
					}
				}
			)
			$('table.calendar tr td.remove').html('').removeClass('remove')


			var nav = $('<div />')
			var prev = $('<a />')
			var next = $('<a />')
			nav.addClass('paged-navigation')
			prev.addClass('prev-link')
			next.addClass('next-link')
			prev.attr({href: '#previous-group', title: 'View Previous Entries', group: 1})
			prev.html('&laquo; Previous')
			next.attr({href: '#next-group', title: 'View Next Entries', group: 2})
			next.html('Next &raquo;')
			nav.append(prev)
			for(var i = 0; i < group_no; i++) {
				nav.append(
						$(jQuery('<span />'))
							.addClass('nav-page')
							.append(
									$(jQuery('<a />'))
										.attr({
											href: '#group-' + (i+1),
											group: (i+1),
											title: 'View Entries ' + (1 + (i*10)) + '-' + (9 + (i*10))
										})
										.html(i+1)
								)
					)
			}
			nav.append(next)
			prev.hide()
			table.find('th').each(
				function() {
					$(this).width($(this).width())
				}
			)
			rows.hide()
			table.find('tr[group=1]').show().attr({current: 'current'})
			nav.find('.nav-page a[group=1]').parent('.nav-page').addClass('selected')
			$('.table-wrapper').height(table.height())
			$('.table-wrapper').after(nav)
			$(nav.find('a')).click(
					function(c) {
						c.preventDefault()
						if($(this).attr('group') == table.find('.nav-page.selected a').attr('group')) {
							return
						}
						var group = parseInt($(this).attr('group'), 10)
						$('.table-wrapper').addClass('loading')
						table.find('tr[current]').removeAttr('current').fadeOut('normal', function() {
							table.find('tr[group=' + group + ']').attr({current: 'current'}).fadeIn('normal', function() {
								$('.table-wrapper').removeClass('loading')
								prev.attr({group: group - 1})
								next.attr({group: group + 1})
								nav.find('.nav-page.selected').removeClass('selected')
								$(this).parent('.nav-page').addClass('selected')
								if(group - 1 < 1) {
									prev.hide()
								} else {
									prev.show()
								}
								if(group + 1 > group_no) {
									next.hide()
								} else {
									next.show()
								}
							})
						})
					}
				)
		}
	}
	
	function preload_hovers() {
		if(!document.images) {
			return
		}
		var preloader = $(jQuery('<div />'))
		preloader.attr({id: 'img-preloader'}).css({position: 'absolute', top: '-100000px', left: '-100000px'})
		$('body').append(preloader)
		var sheets = document.styleSheets
		for(var i = 0; i < sheets.length; i++) {
			if(sheets[i].href.match(document.domain) != null && sheets[i].media.mediaText != 'print') {
				var rules = document.styleSheets[i].cssRules
				for(var j = 0; j < rules.length; j++){
					if(rules[j].cssText.match(/:hover/) != null) {
						var selectors = rules[j].selectorText
						selectors = selectors.split(", ")
						var active = false
						for(var k = 0; k < selectors.length; k++) {
							var selector = selectors[k].replace(':hover','')
							if($(selector).size()) {
								active = true
							}
						}
						if(active) {
							var background = String(rules[j].style.cssText.match(/url\([^\)]+\)/g))
							if(background != 'null') {
								background = background.replace(/url\(([^\)]+)/g,'$1').replace(/\)/,'')
								preloader.append(
									$(jQuery('<img />')).attr({src: background})
								)
							}
						}
					}
				}
			}
		}
	}

	function below_the_fold() {
		if(jQuery.browser.msie) {
			return
		}
		var fold = $('html').height() + $('body').offset().top
		$('img').each(
			function() {
				if($(this).offset().top > fold || $(this).attr('id') == 'print-logo') {
					$(this).attr('orig_src', $(this).attr('src'))
					$(this).removeAttr('src')
				}
			}
		)
		$('h2,h3,li,a,p,div,img')
			.filter(
				function() {
					return ($(this).css('background-image') == 'none') ? false : true
				}
			)
			.each(
				function() {
					if($(this).offset().top > fold) {
						$(this).attr('orig_bg',$(this).css('background-image'))
						$(this).css('background-image','none')
					}
				}
			)
		$(window).bind(
			'scroll',
			reset_below_the_fold
		)
		$(window).bind(
			'resize',
			reset_below_the_fold
		)
	}
	
	function calendar() {
		if(!$('#index div.calendar').size() || $('div.science-theatre').size()) {
			return
		}
		$('div.item:even').addClass('item-even')
		$('div.item:odd').addClass('item-odd')
		if(!$('div.item').size()) {
			$('#main').append(
				$(jQuery('<p />')).text('There are no events currently scheduled for this month.')
			)
		}
	}
	
	function press_photos() {
		if(!$('#hi-res-photos').size()) {
			return
		}
		var tallest = 0
		$('div.thumb-wrapper').each(function() {
			tallest = $(this).outerHeight({'margin': true}) > tallest ? $(this).outerHeight({'margin': true}) : tallest
		})
		$('div.thumb-wrapper').each(function() {
			$(this).height(tallest)
		})
	}
	
	function h3_fix() {
		$('div.page-content > h3:first-child').each(function() {
			var h3 = $(this)
			if(h3.parents('.content').prev('div.teaser:hidden').size()) {
				h3.css({'margin-top': '0'})
			}
		})
	}
})();
function reset_below_the_fold() {
	var images = jQuery('img[orig_src]')
	var elems = jQuery('h2[orig_bg],h3[orig_bg],li[orig_bg],a[orig_bg],p[orig_bg],div[orig_bg],img[orig_bg]')
	if(images.size() + elems.size() == 0) {
		jQuery(window).unbind(
			'scroll',
			reset_below_the_fold
		)
		jQuery(window).unbind(
			'resize',
			reset_below_the_fold
		)
		return
	}

	if(jQuery(images[0]).size() && jQuery(images[0]).attr('orig_src')) {
		var img = jQuery(images[0])
		img.attr({src: img.attr('orig_src')}).removeAttr('orig_src')
		img.load(
			function() {
				reset_below_the_fold()
			}
		)
	}
	if(jQuery(elems[0]).size() && jQuery(elems[0]).attr('orig_bg')) {
		var elem = jQuery(elems[0])
		var bg = jQuery('<img />')
		var bg_src = elem.attr('orig_bg').replace(/url\(/,'').replace(/\)/,'')
		if(!jQuery('#img-preloader img[src=' + bg_src + ']').size()) {
			jQuery('#img-preloader').append(bg.attr({src: bg_src}))
			bg.load(
				function() {
					reset_below_the_fold()
				}
			)
		}
		elem.css({'background-image': ''}).removeAttr('orig_bg')
	}
}

