$(document).ready(function() {
	$('#imageArrierePlan').each(function() {
		var maxWidth = 150; // Max width for the image
		var maxHeight = 150;    // Max height for the image
		var ratio = 0;  // Used for aspect ratio
		var width = $(this).width();    // Current image width
		var height = $(this).height();  // Current image height
 
		// Check if the current width is larger than the max
		if(width > maxWidth){
			ratio = maxWidth / width;   // get ratio for scaling image
			$(this).css("width", maxWidth); // Set new width
			$(this).css("height", height * ratio);  // Scale height based on ratio
			height = height * ratio;    // Reset height to match scaled image
			width = width * ratio;    // Reset width to match scaled image
		}
 
		// Check if current height is larger than max
		if(height > maxHeight){
			ratio = maxHeight / height; // get ratio for scaling image
			$(this).css("height", maxHeight);   // Set new height
			$(this).css("width", width * ratio);    // Scale width based on ratio
			width = width * ratio;    // Reset width to match scaled image
		}
	});
	var offset = $("#Vision").offset();
	//alert(offset.left);
});

function selectTous()
{
	if(document.liste[0].checked == true){
		for (i = 0; i < document.liste.length; i++)
		document.liste[i].checked = true;
	}
	else
	{
		for (i = 0; i < document.liste.length; i++)
		document.liste[i].checked = false;
	}
}

function ajouterVideo(galerie)
{
	var reponse = prompt("Entrez le code du vidéo que vous voulez ajouter:","");
	if(reponse){window.location = "fonctions.php?video=" + reponse + "&galerie=" + galerie + "&action=ajouter"}
}

function renommerCategorie(categorie)
{
	var reponse = prompt("Entrez le nouveau nom de la galerie " + categorie + ":","");
	if(reponse){window.location = "fonctions.php?categorie=" + categorie + "&nom=" + reponse + "&action=renommer"}
}

function renommerGalerie(galerie,type)
{
	var reponse = prompt("Entrez le nouveau nom de la galerie " + galerie + ":","");
	if(reponse){window.location = "fonctions.php?galerie=" + galerie + "&nom=" + reponse + "&action=renommer&type=" + type}
}

function renommerImage(image)
{
	var reponse = prompt("Entrez le nouveau nom de l'image " + image + ":","");
	if(reponse){window.location = "fonctions.php?image=" + image + "&nom=" + reponse + "&action=renommer"}
}

function lienAutres(bouton, menu)
{
	var reponse = prompt("Entrez le nouveau lien du bouton '" + bouton + "':","");
	if(reponse){window.location = "fonctions.php?bouton=" + bouton + "&lien=" + reponse + "&menu=" + menu + "&action=lien"}
}

function renommerBouton(bouton, menu, id)
{
	var reponse = prompt("Entrez le nouveau nom du bouton '" + bouton + "':","");
	if(reponse){window.location = "fonctions.php?bouton=" + id + "&titre=" + reponse + "&menu=" + menu + "&action=renommer"}
}

function nouveauBouton(menu)
{
	var reponse = prompt("Entrez le nom du bouton que vous d\351sirez ajouter:","");
	if(reponse){window.location = "fonctions.php?bouton=" + reponse + "&menu=" + menu + "&action=ajouter"}
}

function nouvelleGalerie(type)
{
	var reponse = prompt("Entrez le nom de la galerie que vous d\351sirez ajouter:","");
	if(reponse){window.location = "fonctions.php?galerie=" + reponse + "&action=ajouter&type=" + type}
}

function nouvelleCategorie()
{
	var reponse = prompt("Entrez le nom de la cat\351gorie que vous d\351sirez ajouter:","");
	if(reponse){window.location = "fonctions.php?categorie=" + reponse + "&action=ajouter"}
}

function nouveauMenu()
{
	var reponse = prompt("Entrez le nom du menu que vous d\351sirez ajouter:","");
	if(reponse){window.location = "fonctions.php?menu=" + reponse + "&action=ajouter"}
}

function selection()
{
	var action = document.getElementById('actionSelection').value;
	if(action=="supprimer")var reponse = confirm("Supprimer la s\351lection?");
	else if(action=="brouillon")var reponse = confirm("Mettre la s\351lection en brouillon?");
	else if(action=="enligne")var reponse = confirm("Mettre la s\351lection en ligne?");
	else if(action=="monter")var reponse = confirm("Monter la s\351lection?");
	else if(action=="descendre")var reponse = confirm("Descendre la s\351lection?");
	else var reponse = true;
	if(reponse==true){document.liste.submit();}
}

function supprimerMenu(nom)
{
	var reponse = confirm("Supprimer le menu '" + nom + "' ?")
	if(reponse){window.location = "fonctions.php?menu=" + nom + "&action=supprimer"}
}

function supprimerBouton(id,menu, nom)
{
	var reponse = confirm("Supprimer le bouton '" + nom + "' du menu '" + menu + "' ?")
	if(reponse){window.location = "fonctions.php?bouton=" + id + "&menu=" + menu + "&action=supprimer"}
}

function supprimerUtilisateur(nom)
{
	var reponse = confirm("Supprimer l'utilisateur " + nom + " ?")
	if(reponse){window.location = "fonctions.php?nom=" + nom + "&action=supprimer"}
}

function supprimerArticle(id)
{	
	var reponse = confirm("Supprimer l'article " + id + " ?")
	if(reponse){window.location = "fonctions.php?article=" + id + "&action=supprimer"}
}

function supprimerTheme(theme)
{	
	var reponse = confirm("Supprimer le th\350me " + theme + " ?")
	if(reponse){window.location = "fonctions.php?theme=" + theme + "&action=supprimer"}
}

function supprimerGalerie(galerie,type)
{	
	var reponse = confirm("Supprimer la galerie " + galerie + " ?")
	if(reponse){window.location = "fonctions.php?galerie=" + galerie + "&action=supprimer&type=" + type}
}

function supprimerCategorie(categorie)
{	
	var reponse = confirm("Supprimer la cat\351gorie " + categorie + " ?")
	if(reponse){window.location = "fonctions.php?categorie=" + categorie + "&action=supprimer"}
}

function supprimerPage(page)
{
	var reponse = confirm("Supprimer la page " + page + " ?")
	if(reponse){window.location = "fonctions.php?page=" + page + "&action=supprimer"}
}

function supprimerImage(image, type, offset)
{
	var reponse = confirm("Supprimer l'image " + image + " ?")
	if(reponse){window.location = "fonctions.php?image=" + image + "&action=supprimer&type=" + type + "&offset=" + offset}
}

function supprimerVideo(video,id,galerie)
{
	var reponse = confirm("Supprimer le vidéo " + video + " ?")
	if(reponse){window.location = "fonctions.php?video=" + id + "&action=supprimer&galerie=" + galerie}
}

/*function reset(video)
{
	var reponse = confirm("Réinitialiser l'installation de smartFish ?")
	if(reponse){window.location = "fonctions.php?action=reset"}
}*/

function loadXMLDoc(id)
{
	if (window.XMLHttpRequest)
	  {// code pour IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code pour IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	  
	  xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			alert(xmlhttp.responseText);
		}
	  }
	  
	xmlhttp.open("GET","fonctions.php?supprimeArticle=" + id,true);
	xmlhttp.send();
}
    
