/******************** JAVASCRIPT **************************/

//---- FONCTION DE DIMENSIONNEMENT DES DIV
function HideAll(){
	$('CACHE').hide();
	for (i=1;i<=4;i++){
		$('FENETRE'+i).hide();
	}
}
//---- REDIMMENSION DES DIV CONTENEURS
function DimensionneDiv(principal) {
	var Hauteur = document.body.clientHeight;
	/* Redimension des DIV */
	if ( principal==1 ) $('PRINCIPAL').style.height = (Hauteur - $('PIEDDEPAGE').getHeight() - $('ENTETE').getHeight() - 10 ) + 'px';
	//$('MENU2').style.height = (Hauteur - $('PIEDDEPAGE').getHeight() - $('MENU2').offsetTop) + 'px';
	//$('FENETRE4').style.width = $('PRINCIPAL').getWidth() + 'px';
	//$('FENETRE4').style.marginLeft = '-' + ($('PRINCIPAL').getWidth() / 2) + 'px';
	$('CACHE').style.height = '100%';
	$('CACHE').style.width = '100%';
	$('PIEDDEPAGE').style.top = (Hauteur - $('PIEDDEPAGE').getHeight()) + 'px';
	/* Positionnement INFOS */
	if ($('INFOS')) $('INFOS').style.top = (Hauteur - 140) + 'px';
	//-- GALERIE 
	if ( $('GALALBUM') ){
		var principal_w = $('PRINCIPAL').getWidth()
		var principal_h = $('PRINCIPAL').getHeight()
		$('GALALBUM').style.width = (principal_w-0) + 'px'
		$('GALALBUM').style.height = (principal_h-140) + 'px'
		$('carousel_cont').style.width = ( principal_w - 80 ) + 'px'
	}
}

function AffichSousMenu(div,x,y,affich){
	if (!affich) affich = false;
	if (!x) x=0;
	if (!y) y=0;
	divEnCours = document.getElementById(div);
	divEnCours.style.left = x + 'px';
	divEnCours.style.top = y + 'px';
	if (affich==true) {
		divEnCours.style.display = 'block';
	} else {
		divEnCours.style.display = 'none';
	}
}

function OuvreFenetre(NumFenetre){
	Div = $('FENETRE'+NumFenetre);
	//---- Cadre Transparent ("CACHE")
	if ( $('CACHE').visible() ) {
		new Effect.Fade(Div,{duration:0.5});
		new Effect.Fade($('CACHE'),{duration:0.5});
	} else {
		$('CACHE').show();
		new Effect.Appear(Div,{duration:0.5});
	}
}
function Wait(Div){
	couleur = '#999999';
	var text = 	"<div align='center' style='padding-top:100px;'>" +
				"<b><font style='color:"+couleur+";'>Chargement en cours.....</font></b><br><br>" +
				"<img src='images/loading.gif' border='0' alt='Chargement en cours....'>" +
				"</div>";
	$(Div).innerHTML = text;
}

//---- Ouverture d'une image en PopUp
function OpenImage(img, titre) {
	var ladate = new Date();
	if ( !titre ) titre='--== Photo - Image - '+ladate.getFullYear()+' ==--';
	w=open("",'image','width=400,height=400,toolbar=no,scrollbars=no,resizable=yes, left=50, top=50');
	w.document.write("<HTML><HEAD><TITLE>"+titre+"</TITLE></HEAD>");
	w.document.write("<SCRIPT language=javascript>function checksize()  { if (document.images[0].complete) {  window.resizeTo(document.images[0].width+17,document.images[0].height+40); window.focus();} else { setTimeout('check()',250) } }</"+"SCRIPT>");
	w.document.write("<BODY onload='checksize()' oncontextmenu='return false' onkeydown='return false' leftMargin=5 topMargin=5 marginwidth=0 marginheight=0><IMG src='"+img+"' border=0>");
	w.document.write("");
	w.document.write("</BODY></HTML>");
	w.document.close();
}

