//DEPLACEMENT DU FILIGRANE
function deplaceFili(){
	//$('#filigrane').fadeOut('fast', function(){});
	var marg=(window.innerWidth-900)/2;
	if(marg>114){
		marg-=114;		
	}else{
		marg=0;
	}
	marg+='px';
	$('#filigrane').animate({
		'marginLeft': marg,
		'marginTop': '10px'
	},1);
	//On fait apparaitre le filigrane
	$('#filigrane').fadeIn(3000, function(){});
}

function getEcran(){
//Test du navigateur pour IE l'icompatible de service
		//ecran[0]=height et ecran[1]=width
		
		var ecran= new Array();
		if(navigator.appName=="Microsoft Internet Explorer"){
			var isIE=true;
			if(window.document.compatMode == "CSS1Compat" ){
				ecran[0]=document.documentElement.clientHeight;
				ecran[1]=document.documentElement.clientWidth;
			}else{
				ecran[0]=document.body.clientHeight;
				ecran[1]=document.body.clientWidth;
			}	
		}else{
			var isIE=false;
			ecran[0]=window.innerHeight;
			ecran[1]=window.innerWidth;
		}
		return ecran;

}

function positionMots(){
		var ch=getEcran()[0];
		var cw=getEcran()[1];
		//calcul de la marge pour les mots de gauche et droite
		var mlg=0;
		var mld=cw-240;
		
		if((cw-$('#global_page').width())/2>240){
			mlg=(cw-$('#global_page').width())/2-180;
			
			mld=$('#global_page').width()/2+cw/2-40;
		}
		//alert(mld+' :'+$('#global_page').width()+' : '+cw/2+' I '+mlg );
		$('#motsg').css({ position: "absolute", marginLeft: mlg+'px', marginTop: 0});
		$('#motsd').css({ position: "absolute", marginLeft: mld+'px', marginTop: 0});
}



$(document).ready(function() {
	
	$('.close').live('click', function(){
		//$('#box').fadeOut('fast', function(){
		$(this).parent().fadeOut('fast', function(){
		$('#form_filtres').animate({
			'marginRight': '0px',
				 'marginTop': '0px'
					},700);
		$('#box').html('');
		} );
	});
	
	$(window).resize(function() {
		var marg=(window.innerWidth-$('#global_page').width())/2;
		//On replace la global page
    	$('#global_page').animate({
    		marginLeft:marg+'px'
    	},0);
    	//On replace les mots
    	positionMots();
	});
		
	
});


function replaceFooter(){
	var taillesmenu=$('#sousmenu').height()+100;
	//alert($('#sousmenu').css('display'));
	if($('#sousmenu').css('display')=="none"){
		var taillesmenu=100;
	}
	var hc=$('#header').height()+$('#conteneur').height()+taillesmenu+$('#bottom').height()+$('#reflet').height()+'px';
	$('#footer').animate({
		marginTop:hc
	},100);
	
	
	//On adapte la taille à la taille de l'écran
	var ch=getEcran()[0];
	var cw=getEcran()[1];
	var tr=ch-($('#global_page').height()+100);
	var tailles= 'header :'+$('#header').height()+' / Conteneur :'+$('#conteneur').height()+ ' / Contenu :'+$('#contenu').height()+ ' / reflet :'+$('#reflet').height()+ ' / GlobalPage :'+$('#global_page').height()+' / footer:'+$('#footer').height()+' / footerTOP:'+$('#footer').css('marginTop');
	//writediv(tailles,'msg');
	if(tr>$('#footer').height()){
		$('#footer').animate({
			height: tr+'px'
		},200);
	}
	
}


function confirmSubmit(){
    choix = confirm("Souaitez vous vraiment supprimer cette entree ?");
    if (choix == true)
      {
      document.formulaire.submit();
      }
    else
      {
      return false;
      }
}


function afficheContenu(id){
	if(texte=file('inc/get_smenu.php?idcontenu='+id)){
		writediv(texte,'contenu');
		//On redimentionne le conteneur
		//$('#contenu').css('padding-top','244px');
		$('#contenu').animate({
			marginTop: '230px'
		});
		//On replace le footer
		replaceFooter();
		
	}

}



function formulaire(action,type){
	var texte="";
	if(action=="afficher"){
			if(texte = file('form.php?type='+type)){
				writediv(texte,'box');
				$('#box').fadeIn('normal', function(){
				
				
				} );
			}
		}else{
			$('#box').fadeOut('fast', function(){
				$('#form_filtres').animate({
				 'marginRight': '0px',
				 'marginTop': '0px'
					},700);
				writediv(texte,'box');	
			} );
		}
}




/**************AJAX*********************************************************/
function writediv(texte,id){
	document.getElementById(id).innerHTML = texte;
}

function file(fichier){
if(window.XMLHttpRequest) // FIREFOX
xhr_object = new XMLHttpRequest();
else if(window.ActiveXObject) // IE
xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
else
return(false);
xhr_object.open("GET", fichier, false);
xhr_object.send(null);
if(xhr_object.readyState == 4) return(xhr_object.responseText);
else return(false);
}

/**************fin AJAX*********************************************************/







// JavaScript Document
// Correctly handle PNG transparency in Win IE 5.5 or higher.
// Optimization : Browser Detection by Sol@web - Updated on 06 September 2005
function correctPNG(){
   for(var i=0; i<document.images.length; i++){
     var img = document.images[i]
     var imgName = img.src.toUpperCase()
     if (imgName.substring(imgName.length-3, imgName.length) == "PNG"){
       var imgID = (img.id) ? "id='" + img.id + "' " : ""
       var imgClass = (img.className) ? "class='" + img.className + "' " : ""
       var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
       var imgStyle = "display:inline-block;" + img.style.cssText
       if (img.align == "left") imgStyle = "float:left;" + imgStyle
       if (img.align == "right") imgStyle = "float:right;" + imgStyle
       if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle      
       var strNewHTML = "<span " + imgID + imgClass + imgTitle
       + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
        + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
       + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
       img.outerHTML = strNewHTML
       i = i-1
     }
   }
   /////  This part handles background png's (Koen Betsens)
   for(i=0;i<document.all.length;i++){
      bg=document.all[i].currentStyle.backgroundImage;
      if(bg.toUpperCase().substr(bg.length-5,3)=='PNG'){
         if(bg.search('%20')>0){bg=bg.replace('%20',' ')}
         document.all[i].style.backgroundImage='none';
         document.all[i].style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale src='"+bg.substr(5,bg.length-7)+"')"
      }
   }
}
 
if (navigator.appName == "Microsoft Internet Explorer") {
//	window.attachEvent("onload", correctPNG); 
}
