(function($) {
	$(function() {
		// Tweet button
		$('#twitter').bind('click', function(e) {
			e.preventDefault();
			e.stopPropagation();
			window.twttr = window.twttr || {};
			var D = 550, A = 450, C = screen.height, B = screen.width, H = Math.round((B / 2) - (D / 2)), G = 0, F = document, E;
			if (C > A) { G = Math.round((C / 2) - (A / 2)) }
			window.twttr.shareWin = window.open('http://twitter.com/share', '', 'left=' + H + ',top=' + G + ',width=' + D + ',height=' + A + ',personalbar=0,toolbar=0,scrollbars=1,resizable=1');
			E = F.createElement('script');
			E.src = 'http://platform.twitter.com/bookmarklets/share.js?v=1';
			F.getElementsByTagName('head')[0].appendChild(E);
		}).attr('title', 'Partager sur twitter');										   
		// Newsletter
		$('#newsletter form').bind('submit', function(e) {
			e.preventDefault();
			e.stopPropagation();
			var mail = $(this).find('input[type="text"]').val();										  
			$.get('newsletter.php?mail=' + encodeURIComponent(mail), function(data) {
			    alert(data);
			}).error(function() {
				alert("Une erreur s'est produite, merci de réessayer ulterieurement.");
			});
		});
		// Video
		$('a.popupVideo').colorbox({
			'innerWidth' : 800,
			'innerHeight' : 600,
			'iframe' : true,
			'fixed' : true
		});
		// Magazine
		$('a.popupMagazine').colorbox({
			'innerWidth' : 1200,
			'innerHeight' : 800,
			'iframe' : true,
			'title' : '',
			'fixed' : true
		});		
		// Galeries
		$('.article_photos a').colorbox({
			'maxWidth' : '100%',
			'maxHeight' : '100%',
			'rel' : 'gallerie_article',
			'current' : '',
			'fixed' : true
		});
		// Css3 columns
		if ($('.colonnes').size() > 0) {
			new CSS3MultiColumn();
		}
		// Bonnes adresses
		$('a.onglet').bind('click', function(e) {
			e.preventDefault();
			e.stopPropagation();
			$('a.onglet').not(this).removeClass('onglet_current');
			$('div.adresse').hide().filter('.adresseType' + $(this).addClass('onglet_current').data('type')).show();
		}).first().trigger('click');
		$('.toggleableInfos').next('div').bind('click', function() {
			// Variables
			var button = $(this);
			var infos = button.prev('.toggleableInfos');
			var height = infos.css('height');
			// Si 32px, on remet la taille normale
			if (height === '32px') {
				infos.css({'height' : 'auto'});
				button.text('Moins d\'infos [-]');
			}
			// Sinon, on met à 32
			else {
				infos.css({'height' : '32px'});
				button.text('Plus d\'infos [+]');
			}
		});
	});
}(jQuery))