//---- Ouverture d'une image en DIV
function AffichImage(img, niveau){
	if ( !niveau ) niveau=0;
	var dossier='';
	switch ( niveau ) {
		case 0:
			new Ajax.Updater( $('FENETRE2'),dossier+'fenetre2_img.php',{method:'get',parameters:{image:img}, onSuccess:function(){} } );
			$('FENETRE2').show();
			return false;
		case 1 :
			niveau = window.parent;
			dossier += '../../';
			break;
		case 2 :
			niveau = window.parent.parent;
			dossier += '../../';
			break;
	}
	niveau.$('CACHE').show();
	new Ajax.Updater( niveau.$('FENETRE2'),dossier+'fenetre2_img.php',{method:'get',parameters:{image:img}, onSuccess:function(){} } );
	niveau.$('FENETRE2').show();

}

//---- Charge LIVRE GALERIE
function ChargeXMLPages(pages){
	alert(pages);
	var so = new SWFObject("modules/galerie/swf/book.swf", "book", "600", "400", "8", "#FFFFFF");
	so.addVariable("xmlFile","modules/galerie/xml/"+pages);
	so.write("livre");
}

//---- CORRECTION AJAX-FCKEDITOR
  function FCKVerif()
  {
          this.UpdateEditorFormValue = function()
          {
                  for ( i = 0; i < parent.frames.length; ++i )
                          if ( parent.frames[i].FCK )
                                  parent.frames[i].FCK.UpdateLinkedField();
          }
  }
  
//---- CADRE D'AIDE
	var aide_i=false;
	
	function aide_move(e) {
		if(aide_i) {
			var HAide = $('AIDE').getHeight();
			var HFenetre = document.body.clientHeight;
			if (navigator.appName!="Microsoft Internet Explorer") {
				$('AIDE').style.left=e.pageX + 5+"px";
				if ( (e.pageY + HAide)<HFenetre ) $('AIDE').style.top=e.pageY + 10+"px";
				else $('AIDE').style.top=e.pageY - HAide + 10+"px";
			}
			else {
				if(document.documentElement.clientWidth>0) {
					$('AIDE').style.left=10+event.x+document.documentElement.scrollLeft+"px";
					if ( (event.y + document.documentElement.scrollTop + HAide)>HFenetre ) $('AIDE').style.top=10+(event.y-HAide)+document.documentElement.scrollTop+"px";
					else $('AIDE').style.top=10+event.y+document.documentElement.scrollTop+"px";
				} else {
					$('AIDE').style.left=10+event.x+document.body.scrollLeft+"px";
					if ( (event.y + document.documentElement.scrollTop + HAide)>HFenetre ) $('AIDE').style.top=10+(event.y-HAide)+document.documentElement.scrollTop+"px";
					else $('AIDE').style.top=10+event.y+document.documentElement.scrollTop+"px";
				}
			}
		}
	}
	
	function aide_affiche(text) {
		if(aide_i==false) {
			$('AIDE').style.visibility="visible"; 
			$('AIDE').innerHTML = text;
			aide_i=true;
		}
	}
	
	function aide_cache() {
		if(aide_i==true) {
			$('AIDE').style.visibility="hidden";
			aide_i=false;
		}
	}
	
	document.onmousemove=aide_move;

//---- EVENEMENTIEL
	function EV_Clignote(){
		if ( ($('EV_PROCHAIN')) && ($('EV_PROCHAIN').visible()) ) {
			new Effect.Fade($('EV_PROCHAIN'),{duration:1});
			window.setTimeout("EV_Clignote()",1000);
		} else {
			new Effect.Appear($('EV_PROCHAIN'),{duration:0.1});
			window.setTimeout("EV_Clignote()",3000);
		}
	}

