$(function(){
	// bars
	$(window).resize(function() {
		var bar = $("[rel=barEl]");
		bar.css({
			'position': 'absolute',
			'width': $(window).width()-$(bar).offset()['left']
		});
	}).resize();
	// framed links
	$(window).load(function() {
		$("a[rel=framed]").click(function(){
			window.location.href = "/framed.php?url="+escape(this.href)+"&title="+escape(this.title)+"&return="+escape(window.location.href)
			return false;
		})
		$("a[rel=replace]").click(function(){
			var o = $(this);
			style = {
				height: $(this).children().height(),
				width: $(this).children().width(),
				display: "block",
				overflow: "hidden"
			};
			$(this).css(style);
			$(this).children(".overlay").fadeOut("fast");
			$(this).children().animate({
				"margin-left":-$(this).width()
			},function() {
				o.href = "";
				o.empty().append("<iframe frameborder='0' border='0' width='100%' src='"+o.attr('href')+"' height='100%' />").children("iframe");
			});
			return false;
		}).each(function() {
			var overlay = $("<span class='overlay overlay"+this.getAttribute('alt')+"'></span>");
			style = {
				height: $(this).children().height(),
				width: $(this).children().width(),
				display: "block",
				overflow: "hidden"
			};
			overlay.css(style).prependTo(this);
		}).mouseover(function() {
			$(this).addClass("hovering");
		}).mousemove(function() {
			$(this).removeClass("hovering");
		});
	});
	$("#contactForm").submit(function() {
		var name = $("#contactForm input[name=name]");
		var org = $("#contactForm input[name=organisation]");
		var phone = $("#contactForm input[name=phone]");
		var email = $("#contactForm input[name=email]");
		var enquiry = $("#contactForm select");
		var message = $("#contactForm textarea");
		var errors = [];
		if(name.val() == "") {
			errors.push("name");
		}
		if(org.val() == "") {
			errors.push("organisation");
		}
		if(email.val() == "" || email.val().lastIndexOf("@") <= 0) {
			errors.push("email");
		}
		if(enquiry.val() == "") {
			errors.push("enquiry");
		}
		if(message.val() == "") {
			errors.push("message");
		}
		if(errors.length) {
			$("#contactForm p").removeClass("error");
			for(var m in errors) {
				$("#contactForm [rel="+errors[m]+"]").addClass("error");
			}
			alert("Please complete the highlighted fields before continuing.");
			return false;
		}
	});
});
var addthis_config = {data_track_linkback: true};
