
$(document).ready(function() {
	var backgroundheight = 2300;
	var now = new Date();
	var hour = now.getHours();
	var minute = now.getMinutes();
	// work out how far through the day we are as a percentage - e.g. 6pm = 75%
	var hourpercent = hour / 24 * 100;
	var minutepercent = minute / 60 / 24 * 100;
	var percentofday = Math.round(hourpercent + minutepercent);
	// calculate which pixel row to start graphic from based on how far through the day we are
	var offset = backgroundheight / 100 * percentofday;

	// graphic starts at approx 6am, so adjust offset by 1/4
	var offset = offset - (backgroundheight / 4);

	function scrollbackground() {
		offset = (offset < 1) ? offset + (backgroundheight + 1) : offset + 1;
		$('body').css("background-position", offset + "px" + " 0");
		setTimeout(function() {scrollbackground();}, 150);
	}
	scrollbackground();
	
	$('img.size-medium').parent('a').attr('rel','shadowbox');
	$('img.size-large').parent('a').attr('rel','shadowbox');
	$('img.size-full').parent('a').attr('rel','shadowbox');
	
	Shadowbox.init({
	    handleOversize: "resize",
	    modal: true
	});
	
	$('#tabs').tabs({ 
		fx: { opacity: 'toggle' }
	});
	$('#box-tabs').tabs({ event: 'mouseover'});
	
	
	$('#list').tabs({ event: 'mouseover'}).tabs('rotate', 4000);
	
	$('#list li a').click( function(){
		var slug = $(this).attr("slug");
		window.location.href=slug
	});
	
	$('#content').hover(function(){
			$("#list").tabs('rotate', 0, false)
		},function(){
			$("#list").tabs({ fx: { opacity: 'toggle' } }).tabs('rotate', 3000)
		}
	);

	$('li.dropdown').hover(function(){
			$(this).children('div').stop(true, true).slideDown();
		},function(){
			$(this).children('div').delay(1000).slideUp();
		}
	);

	$(".bios ul li").each(function() {
		var name = $(this).attr("class");
		var next = $(this).next().attr("class");
		var previous = $(this).prev().attr("class");
		$('#' + name).dialog({
			bgiframe: true,
			autoOpen: false,
			modal: true,
			resizable: true,
			stack: false,
			width: 650,
			open: function(event, ui) {
				$('.next_button').click(function() {
					$('#' + next).dialog('open');
					$('#' + name).dialog('close');
					$('#' + previous).dialog('close');
			    });
				$('.previous_button').click(function() {
					$('#' + previous).dialog('open');
					$('#' + name).dialog('close');
					$('#' + next).dialog('close');
				});
				next = $('.' + name).next().attr("class");
				previous = $('.' + name).prev().attr("class");
			}
		});

	    $(this).click(function() {
			$('#' + name).dialog('open');
	    });
	});

	$('#middle ul.level2').hide();
	$('#middle ul.level1 h1.arrowed').click(function() {
		$(this).toggleClass('down');
		$(this).next('ul.level2').slideToggle('slow');
		$(this).next('ul.level2').siblings('.level2:visible').slideUp('slow');
	});
	
});

