/*scroll des menus*/
$(function() {
		   
	var _height_site = $('#content').height()+300;
	$('.menu_right').css('height', _height_site+'px');	   
		   
		   
	$('.menu').click(function() {
		var _attribute = $(this).attr('id');
		/*$('html,body').animate({ scrollTop: $('.'+_attribute).offset().top }, 1000, "easeOutExpo");*/
		if($.browser.opera){$('html').animate({ scrollTop: $('.'+_attribute).offset().top }, 1200, 'easeInOutCirc');}
		else{$('html,body').animate({ scrollTop: $('.'+_attribute).offset().top }, 1200, 'easeInOutCirc');}
	});
 });
/*-------------------------*/

/*realisations*/
$(function() {
	$('.open_detail_rea').click(function() {							  
		if ($(this).next('.detail_rea').css('top') == '352px') {
			$('.detail_rea').animate({'top': '352px'}, 300);
			$('.open_detail_rea').css('background-image', 'url(/images/realisation_detail.png)');		
			$(this).css('background-image', 'url(/images/realisation_close_detail.png)');			
			$(this).next('.detail_rea').animate({'top': '1px'}, 300);
		}			
		else {
			$(this).css('background-image', 'url(/images/realisation_detail.png)');
			$(this).next('.detail_rea').animate({'top': '352px'}, 600);
		}
	});
	
    /*$(".realisation_vignette").hover(function(){       
		$(this).find('.title').stop().animate({opacity: 100}, {queue:false, duration:800});						 
    },
    function(){
		$(this).find('.title').stop().animate({opacity: 0}, {queue:false, duration:450});	
    });*/
	
	// on met à jour la hauteur des actus
	var div_scroll_annonce = $('#div_scroll_actu');
	if(div_scroll_annonce.length > 0) {
		var max_height = 0;
		
		for(var i=0;i<max_actu; i++) {
			max_height = Math.max(max_height, $('#td_actu_'+i).height() );
		}

		for(var i=0;i<max_actu; i++) {
			$('#td_actu_'+i).height(max_height - 10);
		}
		
		$('#div_scroll_actu').height(max_height+20);
	}
	
	//on met à jour la largeur de la div 
	resize_div_full_width();
	$('.jScrollPaneContainer').width($('.content').width());
	resizeScroller2();
	
	
	// on masque les scrollbar qu'il faut
	$('.hide_scroll').children('.jScrollPaneContainer').css('display','none')
	
	// on récupère toutes les lignes d'aperçu de réalisation et on attache l'événement
	$('.ligne_realisation_apercu').click(function() {
		var id = $(this).attr('id');
		display_realisation(id.replace(/ligne_realisation_apercu_/,''));
	});	
 });


$(window).resize(function() {
	resize_div_full_width();
	resizeScroller2();
});

$(window).scroll(function(){
	if( getScrollHeight() > 220){
		var marginTop = parseInt( getScrollHeight() - 220 );
		
		$('#menu_content').css('margin-top', marginTop );
	}
});

function getScrollHeight(){
	 var h = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;
	 return h ? h : 0;
}



/*-------------------------*/


function display_realisation(id_realisation) {
	// on commence par masque le detail actuel
	$(".ligne_realisation_detail:visible").children('.jScrollPaneContainer').slideUp('slow', function() {
		var id = $(this).parent().attr('id');
		$("#"+(id.replace(/ligne_realisation_detail/,'ligne_realisation_apercu'))+":hidden").slideDown('slow');
	});
	
	// on affiche le nouveau detail
	$("#ligne_realisation_apercu_"+id_realisation+":visible").slideUp('slow', function() {
		$("#ligne_realisation_detail_"+id_realisation).children('.jScrollPaneContainer:hidden').slideDown('slow');
	});
}

function resize_div_full_width() {
	$('#content').width($('body').width()-$('#menu_left').width()-20);
	/*$('body').height($('#content').height()+20);*/
}


function PopupCentrer(page,name,largeur,hauteur,options) 
{
    var top=(screen.height-hauteur)/2;
    var left=(screen.width-largeur)/2;
    window.open(page,name,"top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}
    
function openShadowbox( _page, _width, _height, _player) {

	if(typeof(_width) == 'undefined'){
		_width = 950;
	}
	if(typeof(_height) == 'undefined'){
		_height = 800;
	}		
	if(typeof(_player) == 'undefined'){
		_player = 'iframe';
	}	
    Shadowbox.open({player:_player, content:_page, height:_height, width:_width, options:{fadeDuration:0.1, resizeDuration:0.1, animSequence:"sync"}});
}

function closeShadowbox( _goto ) {
    Shadowbox.close();
    
    if(typeof(_goto) != 'undefined')
        document.location.replace(_goto);
}

function is_mail(mail){
	var filter_email=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	return filter_email.test(mail);
}

var t_res;
function preload( t_img ) 
{
	t_res = new Array()
	for(var i=0;i<t_img.length;i++)
	{
		var el = new Image();
		el.src = t_img[i];
		t_res.push( el );
	}
}

function nqToolTip() {
	xOffset = 5;
	yOffset = 5;
	
	Dom.getElementsBy(function(e){return e.className=='screenshot';}, 'a', document.body, function(e) {
		YAHOO.util.Event.addListener(e, "mouseover", function(ev) {
			var p = document.createElement('p');
			p.id = 'screenshot';
			p.innerHTML += "<img src='"+ e.rel +"' />";
			document.body.appendChild(p);
			Dom.setStyle(p,'top',(YAHOO.util.Event.getPageY(ev) + xOffset) + "px");
			Dom.setStyle(p,'left',(YAHOO.util.Event.getPageX(ev) + yOffset) + "px");
			Dom.setStyle(p,'display','block');
			});
		YAHOO.util.Event.addListener(e, "mouseout", function(ev) {
			document.body.removeChild(Dom.get('screenshot'));
			});
		YAHOO.util.Event.addListener(e, "mousemove", function(ev) {
			Dom.setStyle('screenshot','top',(YAHOO.util.Event.getPageY(ev) + xOffset) + "px");
			Dom.setStyle('screenshot','left',(YAHOO.util.Event.getPageX(ev) + yOffset) + "px");
			}); 
	});
}



/*$(function() {
	$("#slider").slider({
   	change: function(event, ui) {
	   $('#div_scroll_actu').scrollTo( $('#td_actu_'+Math.round((ui.value/100)*max_actu)), 800);
	}
});
});*/


/*
----------------------
Préchargement des imaages
monImgRea0
imagePreload_0
----------------------
*/
function preloadImages()
{
	var t_images = $("#ligne_realisation_0").find("img");
	//alert(t_images.length);
	var comp;
	var i = 0;
	var j = 0;
	for( comp=0 ; comp<t_images.length ; comp++ )
	{
		$("#imagePreload_"+j+"Image"+i).fadeOut(400);
		$("#monImgRea"+j+"Image"+i).fadeIn(800);
		
		if( comp == 2 )
		{ 
			i = 0;
			j++;
		}
		i++;
	}
}



/*********************************************************** fleche hover réalisation et actualite */

$(document).ready(function(){
						   
	
		$(".menubisrea").hover(function(){
			 
			 
			  $(".fleche").animate({ 
				left: '270px'
			  }, 500 );

		}, function(){
			  $(".fleche").animate({ 
				left: '250px'
			  }, 500 );
	
		})
		
		$(".menubisactu").hover(function(){
			 
			 
			  $(".fleche2").animate({ 
				left: '270px'
			  }, 500 );

		}, function(){
			  $(".fleche2").animate({ 
				left: '250px'
			  }, 500 );
	
		})

		
});





















