



document.observe("dom:loaded", function() {
  
    // Cache les subpanels quand la page est chargée
    var sunpanel = new ARSSubPanel();
    sunpanel.hide('acces_rapide_contenu');
    sunpanel.hide('form_connexion_contenu');
  
});


function afficheCache(idElt, objContainer,  formConnexion, imgVisible, imgHidden)
{
    if ( formConnexion == 'undefined' ) {formConnexion = false;}
  
    //var content = currentElt.innerHTML;
    var effectDuration = 0.5;
    //$(idElt).toggle();                 
    if($(idElt).style.display == "none")
    {
            
        if(formConnexion == true)
        {
        
            var formIdentification = new ARSSubPanel();
            formIdentification.init('form_connexion', 'form_connexion_contenu', 'right');
      
            // Change le bouton -> afficher le bouton "Fermer"
            objContainer.style.backgroundImage = "url(" + imgHidden + ")";            
        }
        else{
            var accesRapide = new ARSSubPanel();
            accesRapide.init('acces_rapide', 'acces_rapide_contenu', 'left');
        }        
        $(idElt).appear({ duration: effectDuration });
    }
    else
    {
        $(idElt).fade({ duration: effectDuration, from: 1, to: 0 });
        if(formConnexion == true)
        {
            // Change le bouton -> afficher le bouton "Se connecter"
            objContainer.style.backgroundImage = "url(" + imgVisible + ")";
        }
    }    
}



function viderChamp(field)
{
    if(field.value == "identifiant" || field.value == "mot de passe"){field.value = "";}
}

function ARSSubPanel() 
{
    this.posXContent = 0;
    this.posXContent = 0;
    this.container = null;
    this.content = null;
    this.ie = false;
    this.type = "";
    
    
    this.hide = function(idObject)
    {
        $(idObject).style.display = "none";
    }
    
    this.init = function (idContainer, idContent, type)
    {
        this.container  = document.getElementById(idContainer);
        this.content    = document.getElementById(idContent);        
        this.ie         = (navigator.appName.indexOf("Microsoft") != -1)? true:false;
        this.type       = type;                       
        this.setContentPos();
        
        this.content.style.display = "none";  // Hide subpanel
    }
    
    this.setContentPos = function()
    {
        var positions = this.getPosition(this.container);                
        var containerDim = this.container.getDimensions();
        
        this.posXContent = positions[0] ;
        
        if(this.type == "right")
        {
            var contentDim = this.content.getDimensions();
            
            
            this.posXContent +=   containerDim.width  - contentDim.width   ;  
        }
            
        
        this.posYContent = positions[1] + containerDim.height;        
        this.content.style.top = this.posYContent -1 + "px" ;
        this.content.style.left = this.posXContent+'px' ;                        
    }
            
    
    this.getPosition = function(obj)
    {    
        return Element.positionedOffset(obj);      
    }
}


document.observe("dom:loaded", function() {

	$('user').observe('focus',  function(event) {
		viderChamp(this);
	});
	
	$('pass').observe('focus',  function(event) {
		viderChamp(this);
	});

});
