// JavaScript Document

//
//	Librairie by The Rubik's Man
//		    © 2005-2006
//

var Ajax_request = 	function() {
	this.request.apply(this, arguments);
}
Ajax_request.prototype = {
	
	request: function (url, options) {	
		this.getObject();
			
		if ( typeof(options) == 'undefined' ) options = new Array();
		if ( typeof(options) == 'object' ) {
			method = options['method'] || 'post';
			successEnd = options['onSuccess'] || this.debugSuccessMessage.bind(this);
			errorEnd = options['onError'] || this.defaultErrorMessage.bind(this);
			paramString = typeof(options['params']) == 'undefined' ? '' : (options['method'] == 'get' ? '?'+options['params'] : options['params']);
						
			if ( typeof(options['async']) != 'undefined' && typeof(options['async']) != 'boolean' ) {
				alert('si la valeur de \'async\' est definie, elle doit etre de type booleen');
				return;
			}
			else async = typeof(options['async']) == 'undefined' || typeof(options['async']) != 'boolean'? true : options['async'];
									
			this.setProperties(method,successEnd,errorEnd,paramString,async);
		}
								
		if ( typeof(url) != 'string' ) {
			alert('url de format invalide ( l\'url est obligatoire )');
			return;
		}
		else this.properties['url'] = url;
							
		this.setReadyProcess();
		this.processRequest();
	},
	
	
	getObject: function() {
		if(window.XMLHttpRequest) this.Ajax_object = new XMLHttpRequest();
		else if (window.ActiveXObject) { 
			try {
				this.Ajax_object = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) {
				try {
					this.Ajax_object = new ActiveXObject("Microsoft.XMLHTTP");
				} 
				catch (e1) {
					this.Ajax_object = null;
				}
			}
		}
		else  {
		    alert("AJAX impossible sur votre navigateur");
		}
		this.properties = new Array();
	},
	
	setProperties: function() {
		this.properties = {
			method : arguments[0],
			successEnd : arguments[1],
			errorEnd : arguments[2],
			paramString : arguments[3],
			async : arguments[4]
		}
	},

	setReadyProcess: function() {
		this.Ajax_object.onreadystatechange = function() {
			if (this.Ajax_object.readyState == 4 ) {
				responseText = this.Ajax_object.responseText;
				responseXML = this.Ajax_object.responseXML;
				this.responseText = this.Ajax_object.responseText;
				this.responseXML = this.Ajax_object.responseXML;
				if ( this.Ajax_object.status == 200 ) this.properties['successEnd'](this.Ajax_object);
				else this.properties['errorEnd'](this.Ajax_object);
			}
		}.bind(this);
	},
	
	defaultErrorMessage: function(xhr)  {
		alert('Error ' + xhr.status + ' -- ' + xhr.statusText);
	},
	
	debugSuccessMessage: function(xhr) {
		alert('Reponse texte\n\n'+xhr.responseText);
	},
	
	processRequest: function() {
		this.Ajax_object.open(
			this.properties['method'],
			this.properties['method'] == 'post' ?
				this.properties['url'] : this.properties['url']+this.properties['paramString'],
			this.properties['async']
		);
		if ( this.properties['method'] == 'post' )
			this.Ajax_object.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		this.Ajax_object.send(this.properties['method'] == 'post' ? this.properties['paramString'] : null);
	}
	
}
Function.prototype.bind = function(object) {
	var __method = this;
	return function() {
		return __method.apply(object, arguments);
	}
}

var responseText = new String();
var responseXML = new Object();

//
//	Librairie by The Rubik's Man
//		    © 2005-2006
//






function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  obj2 = document.getElementById(obj);
  if(obj2) {
  // IE/Win
  obj2.style.filter = "alpha(opacity=" + opacity + ")";
  
  // Safari<1.2, Konqueror
  obj2.style.KHTMLOpacity = opacity/100;
  
  // Older Mozilla and Firefox
  obj2.style.MozOpacity = opacity/100;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj2.style.opacity = opacity/100;
  }
};
 
