// JavaScript Document

	var new_margin = 0;
	var margin_news = 4;
	var largeur_news;

	function initMenu(){
		
		/*
		* Gestion des HOVER
		
		$('#menu .bt_home').hover(function(){
		},function(){
			$('#menu .bt_home').toggleClass('on');
		});*/
		
		$('#bt_home').hover(function(){
			if(!$(this).hasClass('keepon')){
				$(this).removeClass();
				$(this).addClass('menuItemHomeOn');
			}
		},function(){
			if(!$(this).hasClass('keepon')){
				$(this).removeClass();
				$(this).addClass('menuItemHome');
			}
		});
		
		$('#menu .menuItem').hover(function(){
			var x = $(this).position().left;
			var y = $(this).position().top+35;
			if(!$(this).hasClass('actif')){
				$(this).toggleClass('li_on');
			}
			$(this).find('ul').css('display','block');
			$(this).find('ul').css('left',x+'px');
			$(this).find('ul').css('top',y+'px');
		},function(){
			if(!$(this).hasClass('actif')){
				$(this).toggleClass('li_on');
			}
			$(this).find('ul').css('display','none');
		});
		$('.ssmenu > li').hover(function(){
			if(!$(this).hasClass('inactif')){
				$(this).toggleClass('ssmenu_on');
				$(this).find('span').toggleClass('ssmenu_on');
			}
		},function(){
			if(!$(this).hasClass('inactif')){
				$(this).toggleClass('ssmenu_on');
				$(this).find('span').toggleClass('ssmenu_on');
			}
		});
		
		/*
		* Gestion des CLICKS
		
		$('#menu > .menuItem').click(function(){
			window.open($(this).find('a').attr('href'),'_self');
		});*/
		$('.ssmenu > li:has(a)').click(function(){
			window.open($(this).find('a').attr('href'),'_self');
		});
		$('.ssmenu > li').click(function(){
		});
		
		defileNews();
		
		/*
		* rollovers
		*/
		$('.bt_candidature').hover(function(){
			$(this).attr('src','images/envoyerlacandidatureON.jpg');
		},function(){
			$(this).attr('src','images/envoyerlacandidatureOFF.jpg');					  
		});
		$('.bt_postuler').hover(function(){
			$(this).attr('src','images/postuylerON.jpg');
		},function(){
			$(this).attr('src','images/postuylerOFF.jpg');					  
		});
		$('.bt_toutes_annonces').hover(function(){
			$(this).attr('src','images/touteslesannoncesON.jpg');
		},function(){
			$(this).attr('src','images/touteslesannoncesOFF.jpg');					  
		});
		$('.bt_nous_contacter').hover(function(){
			$(this).attr('src','images/nous-contacter_on.gif');
		},function(){
			$(this).attr('src','images/nous-contacter.gif');					  
		});
		$('.bt_voir_annonces').hover(function(){
			$(this).attr('src','images/voirtouteslesannoncesON.png');
		},function(){
			$(this).attr('src','images/voirtouteslesannoncesOFF.png');					  
		});
		
	}
	
	function startAnim(){
		bougeNews();
	}
	
	function bougeNews(){
		new_margin-=1;
		if(new_margin<(-1*largeur_news)){
			new_margin = 0;
		}
		$('#original').css('margin-left',new_margin+'px');
		$('#doublon').css('margin-left',new_margin+largeur_news+'px');
		
		setTimeout("bougeNews()",25);
	}
	
	function defileNews(){
		
		largeur_news = $('#original').width();
		if(largeur_news < $('#defile .news_container').width()){
			$('#original').append($('#original').html());
			largeur_news = $('#original').width();
		}
		
		//duplication des news
		var news_html = $('.news_container > p').html();
		$('.news_container').append('<p id="doublon">'+news_html+'</p>');
		$('.news_container > p').css('margin-left',margin_news+'px')
		$('#doublon').css('margin-left',largeur_news+'px');
		
		var position_container = $('.news_container').offset();
		startAnim();
	}
	
	function openCredits() {
		var largeur = hauteur = 227;
		var top=((screen.height-hauteur)/2)-80;
		var left=(screen.width-largeur)/2;
		window.open('credits.html',"credits","top="+top+",left="+left+",width="+largeur+",height="+hauteur+",toolbar=no,directories=no,status=no,scrollbars=yes,resize=no,menubar=no,location=no");
	}
	
	
	$(document).ready(initMenu);