

function view_resize(img){
	
	if($('#galerie-image').css('display') == 'none'){
	$('#galerie-image').css({ display: 'block' });
	$('#galerie-image-fond').css({ display: 'block' });
	}
	else {
	size_screen();
	
	$.post("/index.php",
	   { 
		module: 'admin',
		section: 'images_gest',
		ajax: true,
		display_resize: true,
		image: img,
		width: width,
		height: height
		},
	   function(data){
			$('body').append(data);
			resize();
	   }
	 );
	 }
}
	
	var image_mini;
	var top;
	var left;
	var width_c;
	var height_c;
	var rate;

function view_resize_prev(img, wg, wm) {
	var scrollleft = document.getElementById('galerie-image-cadre').scrollLeft;
	var scrolltop = document.getElementById('galerie-image-cadre').scrollTop;

	
	top = $("#cadre").position().top + scrolltop;
	left = $("#cadre").position().left + scrollleft;
	width_c = $("#cadre").width();
	height_c = $("#cadre").height();
	rate = wg/wm;
	
	image_mini = '/admin/images_gest.php?resize=true&image='+img+'&top='+top*rate+'&left='+left*rate+'&width_red='+width_c*rate+'&height_red='+height_c*rate ;
	
	$('#preview_mini').empty();
	$('#preview_mini').css({ display: 'block' });
	$('#preview_mini').css({ background: 'url('+image_mini+')'});
}

function valid_resize() {
	$("#img_mini2").attr("src",image_mini);
	$('#galerie-image').css({ display: 'none' });
	$('#galerie-image-fond').css({ display: 'none' });
	$("#top").attr('value', top*rate);
	$("#left").attr('value', left*rate)
	$("#width_red").attr('value', width_c*rate)
	$("#height_red").attr('value', height_c*rate)
	
}

function resize(){
	
    $('#cadre').resizable({
			containment: '#galerie-image-cadre',
			aspectRatio: 200/150,
			minHeight: 150,
			minWidth: 200
		});
	$("#cadre").draggable({ 
			containment: '#galerie-image-cadre', 
			scroll: false 
		});
	
	$("#preview_mini").draggable({ 
			containment: '#galerie-image-cadre', 
			scroll: false 
		});
}

function color_resize() {
	var color = document.getElementById('color_resize').value;
	$('#cadre').css({ border: color + ' 2px solid' });
}


// Galerie d'image

function resize_down(widthi, heighti) {

	$('#agrandir').css( 'display', 'inline' );
	$('#reduire').css( 'display', 'none' );
	
	$('#image').css({ width: widthi, height: heighti });
	
	margin_left = -(widthi/2);
	
	$('#galerie-image-cadre').css( 'overflow', 'hidden');
	$('#galerie-image-cadre').animate({height: heighti , width: widthi});
	
	heighti = heighti + 35;
	
	$('#galerie-image').animate({ height: heighti , width: widthi, marginLeft: margin_left});

}

// agrandir
function resize_up(widthi, heighti) {

	size_screen();
	
	$('#reduire').css('display', 'inline' );
	$('#agrandir').css('display', 'none' );

	$('#image').css({ width: widthi, height: heighti });
	
	if( widthi < width - 120)
	{
		width_img = widthi + 20;
	}
	else
	{
		width_img = width - 120;
	}
	
	if( heighti < height - 120)
	{
		height_img = heighti + 20;
	}
	else
	{
		height_img = height - 80;
	}
	
	margin_left = -(width_img/2);
	
	$('#galerie-image').animate({ width: width_img, height: height_img, marginLeft: margin_left}, 500);
	
	cadre_height = height_img - 35;
	
	$('#galerie-image-cadre').css( 'overflow', 'scroll');
	$('#galerie-image-cadre').animate({ height: cadre_height , width: '100%'}, 500);


}

function view_image(mode, image, refresh) {
	
	size_screen();
	
		$.post("/index.php", {
							module: 'galerie', 
							section: 'view_image',
							ajax: true,
							mode: mode,
							image: image,
							height: height,
							width: width
						},
						function(data){ 
						
								if( refresh == 1) {
									$('#fond-galerie-image').remove();
									$('#galerie-image').remove();
								}
								
								$('body').prepend(data);

							}
			);
 
}



function fermer_image() {
	 $('#fond-galerie-image').remove();
	$('#galerie-image').remove();
}

function open_cat(cat_id, action) {
	
	var action;
	
	$('#menu-li-cat-'+cat_id).slideToggle('fast', function(){
  			
		if( $('#menu-li-cat-'+cat_id).css('display') == 'block')
		{
			action = 'open';
		}
		else
		{
			action = 'close';
		}
		
		$.post("/index.php", {
								module: 'site', 
								ajax: true,
								open_cat: true,
								cat_id: cat_id,
								action: action
							}

		);
 });
	

 
}

function resize_news(news, height) {
	
	if( $('#news-'+news).css('height') == height+'px')
	{
		var height_text = $('#news-text-'+news).css('height');
		
		 $('#news-'+news).animate({ 
       		height: height_text
      	}, 750 );
		
		$('#view-next-'+news).empty();
		$('#view-next-'+news).append("Réduire");
	}
	else
	{ 
		 $('#news-'+news).animate({ 
       		height: height
      	}, 750 );
		
		$('#view-next-'+news).empty();
		$('#view-next-'+news).append("Voir la suite");
	}
	
	
}

