
debug_layer = false;
layer_animation = true;
layer_taille_fixe = false;
layer_a_gauche = false;
layer_en_bas = false;


jQuery(document).ready(function(){

	$('img').attr('title','').attr('alt','');
		
	$("a.open").click(function(){
		var this_element = '#' + $(this).attr('rel');
		
		if(content_sous_menu_open==false){
			content_sous_menu_open = true;
			$(this_element).slideDown('slow',function(){
				// SILENCE IS MINE
			});
		}
		else{
			//alert("iccciii");
			//alert( $(this).attr('id') );
			
			if( $(this).attr('id')=='link-7' || $(this).attr('id')=='link-102' ){
			
				if( $(this).attr('id')=='link-7' ){
					 document.location.href = "http://www.nwagency.fr/do/conseil-branding/";
					 return false;
				}
				
				if( $(this).attr('id')=='link-102' ){
					document.location.href="http://www.nwagency.fr/be-2/team-nwa/";
					return false;
				}
				
			}
			
			
			$(this_element).stop();
			$('.content-sous-menu').hide();
			$(this_element).show();
		}
		
		return false;
	});
	
	$('#list-event li').hover(function(){
		$('div, a, p',this).css({
			'color':'#969696',
			'cursor':'pointer'
		});
	}, function(){
		$('div, a, p',this).css({
			'color':'#000000',
			'pointer':'normal'
		});
		return false;
	});
	
	
	$('#list-event li').click(function(){
		var link_news = $('.link-news',this).attr('href');
		document.location.href = link_news;
		return false;
	});
	
});

	// INITIALISATION
	if(debug_layer == false) document.getElementById('layer').style.display = 'none';
	
	function mouseCoords(event)
	{
		ev = event;
		if(event.pageX || event.pageY)
		{
			return {x:event.pageX, y:event.pageY}
		}
		return {x:ev.clientX + document.body.scrollLeft - document.body.clientLeft, y:ev.clientY + document.body.scrollTop  - document.body.clientTop}
	}

	function mapOver(event)
	{
		if (event.target)
		{
			var target = event.target
		}
		else if (event.srcElement)
		{
			var target = event.srcElement
		}
		document.getElementById('layer').style.display = 'block';
		
		return false;
	}

	function mouseMove(event){
		var mousePos = mouseCoords(event);
		drag = document.getElementById('layer');

		if (drag)
		{
			m_left = 0;
			m_top = 0;
			
			if( window.getComputedStyle ){
				var m_left = mousePos.x - (getComputedStyle(drag, null).getPropertyValue("width").split("p")[0] / 2)
				var m_top = mousePos.y - (getComputedStyle(drag, null).getPropertyValue("height").split("p")[0])
				
			}
			else if( drag.currentStyle){
				var m_left = mousePos.x - (drag.currentStyle["width"].split("p")[0] / 2)
				var m_top = mousePos.y - (drag.currentStyle["height"].split("p")[0])
				drag.style.position = 'fixed';
			}		
			
			//alert(document.body.clientWidth); // 1263
			
			// WIDTH LAYER : 228
			
			if(layer_taille_fixe==true){
				/*** LE LAYER A UNE TAILLE FIXE ***/
				if(layer_a_gauche == true) m_left = m_left + 168;
				else m_left = m_left - 128;
				// NON m_left = m_left + document.body.clientWidth - (document.body.clientWidth/1.3);
				m_top = m_top + 170;	
			}
			else{
				//alert($('#layer').width());
				if(layer_a_gauche == true) m_left = m_left - $('#layer').width() + 140;
				else m_left = m_left - $('#layer').width() + 100;
				
				
				if(layer_en_bas == true){
				
					$('#layer').css({
						marginTop: '-' + ( $('#layer').height() - 50 ) +'px',
						backgroundPosition: '0px 0px',
						paddingLeft: '0px'
					});
					
					$('img#fleche-layer').css('top', '366px');
					document.getElementById('fleche-layer').style.top = ( $('#layer').height() - 50 ) +'px';
					
				}
				else if(layer_a_gauche == false){

					
					$('img#fleche-layer').css('top', '23px;');
					document.getElementById('fleche-layer').style.top = '23px';
				
				}
				else{
				
					$('img#fleche-layer').css('top', '23px;');
					document.getElementById('fleche-layer').style.top = '23px';
				
				}
				
				// NON m_left = m_left - $('#layer').width() + document.body.clientWidth - (document.body.clientWidth/1.001);
				m_top = m_top +  $('#layer').height() - 37;
			}
			
			//alert($('#layer').height() - 153);
			
			// DEBUG
			if(debug_layer == true) $('#text-layer').html('LEFT : ' + m_left + ' / TOP : ' + m_top);
			
			$('#layer').css('top',m_top);
			$('#layer').css('left',m_left);
			
			return false;
		}

		return false;
	}

	function mapOut(event){
		if(debug_layer == false) document.getElementById('layer').style.display = 'none';
		return false;
	}

	//var li = document.getElementsByTagName('li');
	var li = document.getElementsByClassName('puzzle');
	
	for (i=0; i<li.length ; i++)
	{
		li_class_name = li[i].getAttribute('class');
		
		addEvent(li[i], 'mouseover', 'onmouseover', 'mapOver');
		addEvent(li[i], 'mouseout', 'onmouseout', 'mapOut');
	}

	addEvent(document, "mousemove", "onmousemove", "mouseMove")
	
	
	function changement_position_layer(element){
		if( $(element).attr('rel')=='left' ){
			
			// ON FAIT L'ANIMATION POUR ALLER A GAUCHE
			
			$('#layer').css({
				marginTop: '0px',
				marginLeft: '228px',
				backgroundPosition: '40px 0px',
				paddingLeft: '40px'
			});
			
			$("#fleche-layer").hide();
			$("#fleche-layer2").show();
			
			layer_a_gauche = true;
			layer_en_bas = false;
			
		}
		else if( $(element).attr('rel')=='bottom' ){
			
			//alert('iaaa');
			// ON FAIT L'ANIMATION POUR ALLER A GAUCHE
			
			$('#layer').css({
				marginTop: '-' + $('#layer').height() + 'px',
				marginLeft: '0px',
				backgroundPosition: '0px 0px',
				paddingLeft: '0px'
			});
			
			$("#fleche-layer2").hide();
			$("#fleche-layer").show();
			
			layer_a_gauche = false;
			layer_en_bas = true;
			
		}
		else{
			// ON FAIT L'ANIMATION POUR ALLER A DROITE
			
			$('#layer').css({
				marginTop: '0px',
				marginLeft: '0px',
				backgroundPosition: '0px 0px',
				paddingLeft: '0px'
			});
			
			$("#fleche-layer2").hide();
			$("#fleche-layer").show();
			
			layer_a_gauche = false;
			layer_en_bas = false;
			
		}
	}
	
jQuery(document).ready(function(){

	$(".puzzle").hover(function(){		
		if( debug_layer == true) return false
		
		var this_puzzle = $(this);
		var this_puzzle_h2 = $('h2',this);
		var this_puzzle_div = $('div',this);
		
		if( layer_animation == true ){
		
			$('#layer').stop();
			
			changement_position_layer(this_puzzle);
			
			$('#layer').animate({ 'height':($(this_puzzle_div).height() + $(this_puzzle_h2).height()) + 30 }, "fast", function(){
				$('#title-layer').html($(this_puzzle_h2).html());
				$('#text-layer').html($(this_puzzle_div).html());
				
			});
			
		}
		else{
		
			// PAS D'ANIMATION DONC A FAIRE
			
			changement_position_layer(this_puzzle);
			
			$('#title-layer').html($(this_puzzle_h2).html());
			$('#text-layer').html($(this_puzzle_div).html());
		}
		
		
		return false;
	});
	
});	
