


function diaporama_swap_image(id){
	var table = $("#diaporama_table").attr('value');
	var limit_name = $("#diaporama_limit_name").attr('value');
	var limit_value = $("#diaporama_limit_value").attr('value');
	
	var current_id = $("#dipoarama_id").attr('value');
	
	var nb = $("#dipoarama_nb").attr('value');
	
	
	if(id == 'next'){
		id = (Number(current_id) + 1 == Number(nb) ? 0 : Number(current_id)+1);
	}else if(id  == 'previous'){
		id = (Number(current_id) == 0 ? Number(nb)-1 : Number(current_id)-1);
	}
	
	
	$.ajax({
	   type: "POST",
	   url: CFG_HTTP_ROOT + "include/ajax.inc.php",
	   data: "ajax=1&action=diaporama_swap_image&table=" + table + "&id=" + id + "&nb=" + nb + "&limit_name=" + limit_name + "&limit_value=" + limit_value  ,
	   success: function(msg){
		 
		 
		 
		 	retour = msg.split('|');
			//$("#diaporama_img").attr('src', CFG_HTTP_ROOT + retour[0])
			
			$("#diaporama_image").html(retour[0]);
			$("#diaporama_nav").css('width', retour[1]+'px');
			$("#diaporama_nav .texte").html(retour[2]);
			$("#dipoarama_id").attr('value', id);

	   }
	 });		
		
}











function slide_show_preload() { 
	document.getElementById(diaporama_image).src = CFG_HTTP_ROOT + 'img/preload.gif';	
	tmp_img_loaded = new Array();
	tmp_img = new Array();
	tmp_img_loaded_count = 0
	for(a = 0; a < diaporama_array.length; a++){
		array_img =diaporama_array[a].split('|');
		
		tmp_img[a] = new Image(); 
		tmp_img[a].src  = array_img[0];
		tmp_img_loaded[a] = false
	}										  
	slide_show_checkload()
}
















function slide_show_checkload() {
	if (tmp_img_loaded_count == diaporama_array.length) { 
		slide_show(0);
		return false;
	}
	for (i = 0; i <= diaporama_array.length; i++) {
		if (tmp_img_loaded[i] == false && tmp_img[i].complete) {
			tmp_img_loaded[i] = true;
			tmp_img_loaded_count++;
		}
	}
	timerID = setTimeout("slide_show_checkload()",10) 
}


function slide_show(id){
	
	array_img =diaporama_array[id].split('|');
	document.getElementById(diaporama_image).src = array_img[0];
	document.getElementById(diaporama_titre).innerHTML = array_img[1];
	document.getElementById(diaporama_titre).style.width = array_img[3]+'px';
	document.getElementById(diaporama_image).onclick=function(){
		document.location.replace(array_img[2]);
	}
	
      $("#slide_show").fadeIn("slow", function () {
			setTimeout("slide_show_fade_out("+id+")",diaporama_vitesse);
      });

	

	
}	


function slide_show_fade_out(id){
	
      $("#slide_show").fadeOut("slow", function () {
			slide_show_timout(id)
      });

	

}

function slide_show_timout(id){
	id = (id == diaporama_array.length - 1) ? 0 : id+1;
	slide_show(id);
	
}




function changeSize() {

if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
 var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
}else{
 var ieversion = 0
}



  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;

  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  
  	if( (ieversion <= 6) &&  (ieversion != 0)) {
		myWidth = myWidth - 30;
	}
	if(ieversion != 0){
		myHeight = myHeight + 18;
		myWidth = myWidth - 8;
	}
  MainWidth = myWidth - 2
  MainHeight = myHeight - 2
  
  document.getElementById('website').style.height = MainHeight + 'px';
  document.getElementById('website').style.width = MainWidth + 'px';
}


















function prepareMouseOverImage(image_out_id, image_over, HexColor_out, HexColor_over){
  var myCanvas=document.createElement("canvas");

	if (myCanvas.getContext) {  
		image = document.getElementById(image_out_id)
		image.onload=function(){
			this.normalImage = ChangeColor(this, HexColor_out);
			this.mouseOverImage = ChangeColor(this, HexColor_over);
			
			this.onmouseover=function(){
				this.src=this.mouseOverImage;
				this.style.cursor='pointer';
			}
			
			this.onmouseout=function(){
				this.src=this.normalImage;
				this.style.cursor='	pointer';
			}
			this.src=this.normalImage;
			this.style.display = 'block';
		};
	}else{
		image_src = document.getElementById(image_out_id).src;


			document.getElementById(image_out_id).onmouseover=function(){
				this.src= image_over;
			}
			
			document.getElementById(image_out_id).onmouseout=function(){
				this.src=image_src;
			}
			
			document.getElementById(image_out_id).style.display = 'block';
		
	}
}




function ChangeColor(image, HexColor)
{
	
  currentColor = Colors.ColorFromHex(HexColor);
  
  var red = currentColor.Red();
  var green= currentColor.Green();
  var blue = currentColor.Blue();
  
  
  
  var myCanvas=document.createElement("canvas");
  var myCanvasContext=myCanvas.getContext('2d');

  var imgWidth=image.width;
  var imgHeight=image.height;
  // You'll get some string error if you fail to specify the dimensions
  myCanvas.width= imgWidth;
  myCanvas.height=imgHeight;
//  alert(imgWidth);
  myCanvasContext.drawImage(image,0,0);
  // this function cannot be called if the image is not rom the same domain.  You'll get security error
  var imageData=myCanvasContext.getImageData(0,0, imgWidth, imgHeight);
  for (i=0; i<imageData.height; i++)
  {
    for (j=0; j<imageData.width; j++)
    {
	  var index=(i*4)*imageData.width+(j*4);
	  var alpha=imageData.data[index+3];	 
   	  imageData.data[index]= red;	  
   	  imageData.data[index+1]=green;
   	  imageData.data[index+2]=blue;
   	  imageData.data[index+3]=alpha;	  	  
	}
  }
  myCanvasContext.putImageData(imageData,0,0,0,0, imageData.width, imageData.height);
 // myCanvasContext.drawIMage(imageData,0,0);//,0,0, imageData.width, imageData.height);  

	return myCanvas.toDataURL();
}