function fadeIn(objId,opacity) {
    if (opacity <= 100) {
      opacity += 10;
	setOpacity(objId, opacity);
      window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 70);
    }
};
function fadeInSlim(objId,opacity, maxi) {
    if (opacity < maxi) {
      opacity += 20;
	if(opacity > 100) opacity = 100;
	setOpacity(objId, opacity);
      window.setTimeout("fadeInSlim('"+objId+"',"+opacity+","+maxi+")", 40);
    }
};
function fadeOut(objId,opacity) {
    if (opacity >= 80) {
      opacity -= 10;
	setOpacity(objId, opacity);
      window.setTimeout("fadeOut('"+objId+"',"+opacity+")", 100);
    }
};
function fadeOutTotal(objId,opacity) {
    if (opacity >= 10) {
      opacity -= 10;
	setOpacity(objId, opacity);
      window.setTimeout("fadeOutTotal('"+objId+"',"+opacity+")", 50);
    } else {
	document.getElementById(objId).style.display = 'none';    
    }	
};

function slideIn(objId, hauteur, maxi) {
	if(hauteur < maxi - 5) {
		hauteur = Math.floor(hauteur + ((maxi - hauteur) / 4));
		document.getElementById(objId).style.height = hauteur+'px';
		window.setTimeout("slideIn('"+objId+"',"+hauteur+","+maxi+")", 50);
	} else {
		document.getElementById(objId).style.height = maxi+'px';
	}
};
function slideOut(objId, hauteur, maxi) {
	if(hauteur > maxi + 5) {
		hauteur = Math.floor(((hauteur - maxi) / 2));
		document.getElementById(objId).style.paddingBottom = hauteur+'px';
		window.setTimeout("slideOut('"+objId+"',"+hauteur+","+maxi+")", 50);
	} else {
		document.getElementById(objId).style.paddingBottom = (maxi + 5) +'px';
	}
};


function artFadeIn(objId,opacity) {
    if (opacity <= 6) {
      opacity += 1;
	setOpacity(objId, opacity);
      window.setTimeout("artFadeIn('"+objId+"',"+opacity+")", 50);
    }
};

function mFadeOut(objId,opacity) {
    if (opacity < 100) {
      opacity += 5;
	setOpacity(objId, opacity);
      window.setTimeout("mFadeOut('"+objId+"',"+opacity+")", 50);
    }
};


function artOver(id)
{
	if(document.getElementById(id))
	{
	//	document.getElementById(id).style.textDecoration = "underline";		
		document.getElementById(id).style.display = 'block';
	//	setOpacity(id, 8);
		artFadeIn(id, 0);
	}
};

function artOut(id)
{
	if(document.getElementById(id))
	{
	//	document.getElementById(id).style.textDecoration = "none";				
		document.getElementById(id).style.display = 'none';
	}
};


function mOver(id)
{
	if(document.getElementById(id))
	{
		setOpacity(id, 65);
	}
};

function mOut(id)
{
	if(document.getElementById(id))
	{
		mFadeOut(id, 70);
	}
};


function cartOver(id)
{
	if(document.getElementById(id))
	{
		setOpacity(id, 85);
		document.getElementById(id).style.display = "block";		
	}
};

function cartOut(id)
{
	if(document.getElementById(id))
	{
		document.getElementById(id).style.display = "none";		
	}
};


function heaOver(id)
{
	if(document.getElementById(id))
	{
		document.getElementById(id).style.backgroundPosition = "top left";		
	}
};

function heaOut(id)
{
	if(document.getElementById(id))
	{
		document.getElementById(id).style.backgroundPosition = "bottom left";		
	}
};


function displayThumb(selected, liste)
{
	var html = "";
	var tableau = liste.split(',');
	if(tableau.length>2)
	{
			
		for(var i=0; i<tableau.length-1; i++)
		{
		
			html = html + "<div class=\"agrandirimageminclass\" style=\" background-image: url('"+tableau[i].replace('560x270', '80x60')+"');\" id=\"agrandirimageminid"+i+"\" onclick=\" document.getElementById('agrandirimagecontent').style.backgroundImage = 'url("+tableau[i].replace('560x270', '800x600')+")'; \" onmouseover=\" setOpacity('agrandirimageminid"+i+"', 50); \" onmouseout=\" setOpacity('agrandirimageminid"+i+"', 100); \"></div>";
	
	
	
		}	
		document.getElementById('agrandirimagemin').innerHTML = html;
		
	}
	
	document.getElementById('agrandirimage').style.display = 'block';
	document.getElementById('agrandirimagecontent').style.backgroundImage = "url('"+selected.replace('560x270', '800x600')+"')";
	
};