
/*
==================================================================================================================*/	

var canvas, img, sW, sH, winW, winH, ratio, debug;
sH = 1000;
sW = 1600;

$(document).ready(function(){
	
	canvas = $('#canvas');
	img = $('#canvas > img');
	
	resizeImg();	
	
	// footer More Info slide up
	var infoShown = false;
	$('#more-info h6').click(function() {
		if (infoShown) {
			$('#more-info .summary').parent().parent().removeClass('open').animate({ 'height' : '38px' }, 1000).hide();
			infoShown = false;
		} else {
			$('#more-info .summary').show().parent().parent().addClass('open').animate({ 'height' : '140px' }, 1000);
			infoShown = true;
		}
	});
	
	if ( $('body#index').length > 0 ) {
		// contact form slide-in
		contactWidth = 504;
		$contact = $('#contact-form').css({ 'left' : '-' + contactWidth + 'px' });
		$contact.append('<div class="close"></div>');
		var formShown = false;
		$('a[href="#contact-form"]').click(function() {
			if (formShown) {
				$contact.animate({ 'left' : '-' + contactWidth + 'px' }, 1000);
				formShown = false;
			} else {
				$contact.animate({ 'left' : '0' }, 1000);
				formShown = true;
			}
			return false;
		});
		// if contact form has errors or has been sent (thank you message), then leave open
		if ( $('#contact-form div.error').length > 0 ) {
			$contact.css({ 'left' : '0' });
		} else if ( $('#contact-form p.thanks').length > 0 ) {
			$contact.css({ 'left' : '0' });
			setTimeout( "$contact.animate({ 'left' : '-' + contactWidth + 'px' }, 1000);", 6000);
		} else {
			$contact.css({ 'left' : '-' + contactWidth + 'px' });
		}
		// if close button is clicked
		$('#contact-form .close').click(function() {
			$contact.animate({ 'left' : '-' + contactWidth + 'px' }, 1000);
			formShown = false;
			return false;
		});
	}
	
});

$(window).resize(function() {
	resizeImg();
});

function resizeImg() {
	
	winW = canvas.width();
	winH = canvas.height();
	
	ratio = sH / sW;
	imgW = winW;
    imgH = winW * ratio;
	if (imgH < winH) {
		imgH = winH;
		imgW = imgH / ratio;
	}
	
	img.width(imgW).height(imgH);
}
