/*------------------SLIDER 1/3------------------------------------*/
var Slider = {
    create: function(Menu) {
        return {
            id: "no name",
            orientation: "horizontal",
            min: 0,
            max: 500,
            speed: 300,
            myObject: Menu,
            moveTo: function(start, end) {
                c = (this.speed / 50);
                d = Math.round(this.speed / c);
                w = new Array();
                t = new Array();
                this.myObject.currentStep = 0;
                this.myObject.testTime = null;
                for (var i = 1; i <= d; i++) {
                    w.push(this.easeOutCubic(i * c, start['left'], end['left'] - start['left'], this.speed));
                    t.push(this.easeOutCubic(i * c, start['width'], end['width'] - start['width'], this.speed))
					
                }
                this.go(this, c, w, t);
            },
            go: function(b, c, w, t) {
                b.myObject.testTime = window.setInterval(function() {
                    var a = true;
                    if (w[b.myObject.currentStep]) {
                        b.myObject.style['left'] = w[b.myObject.currentStep] + 'px';
                        b.myObject.style['width'] = t[b.myObject.currentStep] + 'px';
                        b.myObject.currentStep++;
                        a = false
                    }
                    if (a) {
                        window.clearInterval(b.myObject.testTime);
                        b.myObject.testTime = null;
                        if (b.callBack) {
                            b.callBack()
                        }
                        return
                    }
                },
                c);
            },
            easeOutCubic: function(t, b, c, d) {
                return c * ((t = t / d - 1) * t * t + 1) + b;
            }
       
	   }
    }
};
/*------------------FIN SLIDER 1/3------------------------------------*/
/*--------------objet ajax--------------------------------------------*/
function getXhr(){
	var xhr = null; 
	if(window.XMLHttpRequest)
		xhr = new XMLHttpRequest(); 
		else if(window.ActiveXObject){
		try {
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
		else {
		alert("Votre navigateur ne supporte pas Ajax");
		xhr = false;
	}
	return xhr
}
/*--------------fin objet ajax--------------------------------------------*/



function charge_page(Pagecible,Params,Divcible,vidtitre) 
{       
var xhr = getXhr()
	xhr.open('POST', Pagecible, true); 
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send(Params);
	xhr.onreadystatechange = function() { 

	
		if (xhr.readyState == 4) 	{                   
		if (xhr.status == 200)	{                  
		document.getElementById(Divcible).innerHTML = xhr.responseText;
		
		} else { /*alert ("Erreur : " + xhr.status);*/ 	}
		} else { 
document.getElementById(Divcible).innerHTML = "<div style='position:relative; top:25%; vertical-align:center; text-align:center;'>Chargement en cours ... <img src='/images/loader.gif' style='vertical-align:middle;' /></div>";}
		



document.getElementById('commflecheup').onmousedown = function(event) { scrollDivUp('defcom');}
document.getElementById('commflecheup').onmouseup = function(event) { stopMe();}

document.getElementById('commflechedown').onmousedown = function(event) { scrollDivDown('defcom');}
document.getElementById('commflechedown').onmouseup = function(event) { stopMe();}


/*FIN GESTION BOUTON DEROULANT APRES AJAX*/

}
//alert(Pagecible);

if (Pagecible == 'blocv_blocvideo.php') 
{
	charge_page('acc_nous.php','','commentaire');  //reset la partie commentaire au changement de video
variable=getVar('idvideo',Params)
url ='idvideo='+variable;
parent.location.hash = url;                  
document.title=vidtitre;
}

}

//----GESTION DES FORMULAIRES PAR AJAX PASSAGE DE GET A POST ---------------------------//
function SendAjaxForm(Pagecible,Params,Divcible,Formsource){
var Pagecible 
var Divcible  
var Params=""
var i=0;
var Elt;
while (Elt=document.forms[Formsource].elements[i] )
{
if(Elt.type=='checkbox'){Params+="&"+Elt.name+"="+Elt.checked;}
else if(Elt.value && Elt.type!='submit'){Params+="&"+Elt.name+"="+encodeURIComponent(Elt.value);}
i++;
}
Params=Params.replace(/^&/,"")
charge_page(Pagecible,Params,Divcible)             
}
//----FIN GESTION DES FORMULAIRES PAR AJAX PASSAGE DE GET A POST ---------------------------//








		function getVar (nomVariable,Params)
		{
				var infos = Params.substring(Params.indexOf("#")+1, location.href.length)+"&"
				if (infos.indexOf("#")!=-1)
				infos = infos.substring(0,infos.indexOf("#"))+"&"
				var variable=0
					{
					nomVariable = nomVariable + "="
					var taille = nomVariable.length
					if (infos.indexOf(nomVariable)!=-1)
					variable = infos.substring(infos.indexOf(nomVariable)+taille,infos.length).substring(0,infos.substring(infos.indexOf(nomVariable)+taille,infos.length).indexOf("&"))
					}
		return variable
		}
				
 var slidcategorie = categorie;
 
 /*SCROLL*/
 /*---------------------------DEBUT DEFILEMENT LISTE-------------------------------*/
 defaultStep=1
step=defaultStep


function scrollDivDown(id)	{
							clearTimeout(timerDown)
							document.getElementById(id).scrollTop+=step
							timerDown=setTimeout("scrollDivDown('"+id+"')",10)
							}


function scrollDivUp(id)	{
							clearTimeout(timerUp)
							document.getElementById(id).scrollTop-=step
							timerUp=setTimeout("scrollDivUp('"+id+"')",10)
							}

timerDown=""
timerUp=""

function stopMe()			{
							clearTimeout(timerDown)
							clearTimeout(timerUp)
							}

 /*---------------------------DEBUT DEFILEMENT LISTE-------------------------------*/
window.onload = function() { 




/*------------------SLIDER 2/3------------------------------------*/
		    var slide1 = Slider.create(document.getElementById('indicator'));
if (slidcategorie != 0)
{    var mouseInfo = document.getElementById('content');

	slidcategorie = slidcategorie.replace(/ /g,"_" );
	slidcategorie = slidcategorie.replace(/%20/g,"_" );
	slidcategorie = slidcategorie.replace(/%C3%A9/g,"e" );
	
	var tonobjetLOL = document.getElementById(slidcategorie);
var start = { 
                "left": 0, 
                "width": 0 
            }; 
            var end = { 
                "left": tonobjetLOL.offsetLeft, 
                "width": tonobjetLOL.offsetWidth 
            }; 
			
	
            slide1.moveTo(start, end); 

}


    var mouseInfo = document.getElementById('content');
    mouseInfo.onmouseover = function(event) {
        var mouseInfos = getMousePosition(event);
        if (mouseInfos) {
            if (slide1.myObject.testTime != null) {
                window.clearInterval(slide1.myObject.testTime);
                slide1.myObject.testTime = null;
            }
            var start = {
                "left": document.getElementById('indicator').offsetLeft,
                "width": document.getElementById('indicator').offsetWidth
            };
            var end = {
                "left": mouseInfos['left'],
                "width": mouseInfos['width']
            };
            slide1.moveTo(start, end);
        }
    };
    mouseInfo.onmouseout = function() {
        var first = document.getElementById('content').getElementsByTagName("li")[0];
        var mouseInfos = null;
        if (!mouseInfo.currentClick || mouseInfo.currentClick == null) {
			
			if (tonobjetLOL){ //dertermine l'emplacement de depart: dans ce cas l'emplacement est le lien et non pas totalement a gauche (nous arrivons d'une autre page)
				//alert(tonobjetLOL)
				 mouseInfos = {
                "left": tonobjetLOL.offsetLeft,
                "width": tonobjetLOL.offsetWidth
            					};
							}
							else{ // aucun lien n'a été cliqué donc l'emplacement de depart est a gauche toute emplacement par defaut!
            mouseInfos = {
                "left": first.offsetLeft,
                "width": first.offsetWidth
            };}
        } else {
            mouseInfos = {
                "left": mouseInfo.currentClick.offsetLeft,
                "width": mouseInfo.currentClick.offsetWidth
            };
        }
        if (mouseInfos) {
            if (slide1.myObject.testTime != null) {
                window.clearInterval(slide1.myObject.testTime);
                slide1.myObject.testTime = null;
            }
            var start = {
                "left": document.getElementById('indicator').offsetLeft,
                "width": document.getElementById('indicator').offsetWidth
            };
            var end = {
                "left": mouseInfos['left'],
                "width": mouseInfos['width']
            };
            slide1.moveTo(start, end);
        }
    };
    mouseInfo.onclick = function(event) {
        var e = event || window.event;
		var tempClick = (e.target) ? e.target: e.srcElement;
        mouseInfo.currentClick = (tempClick.nodeName == "LI") ? tempClick : ( (tempClick.nodeName == "A") ? tempClick.parentNode : (mouseInfo.currentClick != "undefined") ? mouseInfo.currentClick:null);
        var mouseInfos = getMousePosition(event);
        if (mouseInfos) {
            if (slide1.myObject.testTime != null) {
                window.clearInterval(slide1.myObject.testTime);
                slide1.myObject.testTime = null;
            }
            var start = {
                "left": document.getElementById('indicator').offsetLeft,
                "width": document.getElementById('indicator').offsetWidth
            };
            var end = {
                "left": mouseInfos['left'],
                "width": mouseInfos['width']
            };
            slide1.moveTo(start, end);
        }
    };
/*------------------FIN SLIDER 2/3------------------------------------*/


							};
function isInteger(x){
return ((x)!="" && parseInt(x*1)==x);}

/*========================================================================================================================*/

function compteCarac(idTextarea, idSpan, nbrmax)
{
var t = document.getElementById(idTextarea);
var s = document.getElementById(idSpan);
s.innerHTML = nbrmax-t.value.length;
t.value = t.value.slice(0, nbrmax)
}


function smileys(formcible, zonecible, icon){
document.forms[formcible].elements[zonecible].value+=" "+icon;
compteCarac('commentaire', 'nbCarac8', '255'); 
}


/*------------------FIN SLIDER 3/3------------------------------------*/

function getMousePosition(event) {
    var e = event || window.event;
    monElement = (e.target) ? e.target: e.srcElement;
 		 if(monElement.nodeName == "SPAN"){
			
		return {
            "left": monElement.parentNode.parentNode.offsetLeft,
            "width": monElement.parentNode.parentNode.offsetWidth
        };
	}
 else if (monElement.nodeName == "A") {
        return {
            "left": monElement.parentNode.offsetLeft,
            "width": monElement.parentNode.offsetWidth
        };
    }
	else if(monElement.nodeName == "LI"){

		return {
            "left": monElement.offsetLeft,
            "width": monElement.offsetWidth
			
        };
	}

    return false;
};

/*------------------FIN SLIDER 3/3------------------------------------*/