
// COMMON: Load page in a new window; use class="new_window" on <a> tags
$(document).ready(function(){
	$('a.new_window').click(function(){
		w = window.open(this.href, 'new_window');
		return false;
	});
});


// COMMON: Hide "Top of page" on short pages
$(document).ready(function(){
	var w = $(window).height();
	var d = $(document).height();
	var e = $('#header').outerHeight()+$('#footer').outerHeight();
	if (d < (w+e)){
		$('#body .topofpage').remove();
	}
});


// HEADER > NAVIGATION: Display sub-menu
$(document).ready(function(){
	$('#nav .menu').hover(
		function(){
			$(this).css('background-position', '0 -25px');
			$('.submenu1', this).fadeIn(200);
		},
		function(){
			$(this).css('background-position', '0 0');
			$('.submenu1', this).fadeOut(200);
		}
	);

	$('#nav .submenu').hover(
		function(){
			$('.submenu2', this).fadeIn(200);
		},
		function(){
			$('.submenu2', this).fadeOut(200);
		}
	);
});


// ASIDE > TOOLS > SHARE: "Add This" popup window offset
var v = parseInt(jQuery.browser.version);
if (jQuery.browser.mozilla || jQuery.browser.opera || (jQuery.browser.msie && v == 8)){
	var addthis_offset_top = -15;
}
if (jQuery.browser.msie && (v == 6 || v == 7)){
	var addthis_offset_top = 5;
}


// ASIDE > TOOLS > TEXT SIZE: Change the text size (small/large)
$(document).ready(function(){
	if (!$.cookie('cmec_textsize')){
		$.cookie('cmec_textsize', 'small', {path: '/', expires: 365});
	}

	var cookie = $.cookie('cmec_textsize');
	resizeText(cookie);

	$('#text_small').click(function(){
		resizeText('small');
	});
	$('#text_large').click(function(){
		resizeText('large');
	});
});

function resizeText(level){
	switch(level){
		case 'small':
			$('body').css('font-size', '100%');
			$('#text_large').css('background-position', '0 0');
			$('#text_small').css('background-position', '0 -20px');
			$.cookie('cmec_textsize', 'small', {path: '/', expires: 365});
			break;
		case 'large':
			$('body').css('font-size', '120%');
			$('#text_small').css('background-position', '0 0');
			$('#text_large').css('background-position', '0 -20px');
			$.cookie('cmec_textsize', 'large', {path: '/', expires: 365});
			break;
	}
}


// PHOTO ALBUMS: Photo lightbox
TopUp.addPresets({
	'.lightbox a': {
		group: 'lightbox',
		layout: 'dashboard',
		overlayClose: 1,
		readAltText: 1,
		shaded: 1,
		resizable: 0,
		height: 600
	}
});


// PROGRAM > FAQ: Show/Hide answers
$(document).ready(function(){
	$('#faq .q').click(function(){
		$(this).next().slideToggle(0);
		$('p', this).toggleClass('open');
		$('p', this).toggleClass('closed');
	});
});


// PROGRAM > SUBSCRIPTION, PROGRAM > APPLICATIONS: Show/hide coordinators
$(document).ready(function(){
	$('#subscription .toggle, #application .toggle').click(function(){
		var parent = $(this).parent();
		$('.details', parent).toggle('normal');
		$(this).toggleClass('open');
	});
});


// OLP > COORDINATORS, CONTACT > COORDINATORS: Show/hide addresses
$(document).ready(function(){
	$('#plo_coordinators .toggle, #contact_coordinators .toggle').click(function(){
		var parent = $(this).parents('.person');
		$('.address', parent).toggle();
	});
});


// TESTIMONIALS: Add more photos
function addMoreLink(node){
	var label = $('#en').length ? 'Add more' : 'Ajout de photos';
	var link = '&nbsp;&nbsp;<span class="add_more">'+label+'</span>';
	$(node).append(link);
	$('.add_more', node).click(function(){
		$(this).hide();
		$(this).parent().next().show().next().show();
		if ($(this).parent().next().next().attr('id') != 'value_public_photo_10')
			addMoreLink($(this).parent().next().next());
	});
}
$(document).ready(function(){
	if ($('#testimonials #form').length || $('#parents_testimonials #form').length){
		$('#label_public_photo_02').hide();
		$('#value_public_photo_02').hide();
		$('#label_public_photo_03').hide();
		$('#value_public_photo_03').hide();
		$('#label_public_photo_04').hide();
		$('#value_public_photo_04').hide();
		$('#label_public_photo_05').hide();
		$('#value_public_photo_05').hide();
		$('#label_public_photo_06').hide();
		$('#value_public_photo_06').hide();
		$('#label_public_photo_07').hide();
		$('#value_public_photo_07').hide();
		$('#label_public_photo_08').hide();
		$('#value_public_photo_08').hide();
		$('#label_public_photo_09').hide();
		$('#value_public_photo_09').hide();
		$('#label_public_photo_10').hide();
		$('#value_public_photo_10').hide();
		addMoreLink('#value_public_photo_01');
	}
});
