$(document).ready(function() {

	var root = $('h1 a').attr('href');

	$('#data input:eq(0)').focus();

/*----------------------------------------------------------------------------
	Fix IE Stuff
----------------------------------------------------------------------------*/

	if ($.browser.msie) {
		// Hover/Focus
		$('input[type=submit]').hover(
			function() {
				$(this).addClass('hover');
			},
			function() {
				$(this).removeClass('hover');
			}
		);
		// Last/First Child
		$('div.column:first-child').css('margin','0 5px 0 0');
		$('div.column:last-child').css('margin','0 0 0 5px');
		$('ul#nav > li:first-child').css('marginLeft','20px');
	}

/*----------------------------------------------------------------------------
	Presentational |
----------------------------------------------------------------------------*/
	$('ul#nav li:not(:last-child), ul#filter-nav li:not(:last-child)').after("<li class='presentational'>|</li>");

/*----------------------------------------------------------------------------
	Lightbox
----------------------------------------------------------------------------*/
	var lbconfig = {
		imageLoading: root + '/workspace/images/lightbox/lightbox-ico-loading.gif',
		imageBtnClose: root + '/workspace/images/lightbox/lightbox-btn-close.gif',
		imageBtnPrev: root + '/workspace/images/lightbox/lightbox-btn-prev.gif',
		imageBtnNext: root + '/workspace/images/lightbox/lightbox-btn-next.gif',
		imageBlank: root + 'workspace/images/lightbox/lightbox-blank.gif'
	}

	var focusGallery = $('.gallery');

	$('> a.lightbox',focusGallery).lightBox(lbconfig);

	$('h2 a', focusGallery).live('click', function() {
		$('a.lightbox:first', focusGallery).trigger("click");
		return false;
	});

	/*----------------------------------------------------------------------------
		Equal Heights
	----------------------------------------------------------------------------*/
	if(focusGallery.length == 1) {
		focusGallery.height($('#data').height());

		var workingHeight = focusGallery.height() - $('h2', focusGallery).height();
		var numImages = Math.floor(workingHeight / $('a.lightbox:eq(1)', focusGallery).height()) - 1;

		$('a.lightbox:gt(' + numImages + ')').hide();

	} else {
		$('#data, #focus-sidebar').height($('#content').height());
	}
	
	
	/*----------------------------------------------------------------------------
		Home page cycle
	----------------------------------------------------------------------------*/
	$('#limelight .column .rotator').cycle({ 
	    fx:     'fade', 
	    speed:   500, 
	    timeout: 5000 
	 });
	 
});

$(window).ready(function() {
	/*----------------------------------------------------------------------------
		Print
	----------------------------------------------------------------------------*/
		$('a.print').live("click", function() {
			window.print();
			return false;
		});
	/*----------------------------------------------------------------------------
		Open external links in a new tab/window
	----------------------------------------------------------------------------*/

		$('a.external, a[rel=external]').live("click", function() {
			window.open($(this).attr('href'));
			return false;
		});
});