//---- CATALOGUE / WEB BOUTIQUE

	function Cat_Affich_Img(id_img1, id_img2, hcadre, vcadre){
		if ( $(id_img1).visible() ) {
			$(id_img2).style.top = ((hcadre - $(id_img2).getHeight())/2)+'px'; 
			$(id_img2).style.left = ((vcadre - $(id_img2).getWidth())/2)+'px'; 
			new Effect.Fade(id_img1);
			new Effect.Appear(id_img2);
		} else {
			$(id_img1).style.top = ((hcadre - $(id_img1).getHeight())/2)+'px'; 
			$(id_img1).style.left = ((vcadre - $(id_img1).getWidth())/2)+'px'; 
			new Effect.Fade(id_img2);
			new Effect.Appear(id_img1);
		}

	}
	
	function Cat_TurnImages(id_img1, id_img2, cadre, tnimages, images, numimg){
		tnimagesliste = tnimages;
		imagesliste = images;
		var hcadre = $(cadre).offsetHeight;
		var vcadre = $(cadre).offsetWidth;
		if ( !numimg ) numimg=0;

		if ( tnimages.indexOf("|", 0)==-1 ) {
			$(id_img1).hide();
			$(id_img2).hide();
			$(id_img1).src = tnimages;
			$(id_img1).style.top = ((hcadre - $(id_img1).getHeight())/2)+'px'; 
			$(id_img1).style.left = ((vcadre - $(id_img1).getWidth())/2)+'px'; 
			window.setTimeout("Cat_Affich_Img('"+id_img1+"', '"+id_img2+"', '"+hcadre+"', '"+vcadre+"')",500);
		} else {
			// Liste des images en Tableau
			i = 0;
			var tnimagesLst = new Array;
			while ( tnimages.indexOf("|", 0)!=-1 ){
				image = tnimages.substr(0,tnimages.indexOf("|", 0));
				tnimagesLst[i] = image;
				tnimages = tnimages.substr(tnimages.indexOf("|",0)+1, tnimages.length);
				i++;
			}
			tnimagesLst[i] = tnimages;
			
			if ( $(id_img1).visible() ) $(id_img2).src=tnimagesLst[numimg];
			else $(id_img1).src=tnimagesLst[numimg];
			window.setTimeout("Cat_Affich_Img('"+id_img1+"', '"+id_img2+"', '"+hcadre+"', '"+vcadre+"')",500);
			
			if ( numimg+1 == tnimagesLst.length ) numimg = 0;  else numimg = numimg+1;
			window.setTimeout("Cat_TurnImages('"+id_img1+"', '"+id_img2+"', '"+cadre+"', '"+tnimagesliste+"', '', "+numimg+")",3000);
		}
	}
	//--- CCWEB SITE
	function SlideLeft(NumDivOut, NumDivIn){
		$('DIV'+NumDivIn).hide();
		$('DIV'+NumDivIn).style.left = '427px';
		new Effect.MoveBy($('DIV'+NumDivOut),0,-418, {duration:1, fps:25, from:0.0, to:1.0});
		new Effect.Fade($('DIV'+NumDivOut));
		new Effect.MoveBy($('DIV'+NumDivIn),0,-418, {duration:1, fps:25, from:0.0, to:1.0});
		new Effect.Appear($('DIV'+NumDivIn));
	}
	function SlideRight(NumDivOut, NumDivIn){
		$('DIV'+NumDivIn).hide();
		$('DIV'+NumDivIn).style.left = '-427px';
		new Effect.MoveBy($('DIV'+NumDivOut),0,436, {duration:1, fps:25, from:0.0, to:1.0});
		new Effect.Fade($('DIV'+NumDivOut));
		new Effect.MoveBy($('DIV'+NumDivIn),0,436, {duration:1, fps:25, from:0.0, to:1.0});
		new Effect.Appear($('DIV'+NumDivIn));
	}
	
//---- Décodage UTF8
	function utf8_decode ( str_data ) {
		var tmp_arr = [], i = ac = c = c1 = c2 = 0;
		while ( i < str_data.length ) {
			c = str_data.charCodeAt(i);
			if (c < 128) {
				tmp_arr[ac++] = String.fromCharCode(c); 
				i++;
			} else if ((c > 191) && (c < 224)) {
				c2 = str_data.charCodeAt(i+1);
				tmp_arr[ac++] = String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			} else {
				c2 = str_data.charCodeAt(i+1);
				c3 = str_data.charCodeAt(i+2);
				tmp_arr[ac++] = String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
		}
		return tmp_arr.join('');
	}
	
//---- Empêche la sélection de texte
function noSelect(){
	document.onselectstart=new Function ("return false")
}

function StreamVideo(Video, Container, largeur, hauteur)
{
		var s1 = new SWFObject("http://www.bureau-center.net/figaro/fr/pages/player.swf","",largeur, hauteur,"9","#FFFFFF");
		s1.addParam("allowfullscreen","true");
		s1.addParam("allowscriptaccess","always");
		s1.addParam("wmode","transparent");
		s1.addParam("flashvars","file=http://www.bureau-center.net/figaro/fr/pages/flv/"+Video);
		s1.write(Container);
}
