var top = 0;
var h = 96;

$(document).ready(function() {
	
	
	
	$('#background').flash({
		swf:'swf/back_vid.swf',
		width:'100%',
		height:'100%',
		id:'back_vid'
	});
	
	
	$('a[class="interne"]').bind('click', function () {
		changeContent(this);
		return false;
	});

	
	$('#navig a').click(function() {
		document.getElementById('back_vid').pauseVid(); 
	});
	
	$('#zone_logo a').click(function() {
		document.getElementById('back_vid').playVid();
	});
	

	
	
	
	
	
	$('#navig dt').mouseover(function() {
		$(this).css({
			'background': 'url("images/transparence_rpt.png") repeat',
		});
	
		$('#navig dt').mouseout(function(){
			$(this).css({
				'background': 'none',
			});
		});
			
	});
	
	

	
	$('a').focus(function(){
		this.blur();
	})
	
	
});


function initGallery()
{

	$('#zone_content #works img.hover').bind('mouseover', function(){
		$('#zone_content #works .titre').html($(this).parent().find('div.job_titre').text());
		$('#zone_content #works .description').html($(this).parent().find('div.job_description').text());
	});
	$('#zone_content #works img.hover').bind('click', function() {
		$.ajax({
		   type: "GET",
		   url:	'inc/vimeo.php',
		   data: 'id=' + $(this).attr('title'),
		   success: function(msg){
		   		$('#zone_content #works #zone_haut').html(msg);
				$('#zone_content #works #zone_haut .back').css(
					'display','block'
				);
				
				// initialisation du lien back :
				initBackLink();
				
		   }
		 });
	});

	$('#zone_content #works img.hover').mouseover(function() {
		$(this).css({
			'margin-top' : '-96px',
		});
	});
	
	$('#zone_content #works img.hover').mouseout(function(){
		$(this).css({
			'margin-top':'0px',
		});
	});

	 
	
}

function initWorks()
{
	// initialisation de la gallerie des travaux :
	initGallery();
	
	// initialisation de top :
	top = 0;
	
	// initialisation des liens suivant précédant
	$('#zone_content #works a[class="previous"]').bind('click', function() {					
		// contrôle si il y a des travaux ou pa :
		if (top < 0)
		{
			$('#zone_content #works #job_container #scroll').animate({
				'top' : top + h
			}, function() {
				top = top + h;
			});	
		}
	});
	
	$('#zone_content #works a[class="next"]').bind('click', function() {
			
		// calcul de la différence de jobContainer et de scroll :
		var diff = $('#zone_content #works #job_container #scroll').height() - $('#zone_content #works #job_container').height();
	
		// contrôle si il y a des travaux ou pa :
		if (top > -diff)
		{
			$('#zone_content #works #job_container #scroll').animate({
				'top' : top - h
			}, function() {
				top = top - h;
			});	
		}
	});
}

function initBackLink()
{
	$('a[class="back"]').bind('click', function () {
		changeContent(this);
		return false;
	});

}

function changeContent(ref)
{
	$('#navig').find('dt').removeClass('active');
		
		if ($(ref).parent().parent().parent().attr('id') == 'navig') {
			
			$(ref).parent().addClass('active');
		}
		
	
		var url = $(ref).attr('href');
	
		
		// ajax request :
		$.ajax({
		   type: "GET",
		   url: url + '?redirect=false',
		   success: function(msg){
		     $('#zone_content').html(msg);
			 
		 	// initialisation des travaux :
			initWorks();	 
		   }
		 });
		 
	//	return false;
		
}



