//Pour arreter les setTimeout quand le contact à changer
var numero_instance_diapo = 0;
var disable_fadeout = 0;
var taille_block = 0;
var activer_animation = 0;

$(document).ready(function(){
	if($.support.svg == false || $.browser.msie == true){
		$('.svg').remove();
	}

	$('#central_content .button a').disableSelection().click(function(){
		$(this).parent().click();
		return false;
	});

	$('#central_content .button').hover(function(){
		disable_fadeout = 1;
		var os = $(this).offset();
		$('#bulle').css('left', os.left-60);
		$('#bulle').css('top', os.top-35);
		$('#bulle').fadeIn('fast');
		$('#bulle').text($(this).find('img').attr('alt'));
	},function(){
		disable_fadeout = 0;
		setTimeout('cacher_bulle();', 500);
	});

	$('#central_content #services').click(function(){
		activer_animation = 0;
		$('.button.select').removeClass('select');
		$('.button.animation').removeClass('animation');
		$(this).addClass('select');
		$.get('services.html', function(data){
			$('#central_content #contents #presentation').animate({
				width:770,
				height:305,
				'margin-top':35,
				'margin-right':40
			}, 200);
			$('#central_content #contents #presentation').html(data);
			diaporama(++numero_instance_diapo);
		}, 'html');
	});

	$('#central_content #clients').click(function(){
		activer_animation = 0;
		$('.button.select').removeClass('select');
		$('.button.animation').removeClass('animation');
		$(this).addClass('select');
		$.get('clients.html', function(data){
			$('#central_content #contents #presentation').animate({
				width:770,
				height:255,
				'margin-top':35,
				'margin-right':40
			}, 200);
			$('#central_content #contents #presentation').html(data);
			diaporama(++numero_instance_diapo);
		}, 'html');
	});

	$('#central_content #porfolio').click(function(){
		activer_animation = 0;
		$('.button.select').removeClass('select');
		$('.button.animation').removeClass('animation');
		$(this).addClass('select');
		$.get('portfolio.html', function(data){
			$('#central_content #contents #presentation').animate({
				width:890,
				height:380,
				'margin-top':15,
				'margin-right':20
			}, 200);
			$('#central_content #contents #presentation').html(data);
			initialiser_portfolio();
		}, 'html');
	});

	$('#central_content #curriculum').click(function(){
		activer_animation = 0;
		$('.button.select').removeClass('select');
		$('.button.animation').removeClass('animation');
		$(this).addClass('select');
		document.location = '/richard_deloge_2011.pdf';
	});

	$('#central_content #contact').click(function(){
		activer_animation = 0;
		$('.button.select').removeClass('select');
		$('.button.animation').removeClass('animation');
		$(this).addClass('select');
		$.get('contact.html', function(data){
			$('#central_content #contents #presentation').animate({
				width:550,
				height:270,
				'margin-top':35,
				'margin-right':40
			}, 200);
			$('#central_content #contents #presentation').html(data);
		}, 'html');
	});

	taille_block = $('#central_content').height();
	$(window).resize(centrer_site);
	centrer_site();

	activer_animation = 1;
	animation();
});

function animation(){
	if(activer_animation == 0)
		return;

	var btn = $('.button.animation');
	if(btn.length == 0)
		$('.button').first().addClass('animation');
	else if(btn.next().length == 0){
		btn.removeClass('animation');
		$('.button').first().addClass('animation');
	}
	else{
		btn.next().addClass('animation');
		btn.removeClass('animation');
	}

	setTimeout('animation();', 3000);
}

function centrer_site(){
	var H = (window.innerHeight - taille_block)*.45;
	$('#central_content').css('padding-top', H+'px');
}

function cacher_bulle(){
	if(disable_fadeout == 0){
		$('#bulle').fadeOut();
	}
	disable_fadeout = 1;
}

function diaporama(num_execution){
	if(numero_instance_diapo != num_execution || $('.diaporama').length == 0)
		return;

	var li = $('.diaporama li.display');
	if(li.length == 0)
		$('.diaporama li').first().addClass('display');
	else if(li.next().length == 0){
		li.removeClass('display');
		$('.diaporama li').first().addClass('display');
	}
	else{
		li.next().addClass('display');
		li.removeClass('display');
	}
	setTimeout('diaporama('+num_execution+');', 4000);
}

function initialiser_portfolio(){
	$('#selecteur img').attr('src', 'img/bullet_green.png');
	$('#selecteur img').click(function(){
		selection_item_portfolio($(this).attr('id'));
	});
	selection_item_portfolio('cetebat');
}

function selection_item_portfolio(id){
	$('#selecteur img').attr('src', 'img/bullet_green.png');
	$('#selecteur img#' + id).attr('src', 'img/bullet_white.png');
	$('#details > li').css('display', 'none');
	$('#details > li#desc-' + id).css('display', 'list-item');
	$('#captures > li').removeClass('display');
	$('#captures > li#capt-' + id).addClass('display');
	captures(++numero_instance_diapo);
}

function captures(num_execution){
	if(numero_instance_diapo != num_execution || $('#captures > li.display').length == 0)
		return;

	var li = $('#captures > li.display li.display');
	if(li.length == 0)
		$('#captures > li.display li').first().addClass('display');
	else if(li.next().length == 0){
		li.removeClass('display');
		$('#captures > li.display li').first().addClass('display');
	}
	else{
		li.next().addClass('display');
		li.removeClass('display');
	}
	setTimeout('captures('+num_execution+');', 4000);
}

