$(document).ready(function() {
	// Navigation
	$('.subnavigation').hide();


	$("#navigation .navigation").hover(function() {
		$('.subnavigation').hide();
		$(this).parent().find('.subnavigation').show();
		$('#navigation .active').removeClass('active');
		$(this).parent().addClass('active');
	});

	$("#navigation .subnavigation").mouseleave(function() {
		$('.subnavigation').hide();
		$('#navigation .active').removeClass('active');
	});
	
	var overlay_top = 0;
	$('dfn').jHelperTip({
		trigger  : 'hover',
		source   : 'attribute',
		attrName : 'title',
		aC       : '#dfn',
		leftOff  : -100,
		topOff   : 10
	});

	$("a._blank").attr('target', '_blank'); // Ajoute _blank sur les lien

	$("#increase").click(function() {		// Increase Font Size
		var currentFontSize = $('body').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum*1.2;
		if(newFontSize > 20) {
			newFontSize = 12;
		}
		$('body').css('font-size', newFontSize);
		return false;
	});
/*
	$("#print").click(function() {
		window.print();
		pageTracker._trackPageview('/toolbar/print');	// Track Analytics
		return false;
	});
*/
	// Ajout auto du flash
	if($('#illustration').attr('class') != '') {
		$('#illustration embed').css('zIndex', 800);
		if($('#illustration').attr('width')) {
			width = $('#illustration').attr('width');
		} else {
			width = 373;
		}
		if($('#illustration').attr('height')) {
			height = $('#illustration').attr('height');
		} else {
			height = 305;
		}

		$('#illustration').flash({
			swf:'/swf/'+$('#illustration').attr('class')+'.swf',
			width:width,
			height:height,
			wmode:'transparent'});
	}
	$('#partners').flash({
		swf:'/swf/partners.swf',
		width:200,
		height:180,
		wmode:'transparent'
	});

	// Ajoute le footer à la balise .text
	if($(".text").length > 0) {
		$(".text_header").show();
		$(".text_footer").show();
		$(".addthis_button").show();
		$(".text_header").prependTo(".text");
		$(".text_footer").appendTo(".text");
		$(".addthis_button").appendTo(".text");
	}
	// On enlève les bordures pour les inoput a cause d'IE
	if($("input[type=checkbox], input[type=radio]").length > 0) {
		$("input[type=checkbox], input[type=radio]").css('border', 'none');
	}
	
	// Accès clients
	if($("a[rel=#acces-client]").length > 0) {
		$('#acces-client').html('<iframe src="http://extranet.generation-net.org/?f=" width="500" height="150" style="border:none; overflow:hidden;" scrolling="no" />');
		$("a[rel=#acces-client]").overlay({finish:{left:0,top:200}, container:'#wrapper'});
	}



	$('#humans li').jHelperTip({
		trigger  : 'hover',
		source   : 'attribute',
		attrName : 'title',
		aC       : '#human'
	});

	var currentHuman = null;

	$('#gilles').click(function() {
		openHuman('gilles', 200, 170);
	});
	$('#guillaume').click(function() {
		openHuman('guillaume', 200, 260);
	});
	$('#anne').click(function() {
		openHuman('anne', 240, 380);
	});
	$('#albin').click(function() {
		openHuman('albin', 150, 460);
	});
	$('#romain').click(function() {
		openHuman('romain', 200, 120);
	});
	$('#maxime').click(function() {
		openHuman('maxime', 170, 220);
	});
	$('#elodie').click(function() {
		openHuman('elodie', 170, 320);
	});
	$('#lorraine').click(function() {
		openHuman('lorraine', 160, 420);
	});

	function openHuman(name, bottom, left) {
		if(currentHuman != name) {
			$('#human-detail').hide('slow', function(){
				currentHuman = name;
				openHuman(name, bottom, left);
			});
			return;
		}
		if($('#human-detail').css('display') == 'block') {
			$('#human-detail').hide('slow');
			return;
		}
		currentHuman = name;
		$('#human-detail').html('<img src="/agence-web-nantes/'+name+'.png" alt="'+name+'" />');
		$('#human-detail').show('slow');
		$('#human-detail').css('bottom', bottom);
		$('#human-detail').css('left', left);
	}
	
	// Préchargement des images
	var html	= '<img src="/agence-web-nantes/gilles.png" alt="" width="1" />'
				+ '<img src="/agence-web-nantes/guillaume.png" alt="" width="1" />'
				+ '<img src="/agence-web-nantes/anne.png" alt="" width="1" />'
				+ '<img src="/agence-web-nantes/albin.png" alt="" width="1" />'
				+ '<img src="/agence-web-nantes/romain.png" alt="" width="1" />'
				+ '<img src="/agence-web-nantes/maxime.png" alt="" width="1" />'
				+ '<img src="/agence-web-nantes/elodie.png" alt="" width="1" />'
				+ '<img src="/agence-web-nantes/lorraine.png" alt="" width="1" />';

	$('#human-detail').html(html);
	
	$('#human-detail').click(function(){
		$('#human-detail').hide('slow');
	});
});
