function preparer_diaporama () {
	var par = window.document;
	var el = "ul_menu_Realisation";
	
	var ul = par.getElementById(el);
	ul.style.width = "1104px";
	ul.style.overflow = "hidden";
	/**
	var enfant = ul.getElementsByTagName('li');
	var i = 0;
	while (i < enfant.length && enfant[0].getAttribute('id') != 'current') {
		var first = ul.removeChild(ul.getElementsByTagName('li')[0]);
		ul.appendChild(first);
		i++;
	}
	i = 0;
	if (enfant.length >= 3) {
	while (i < 3) {
		var last = ul.removeChild(ul.getElementsByTagName('li')[ul.getElementsByTagName('li').length - 1]);
		ul.insertBefore(last, ul.getElementsByTagName('li')[0]);
		i++;
	}
	}
	**/


}

function insertAfter(newElement,targetElement) {
	//target is what you want it to go after. Look for this elements parent.
	var parent = targetElement.parentNode;
	//if the parents lastchild is the targetElement...
	if(parent.lastchild == targetElement) {
		//add the newElement after the target element.
		parent.appendChild(newElement);
	}
	else {
		// else the target has siblings, insert the new element between the target and it's next sibling.
		parent.insertBefore(newElement, targetElement.nextSibling);
	}
}


function print_r(obj) {
  win_print_r = window.open('about:blank', 'win_print_r');
  win_print_r.document.write('<html><body>');
  r_print_r(obj, win_print_r);
  win_print_r.document.write('</body></html>');
 }

 function r_print_r(theObj, win_print_r) {
  if(theObj.constructor == Array ||
   theObj.constructor == Object){
   if (win_print_r == null)
    win_print_r = window.open('about:blank', 'win_print_r');
   }
   for(var p in theObj){
    if(theObj[p].constructor == Array||
     theObj[p].constructor == Object){
     win_print_r.document.write("<li>["+p+"] =>"+typeof(theObj)+"</li>");
     win_print_r.document.write("<ul>")
     r_print_r(theObj[p], win_print_r);
     win_print_r.document.write("</ul>")
    } else {
     win_print_r.document.write("<li>["+p+"] =>"+theObj[p]+"</li>");
    }
   }
  win_print_r.document.write("</ul>")
 }



function getProduit(next) {
	if (diapo.first != diapo.last) {
	
		if (next == 'a') {
			current = diapo.last;
		}
		else {
			current = diapo.first;
		}
		diapo.json = 0;
		$.getJSON('./Realisation.php?ni=' + next + '&c=' + current, function(data){
			  if (data)
			  diapo.json = data;
			});
			
			for (var x in diapo.json.json) {
			
		if (next == 'a') {
			diapo.last = x;
		}
		else {
			diapo.first = x;
		}
				var par = window.document;
				var li=par.createElement("li");
				var id_li = par.createAttribute("id");
				id_li.nodeValue = 'li_diaporama_' + x;
				li.setAttributeNode(id_li);
				var lien=par.createElement("a");
				//var image=par.createElement("img");
				var div=par.createElement("div");
				//div.setAttribute("class");
				//alert(x + diapo.json.json[x].photo + " " + diapo.json.json[x].lien_page)
				var image = new Image();
				image.src = diapo.json.json[x].photo;
				image.setAttribute('alt', diapo.json.json[x].nom_page);
				image.setAttribute('title', diapo.json.json[x].nom_page);
				lien.setAttribute('title', diapo.json.json[x].nom_page);
				lien.href = diapo.json.json[x].lien_page.replace('&amp;', '&');
				lien.appendChild(image);
				div.appendChild(lien);
				li.appendChild(div);
			}
				return li;
    }
	return false;    
}

Number.prototype.mod = function(n) {
return ((this%n)+n)%n;
}
function play_diaporama (direction) {


	var par = window.document;
	var el = "ul_menu_Realisation";
	var ul = par.getElementById(el);
	var t = ul.getElementsByTagName('li').length;
	
	if (t >= diapo.nb) {
		diapo.first = diapo.last = 0;
	}
	
	var n;
	if (direction == 'right') {
		
		n = getProduit('a');
		var first = ul.removeChild(ul.getElementsByTagName('li')[0]);
		ul.appendChild(first);
		if (n) {
			diapo.debut = (diapo.debut - 1).mod(t);
			ul.insertBefore(n, ul.getElementsByTagName('li')[diapo.debut++]);
		}
		
		
	}
	else if (direction == 'left') {
			
		
		if (diapo.debut == 0) {
			n = getProduit('b');
			if (n) {
				ul.insertBefore(n, ul.getElementsByTagName('li')[diapo.debut]);
				//diapo.debut = (diapo.debut==0?0:(diapo.debut - 1));
			}

		}
		
		//diapo.debut = (diapo.debut + 1) % t;
		if (diapo.debut != 0 || !n) {
			//if (!n) {
				diapo.debut = (diapo.debut + 1) % t;
			//}
			var last = ul.removeChild(ul.getElementsByTagName('li')[ul.getElementsByTagName('li').length - 1]);
			ul.insertBefore(last, ul.getElementsByTagName('li')[0]);
		}
	}
	
}
function aff_sous_menu(id) {
	var dd = document.getElementById(id);
	for (var i = 1; i<=10; i++) {
		if (document.getElementById('dd_sousMenu_0_'+i)) {
			document.getElementById('dd_sousMenu_0_'+i).style.display='none';
		}
	}

	if (dd != null) {
		dd.style.display='block';
	}
}

function hide_sous_menu(id) {
	var dd = document.getElementById(id);
	if (dd != null) {
		dd.style.display='none';
	}
}



/**
function aff_sous_menu(id) {
	var dd = document.getElementById(id);
	for (var i = 1; i<=10; i++) {
		if (document.getElementById('dd_sousMenu_0_'+i)) {
			document.getElementById('dd_sousMenu_0_'+i).style.display='none';
		}
	}

	if (dd != null) {
		var width = dd.parentNode.offsetWidth;
		dd.style.width=width + "px";
		dd.style.display='block';
	}
}

function hide_sous_menu(id) {
	var dd = document.getElementById(id);
	if (dd != null) {
		dd.style.display='none';
	}
}
**/


function CheckUncheckCheckBox(checkBox) {
	var par = window.document;
	if(checkBox.checked) {
		checkBox.parentNode.className = 'label_checkbox ' + '_checked';
	}
	else {
		var reg = new RegExp('_checked');
		checkBox.parentNode.className = checkBox.parentNode.className.replace(reg,' ');
	}
	return checkBox.checked;
}

/**
function aff_sous_menu(el, dd) {
	if (!dd) {
		var dd_el = el.getElementsByTagName('dd')[0];
	}
	else {
		dd_el = el;
	}
	if (dd_el != null) {
		dd_el.style.display='block';
	}
}

function hide_sous_menu(el, dd) {
	if (!dd) {
		var dd_el = el.getElementsByTagName('dd')[0];
	}
	else {
		dd_el = el;
	}
	if (dd_el != null) {
		dd_el.style.display='none';
	}
}
**/
