/*

*/

function init(id, file)
{
	load_image(id, file);
	load_title(id, file);
	load_desc(id, file);
	//~ make_opacity(n);
}

function make_opacity(n)
{
	var i;
	var a = 0;
	var b = 0;

	$$('img.unactive').each(function(s) 
	{
		a++;
	});

	for (i = 1; i <= a; i++)
	{
		if ($('img_'+i) == $('img_'+n))
		{
			unset_opacity('img_'+n);
			$('img_'+n).writeAttribute('onmouseout', '');
			$('img_'+n).writeAttribute('onmouseover', '');
		}
		else
		{
			set_opacity('img_'+i);
			$('img_'+i).writeAttribute('onmouseover', 'unset_opacity(this.id);');
			$('img_'+i).writeAttribute('onmouseout', 'set_opacity(this.id);');
			
			//~ Event.observe(window, 'load', function() {

				//~ $('img_'+i).observe('mouseover',function(){
					//~ new Effect.Opacity('img_'+i, {from: 0.5, to: 1});
				//~ });
				//~ $('img_'+i).observe('mouseout', function(){
					//~ new Effect.Opacity('img_'+i, {from: 1, to: 0.5});
				//~ });
			//~ });
		}
	}		
}

/*

*/
function load_image(id, file)
{
	var urls= 'ajax/load_image.php';
	var param = 'img='+id+'&file='+file;
	var url = urls;
	var myAjax = new Ajax.Request
	(
		url, 
		{
			encoding: 'iso-8859-1',
			asynchronous: false,
			method: 'post', 
			postBody: param,
			onComplete: ajax_img
		}
	);
}

/*

*/
function load_title(id, file)
{
	var urls= 'ajax/load_title.php';
	var param = 'title='+id+'&file='+file;
	var url = urls;
	var myAjax = new Ajax.Request
	(
		url, 
		{
			encoding: 'iso-8859-1',
			asynchronous: false,
			method: 'post', 
			postBody: param,
			onComplete: ajax_title
		}
	);
}

/*

*/
function load_desc(id, file)
{
	var urls= 'ajax/load_desc.php';
	var param = 'desc='+id+'&file='+file;
	var url = urls;
	var myAjax = new Ajax.Request
	(
		url, 
		{
			encoding: 'iso-8859-1',
			asynchronous: false,
			method: 'post', 
			postBody: param,
			onComplete: ajax_desc
		}
	);
}


/*

*/
function ajax_img(originalRequest)
{
	if (originalRequest.readyState == 4)
	{
		if (originalRequest.status==200)
		{
			$('idlink').writeAttribute('rel', ""); 
			if ($('idphoto'))
			{			
				if ($('idlink'))
				{	
					var mylink = 'media/projets/web/large/'+originalRequest.responseText+'_large.png';
					$('idlink').writeAttribute('href', mylink);
					$('idlink').writeAttribute('rel', "lightbox[lol]"); 
				}
							
				if ($('idlinkae'))
				{	
					var mylink = 'media/projets/web/large/'+originalRequest.responseText+'_large.png';
					//~ $('idlinkae').replace(mylink);
				}	
				
				//~ A-t-on une class ?
				var class_css = $('idphoto').classNames();
				
				//~ Oui / Non ??
				if (class_css == '')
				{
					//~ Non, nous n'avons pas de class :'(
					//~ Alors ajoute une class :D
					$('idphoto').addClassName(originalRequest.responseText);		
				}
				else
				{
					//~ On a une class, on la supprime pour la remplacer par une nouvelle :D !!!
					$('idphoto').removeClassName(class_css);
					$('idphoto').toggleClassName(originalRequest.responseText);
				}			
			}

			fixmypng();			
		}
	}
}

/*

*/
function ajax_title(originalRequest)
{
	if (originalRequest.readyState == 4)
	{
		if (originalRequest.status==200)
		{
			if ($('desct'))
			{
				$('desct').update(originalRequest.responseText);		
			}
			fixmypng();			
		}
	}
}

/*

*/
function ajax_desc(originalRequest)
{
	if (originalRequest.readyState == 4)
	{
		if (originalRequest.status==200)
		{
			if ($('descp'))
			{
				$('descp').update(originalRequest.responseText);		
			}
			fixmypng();			
		}
	}
}

function set_opacity(id)
{
	new Effect.Opacity(id, {from: 1.5, to: 0.5, duration: 0.5, speed: 0.0});
}

function unset_opacity(id)
{
	new Effect.Opacity(id, {from: 0.5, to: 1.0, duration: 0.5, speed: 0.0});
}

/********

*********/
function fixmypng()
{
	/*
	//~ Si nous sommes sous IE
	if (Prototype.Browser.IE)
	{
		var arVersion = navigator.appVersion.split("MSIE")
		var version = parseFloat(arVersion[1])

		if ((version >= 5.5) && (document.body.filters)) 
		{
			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 + "' " : "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='image'); \"></span>" 
					img.outerHTML = strNewHTML
					i = i-1
				}
			}
		}
	}
	*/
}

//~ Fix la transparence au chargement de la page
if (Prototype.Browser.IE)
{
	window.attachEvent("onload", fixmypng);
}

/*
function load_url()
{
	document.observe('dom:loaded', function() 
	{
		$$('a').each(function(e) 
		{
			if(e.getAttribute('rel') == 'load') 
			{
				p_sHref = e.getAttribute('href');
				if(/^#/.match(p_sHref) || p_sHref == '' || !p_sHref) return;
				l_oIframe = new Element('iframe', {src:p_sHref} ).hide();
				document.body.appendChild(l_oIframe);
			}
		});
	});
  }
  <a href = "http://www.natures-desktop.com/images/Wallpaper/widescreen1920x1200/coast-beach/Southwold-Beach1.jpg" rel = "load">Testlink</a>
  */