function size_news() {
	
	 $(".news").each(function(){
	 
		var news = $(this);
		var news_text = $(this).children('.news-text');
		var news_resize = $(this).children('.news-resize');
		
		var height_news = $(news).height();
		var height_news_text = $(news_text).height();
		
		
		if( height_news_text < height_news )
		{
			$(news).css('height', height_news_text+'px')
			$(news_resize).css('display','none')
		}
	 
 	});
	
	
}

function size_screen(){

	if( typeof( window.innerWidth ) == 'number' ) {
	  width = window.innerWidth;
	  height = window.innerHeight;
	  }
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	  width = document.documentElement.clientWidth;
	  height = document.documentElement.clientHeight;
	  }
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	  width = document.body.clientWidth;
	  height = document.body.clientHeight;
	  }
	else {
	  width = 800;
	  height = 600;
	  }
}

//option du visualisateur de description
var id_desc = 0;
var time = 10000;

function change_desc(id) {
	
	if(id == undefined)
	var id = id_desc+1;
	if(id >=5)
	var id = 0;
	
	var nom = new Array('location', 'infogerance', 'garantie', 'professionnel', 'evolutif');
	var couleur = new Array('vio', 'ble', 'rou', 'ora', 'ver');
	var top = new Array(94, 95, 102, 105, 100 );
	var right = new Array(222, 215, 212, 220, 225 );
	
	if( id_desc == id)
	return false;
	$(".ref").fadeOut("normal",function(){$(".ref[id!=reflect-head-"+couleur[id]+"]").remove();});
	$("#spyd-head").append('<div id="reflect-head-'+couleur[id]+'" class="ref" style="display: none;"></div>');
	$("#spyd-head").animate({ top: top[id]+"px", right: right[id]+"px"}, 'normal');
	$(".ref").fadeIn("normal");
	$(".accueil-icons a").css('display', 'none');
	$("#desc-"+nom[id]+'').css('left', '700px');
	$(".cadre-acc-h-t:visible").animate({ left: "-560px"}, 'slow', function() {$('.cadre-acc-h-t:visible:not(#desc-'+nom[id]+')').css('display', 'none')})
	$("#desc-"+nom[id]+'').css('display', 'block').animate({ left: "0px"}, 'slow');
	$('.titre-acc:visible').animate({ width: "0px"}, 'slow', function() {$('.titre-acc:visible ').css('display', 'none'); $(".accueil-icons a").css('display', 'block');})
	$('#titre-acc-fond-'+couleur[id]+'').animate({ width: "640px"}, 'slow').css('display', 'block');
	
	
	id_desc = id;
	
	return false;
}

function lecture_desc() {
	interval = setInterval( "change_desc()", time );
	$("#acc-lecture").attr('id', 'acc-lecture-on'); 
	$("#acc-pause-on").attr('id', 'acc-pause'); 
}

function pause_desc() {
	clearInterval(interval);
	$("#acc-lecture-on").attr('id', 'acc-lecture'); 
	$("#acc-pause").attr('id', 'acc-pause-on'); 
}

$(function(){ 
	
	// Ouverture des aides
	$(".form-noir-explain-button").click( function() { $(this).next(".form-noir-explain").slideToggle("speed");});
	$("#h3-icon-help").click( function() { $(".form-noir-explain").slideToggle("speed");});
	
	$(".open-cat").css('display', 'none');
	
	size_news();
	
	$("#spyd-head").css({ top: "94px", right: "222px"}).append('<div id="reflect-head-vio" class="ref"></div>')

	/*
	$(".accueil-icons").mouseout(function(){ $("#spyd-head").css({ top: "100px", right: "220px"}).empty() } );
	$("#accueil-professionnel").mouseover(function(){ $("#spyd-head").css({ top: "105px", right: "220px"}).append('<div id="reflect-head-ora"></div>') } );
	$("#accueil-garantie").mouseover(function(){ $("#spyd-head").css({ top: "102px", right: "212px"}).append('<div id="reflect-head-rou"></div>') } );
	$("#accueil-infogerance").mouseover(function(){ $("#spyd-head").css({ top: "95px", right: "215px"}).append('<div id="reflect-head-ver"></div>') } );
	$("#accueil-location").mouseover(function(){ $("#spyd-head").css({ top: "94px", right: "222px"}).append('<div id="reflect-head-vio"></div>') } );
	$("#accueil-evolutif").mouseover(function(){ $("#spyd-head").css({ top: "100px", right: "225px"}).append('<div id="reflect-head-ble"></div>') } );
*/

	$("#accueil-location a").click(function(){ change_desc(0) }); 
	$("#accueil-infogerance a").click(function(){ change_desc(1) }); 
	$("#accueil-garantie a").click(function(){ change_desc(2) }); 
	$("#accueil-professionnel a").click(function(){ change_desc(3) }); 
	$("#accueil-evolutif a").click(function(){ change_desc(4) }); 
	
	$(".accueil-icons a").click(function(){ pause_desc() });
	
	lecture_desc();

	
}); 
 

