function getViewportSize() {
	var size = [0, 0];
	if (typeof window.innerWidth != "undefined") {
		size = [window.innerWidth, window.innerHeight];
	}
	else if (typeof document.documentElement != "undefined" && typeof document.documentElement.clientWidth != "undefined" && document.documentElement.clientWidth != 0) {
		size = [document.documentElement.clientWidth, document.documentElement.clientHeight];
	}
	else {
		size = [document.getElementsByTagName("body")[0].clientWidth, document.getElementsByTagName("body")[0].clientHeight];
	}
	return size;
}
function createFullBrowserFlash() {
	swfobject.createCSS("html", "height:100%;");
	swfobject.createCSS("body", "height:100%;");
	swfobject.createCSS("#site", "margin:0; width:100%; height:100%; min-width:1000px; min-height:650px; max-width:100%");
	window.onresize = function() {
		var el = document.getElementById("site");
		var size = getViewportSize();
			el.style.width = size[0] < 980 ? "980px" : "100%";
		el.style.height = size[1] < 650 ? "650px" : "100%";
	};
	window.onresize();
}

var flashvars = {};
var params = {
	allowScriptAccess: "sameDomain"
};
var attributes = {};
swfobject.embedSWF("/index.swf", "site", "100%", "100%", "9.0.0", false, flashvars, params, attributes);
if (swfobject.hasFlashPlayerVersion("9.0.0")) {
	swfobject.addDomLoadEvent(createFullBrowserFlash);
}


function hide_footer_links() {
	$('#footer-links').animate({'marginLeft': '-410px'});
}



// Set equal heights
function eq_height() {
	
	// Set #nav height to the same height as #content
	// Ignore IE because we can't trust it
	// Set two tags to equal height
	var ch = $('#content').height();
	var nh = $('#navigation').height();
	
	// Add additional 'height' to cater for padding
	//nh = nh + 80;
	
	// Set default height
	var max_height = ch;
	
	// Is the nav taller?
	if (nh > max_height) {
		max_height = nh;
	}
	
	// Is the contact form taller?
	if ($('#contact-form').length) {
		var fh = $('#contact-form').height();
		if (fh > max_height) {
			max_height = fh;
		}
	}
	
	// Set new heights
	$('#content').css('min-height', max_height + 'px');
	$('#navigation').css('min-height', max_height + 'px');
	$('#contact-form').css('min-height', max_height + 'px');
}



$(document).ready(function(){

	// Footer behaviour
	$('#footer-links').css('marginLeft', '-410px');
	
	$('#show-footer span').click(function(){
		$('#footer-links').animate({'marginLeft': '0'});
		
		t = setTimeout("hide_footer_links()", 5000)
		return false;
	});

	$('#footer-links').hover(function(){
			clearTimeout(t);
		},
		function(){
			t = setTimeout("hide_footer_links()", 5000)
		}
	);
	
	
	
	// Set up Show/Hide #content buttons
	if ($('#content-control').length > 0) {

		if (!swfobject.hasFlashPlayerVersion("9.0.0")) {
			$('#hide-content').show();
		}

		$('#hide-content').click(function(){
			$('#hide-content').hide();
			$('#show-content').show();
			$('#content, #contact-form').hide();
		});

		$('#show-content').click(function(){
			$('#hide-content').show();
			$('#show-content').hide();
			$('#content, #contact-form').show();
		});
	}
	

	// Validate contact forms
	$('#built-in-contact-form').submit(function(){
		var valid = true;

		$('#built-in-contact-form .validation_required').each(function(i, el) {
			var element = $(el);
			if (element.attr('value') == '') {
				valid = false;
				element.addClass('error');
			} else {
				element.removeClass('error');
			}
		});

		if (valid != true) {
			$('#error-message').show();
			
			// Fix Height
			eq_height();
			
			return false;
		}
	});
	

	// Accordions for content areas
	var accordions = $('#main-content .accordion');
	if (accordions.length > 1) {
		$('#main-content h3.accordion-title').css('cursor', 'pointer');
		accordions.hide();
		$('#main-content .accordion:first').show();

		$('#main-content h3.accordion-title').click( function() {
			var checkElement = $(this).next('.accordion');
			
			if (checkElement.is(':visible')) {
				checkElement.slideUp('normal', function() { } );
				return false;
			}
			
			if (!checkElement.is(':visible')) {
				$('#content .accordion:visible').slideUp('normal', function() { } );
				checkElement.slideDown('normal', function() { } );
				return false;
			}
		});
	}

	
	// Fix Height
	eq_height();
	
	// Lightbox for images    		
	Shadowbox.init({
		overlayOpacity: '0.7'
	});


});
