$(document).ready(function() {

	var root = $('#page-header h1 a').attr('href');
/*----------------------------------------------------------------------------
	Fix IE hover:
----------------------------------------------------------------------------*/
	if ($.browser.msie) {

		$('a.embed').remove();

		$('div.col:last-child:not(#content,#aside,.secondary)').css("width", "48%");
		$('.col:last-child, ul.find-us-on li:last-child,ul.inline-list li:last-child,ul.tiles li:last-child,ul.tiles .public:nth-child(4n),ul.tiles .private:nth-child(3n)').css("marginRight","0");

		/* Form Validation */
		$('div.triple:nth-child(6) .information:nth-child(2)').addClass("ie-suburb");
		$('div.triple:nth-child(6) .information:nth-child(4)').addClass("ie-postcode");
		$('div.double:nth-child(3) .information:nth-child(2), div.double:nth-child(4) .information:nth-child(2), #payment div.double .information:nth-child(2)').addClass("ie-double");

		/* Homepage has some specific styles */
		$('#promotions .promo:last-child, #join-the-fid').css("width","439px");
		$('#footer .col').css("width","25%");

		/* IE6 Only, 7&8 support these things :) */
		if($.browser.version == "6.0") {

			$('#nav li').hover(
				function() {
					$(this).addClass('hover');
				},
				function() {
					$(this).removeClass('hover');
				}
			).focus(
				function() {
					$(this).addClass('hover');
				},
				function() {
					$(this).removeClass('hover');
				}
			);

			$('ol li.block:first-child','#content').css("borderTop","1px solid #d8e0e2");
			$('#promotions .promo:first-child').css("width","458px");
			$('#footer dl.inline dt:first-child').css("display","none");
			$('#aside .box:first-child').css("marginTop", "0");
			$('div.single-label div.field:first-child','#content').css("margin","12px 0 0");
			$('div.offset .field:first-child', '#content').css("width","24%");
			$('form.overhead .spacer div.field-check + .information .description', "#content").addClass("ie-fix-field-check-spacer");
			$('form.overhead div.field-check + .information .description',"#content").addClass("ie-fix-field-check").css("left","270px"); /* For some reason IE only works with this */
		}
	}

/*----------------------------------------------------------------------------
	Equal Heights Event Artists
----------------------------------------------------------------------------*/
	$('#content ol.tiles li.three, #content ol.tiles li.two').each(function() {
		var self = $(this),
			prev = self.prev(),
			prevv = prev.prev(),
			heights = [
						self.height(),
						prev.height()
					];

		if(self.hasClass("three")) {
			heights.push(prevv.height())
		}

		var rowHeight = Math.max.apply({}, heights);

		self.height(rowHeight);
		prev.height(rowHeight);

		if(self.hasClass("three")) {
			prevv.height(rowHeight);
		}

	});

/*----------------------------------------------------------------------------
	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'
	};

	$('#content').find('ol.tiles > li a.lightbox').each(function() {
		$(this).lightBox(lbconfig);
	}).end().find('ul.tiles a.lightbox').lightBox(lbconfig);

/*----------------------------------------------------------------------------
	Highlight top
----------------------------------------------------------------------------*/

	if(window.location.hash == "#membership") {
		$('#membership input:eq(0)').focus();
	}

});

$(window).ready(function() {

	/*----------------------------------------------------------------------------
		Open external links in a new tab/window
	----------------------------------------------------------------------------*/
		$('a.external, a[rel=external]').live("click",function() {
			window.open($(this).attr('href'));
			return false;
		});

	/*----------------------------------------------------------------------------
		Highlight top
	----------------------------------------------------------------------------*/

		$('a[href$=#login-form]').live("click",function() {
			$("#login-form input").addClass("highlight");
			$("#login-form input:eq(0)").focus();
			return false;
		});

	/*----------------------------------------------------------------------------
		Embed
	----------------------------------------------------------------------------*/
		$('a.embed', 'div.secondary').live("click",function() {
			if($('#embedded').hasClass('show')) {
				$('#embedded').slideUp("fast").removeClass("show");
			} else {
				$('#embedded').slideDown("normal").addClass("show");
			}
			return false;
		})

		$('#close').live("click",function() {
			$('#embedded').slideUp("fast").removeClass("show");
			return false;
		});
})