/*
function fixLayout () {

	var bgPosition = Math.round($(window).width()/2+154-457);
	if (bgPosition < 0) { bgPosition = 0; }
	$('body').css({
		'background-position'	: bgPosition + 'px 0'
	});

	var headerSide = Math.round(($(window).width()-960)/2);
	if (headerSide < 0) { headerSide = 0; }
	$('#header>.left, #header>.right').css({
		'width' : headerSide + 'px'
	});
}*/
function fixLayout () {

	var bgPosition = Math.round($(window).width()/2+154-457);
	if (bgPosition < 0) { bgPosition = 0; }
	$('body').css({
		'background-position'	: bgPosition + 'px 0'
	});

	var headerSide = Math.round(($(window).width()-960)/2);
	if (headerSide < 0) { headerSide = 0; }
	$('#header>.left, #header>.right').css({
		'width' : headerSide + 'px'
	});
	
	$('.mail-wrapper, .video-wrapper').height(Math.max(
		$('.video-wrapper>.video:last').height() + 100,
		$(document).height(),
		$(window).height(),
		$('body').height(),
		$('html').height()
	));
}


function setOn (rel) {
	$('body>#header>.front').find('[rel=' + rel + ']').addClass('on');
}

$(function () {
	fixLayout(); $(window).resize(function () { fixLayout(); });
	$('a[rel=_nw], .mceContentBody a:not(.fancybox)').click(function (e) {
		e.preventDefault();

		if ($(this).attr('href').match(/^http:\/\/(www\.)?(montreal)?completementcirque\.(com|ca)/i) || $(this).attr('href').substr(0,1) == '/') {
			location.href = $(this).attr('href');
		}

		else if ($(this).attr('href').substr(0,6) == 'mailto') {
			location.href = $(this).attr('href');
		}

		else {
			if(typeof _gaq != 'undefined'){
				_gaq.push(['_trackEvent', 'Offsite Links', 'Click', $(this).attr('href')]);
			}

			window.open($(this).attr('href'));
		}
	});

	$('.mceContentBody .fancybox').attr('rel', 'gallery').fancybox({
		cyclic: true,
		overlayOpacity: 0.6,
		overlayColor: '#000',
		titleShow: false
	});
});
