
$(function() {

$.fn.fancyzoom.defaultsOptions.imgDir='js/ressources/';//very important must finish with a /

// Select all links in object with gallery ID using the defaults options
$('a.tozoom').fancyzoom({showoverlay:true,overlay:4/10});
});

function onloadfonc() {
	if(_loader = document.getElementById('loader')) {
		_loader.style.display="none";
		document.getElementById('photo').style.display="block";
	}
}

function imageDelete(cible,url) {
	if(confirm("Effacer cette image ?")) {
	 	_img='<img src="'+url+'" class="hide">';
	 	document.getElementById(cible).innerHTML+=_img;
		setTimeout('alpha_cacher(\''+cible+'\',100)',1000);
//		setTimeout('document.getElementById(\''+cible+'\').style.display=\'none\'',3000);
	}
}

vitesse = 5;
temps = 2;

function alpha_afficher(obj,indice,_vitesse,_temps) {

	if(!_vitesse)
		_vitesse = vitesse;
	if(!_temps)
		_temps = temps;

	if(!obj.id) {
		if(document.getElementById(obj))
			obj = document.getElementById(obj);
		else 
			return false;
	}
	obj.style.display='block';
	obj.style.visibility='visible';
	obj.style.filter='alpha(opacity='+indice+')';
	obj.style.opacity=Number(indice) / 100;
	if(indice < 100) {
		setTimeout('alpha_afficher("'+obj.id+'","'+(Number(indice)+_vitesse)+'",'+_vitesse+','+_temps+')',_temps);
	}
}

function alpha_cacher(obj,indice) {
	if(!obj.id) {
		if(document.getElementById(obj))
			obj = document.getElementById(obj);
		else 
			return false;
	}
	if(indice >= 0) {
		obj.style.filter='alpha(opacity='+indice+')';
		obj.style.opacity=Number(indice) / 100;
		setTimeout('alpha_cacher("'+obj.id+'","'+(Number(indice)-vitesse)+'")',temps);
	}else {
//		obj.style.display='none';
		obj.style.visibility='hidden';
	}
}


function doAlpha(_obj,_valeur) {
	orig_bg = _obj.getAttribute('orig_bg')

	if(orig_bg == '') {

		orig_bg = _obj.style.backgroundImage;

		_obj.setAttribute('orig_bg',orig_bg);
	}
	if(_valeur) {
		_obj.style.backgroundImage = '';
	} else {
		_obj.style.backgroundImage = orig_bg;
	}
}

function afficherhome() {
	setTimeout('alpha_afficher(\'head\',0)',700);
	setTimeout('alpha_afficher(\'left\',0)',1500);
	setTimeout('alpha_afficher(\'home\',0)',2000);
}

function afficherportfolio() {
	setTimeout('alpha_afficher(\'photo\',0)',700);
	setTimeout('alpha_afficher(\'desc\',0)',500);
	setTimeout('alpha_afficher(\'pagination\',0)',300);
}

_click=true;
function fade_open(p,photo) {
	if(_click) {
		_click=false;
		getPhotoCode(p,photo);
	}
	return false;
}

function createXhrObject()
{
    if (window.XMLHttpRequest)
        return new XMLHttpRequest();
 
    if (window.ActiveXObject)
    {
        var names = [
            "Msxml2.XMLHTTP.6.0",
            "Msxml2.XMLHTTP.3.0",
            "Msxml2.XMLHTTP",
            "Microsoft.XMLHTTP"
        ];
        for(var i in names)
        {
            try{ return new ActiveXObject(names[i]); }
            catch(e){}
        }
    }
    window.alert("Votre navigateur ne prend pas en charge l'objet XMLHTTPRequest.");
    return null; // non supporté
}


function getPhotoCode(p,photo) {
	alpha_cacher('content_photo',100);
	setTimeout('goGetPhotoCode("'+p+'","'+photo+'")',1000);
//	goGetPhotoCode(p,photo);
}

function goGetPhotoCode(p,photo) {
//	document.getElementById('photo').style.display='none';
	xo = createXhrObject();
	send_data = '?p='+p+'&photo='+photo;
	xo.open('GET','ajax_query.php'+	send_data,true);
	xo.onreadystatechange = function() {
		if(xo.readyState == 4) {
			document.getElementById('content_photo').innerHTML = xo.responseText;
			alpha_afficher('pagination',100);
			alpha_afficher('photo',0);
			alpha_afficher('desc',0);
			alpha_afficher('content_photo',0);

			_click=true;
		}
	}
	xo.send(null);
}
