/*
 +--------------------------------------------------------------------------------------+
                                           ClearFx   (v0.04)

 Created: Jun. 15, 2008 
 Last modified: Jul. 13, 2009
 +--------------------------------------------------------------------------------------+

===========================================================
 This script was tested with the following systems and browsers:

 - Windows XP: Firefox 2 / Firefox 3 / Chrome 2 / Safari 3 / Safari 4 / IE8
 - Mac OS X:  Safari 3 / Safari 4 / Firefox 3
 - Linux: Firefox 2 / Firefox 3
 
  /!\ Error with IE6 /!\
  /!\ Error with IE7 /!\
============================================================
Principe des fonctions:

"transparency_up", "transparency_down" : permet de rendre des éléments plus ou moins transparents de manière progressive.
	-"object": nom de l'objet à affecter (son id)
	-"value": valeur de transparence à atteindre (en %)

"height_up(object, size, speed)", "height_down(object, size, speed)", "width_up(object, size, speed)", "width_down(object, size, speed)" : permer d'élargir ou d'agrandir des IMAGES de manière progressive (ne fonctionne que pour les images).
	-"object": nom de l'objet à affecter (son id)
	-"size": taille (largeur ou hauteur) à atteindre (en px) (Attention, webkit ne gère par une taille de "0")
	-"speed": permet de régler la vitesse, correspond au nombre de pixels à ajouter à chaque cycle de la fonction (nombre entier requis)

"roll_out(object, min, max)", "roll_up(object, min, max)", "slide_up(object, min, max)", "slide_out(object, min, max)" : permer d'élargir ou d'agrandir des BLOCS (effet de glissière) de manière progressive (roll pour l'effet vertical et slide pour l'horizontal).
	-"object": nom de l'objet à affecter (son id)
	-"min": taille minimale (px)
	-"max": taille maximale (px)
	
"show_on(object)", "show_off(object)" : permet de faire apparaître ou disparaître des éléments de manière progressive (ressemble à "transparency", mais permet de supprimer totalement l'élément à cacher à la fin par un 'display:none';)
	-"object": nom de l'objet à affecter (son id)

*/

// 1 ------ base functions:

function getId(object)
{
    if (typeof(object) == 'string')
        return document.getElementById(object);
    else
        return object;
}


// 2 ------ loading functions:

function preloading(object)
{
    document.getElementById(object).style.display = 'none';
}


// 3 ------  transparency functions:

function settransparency(object, transparency)
{
    object.style.opacity = transparency / 100;
    object.style.MozOpacity = transparency / 100;
    object.style.KhtmlOpacity = transparency / 100;
    object.style.filter = "alpha(opacity=" + transparency + ")";
}

function transparency_up(object, value)
{
    object = getId(object);

    if (typeof(object.timer_trans) != 'undefined')
	{
        clearTimeout(object.timer_trans);
    }

    if (object.transparency > value)
	{
        object.transparency -= 10;
        settransparency(object, object.transparency);
        object.timer_trans = setTimeout(function() { transparency_up(object, value) }, 15);
    }
	else {
	    object.transparency = value;
	    settransparency(object, object.transparency);
	}
}

function transparency_down(object, value)
{
    object = getId(object);

    if (typeof(object.timer_trans) != 'undefined')
    {
        clearTimeout(object.timer_trans);
    }

    if (object.transparency < value)
    {
        object.transparency += 10;
        settransparency(object, object.transparency);
        object.timer_trans = setTimeout(function() { transparency_down(object, value) }, 15);
    }
	else {
	    object.transparency = value;
	    settransparency(object, object.transparency);
	}
}


// 4 ------  resize functions:

function height_up(object, size, speed)
{
    object = getId(object);
	
    if (typeof(object.timer_largeur) != 'undefined')
    {
        clearTimeout(object.timer_largeur);
    }

    if (object.height < size)
    {
        object.height += speed;
        object.timer_largeur = setTimeout(function() { height_up(object, size, speed); }, 15);
    }
    else{
        object.height = size;
	}
}

function height_down(object, size, speed)
{
    object = getId(object);

    if (typeof(object.timer_largeur) != 'undefined'){
        clearTimeout(object.timer_largeur);
    }

    if (object.height > size){
        object.height -= speed;
        object.timer_largeur = setTimeout(function() { height_down(object, size, speed); }, 15);
    }
    else{
        object.height = size;
	}
}

function width_up(object, size, speed)
{
    object = getId(object);
	
    if (typeof(object.timer_largeur) != 'undefined')
    {
        clearTimeout(object.timer_largeur);
    }

    if (object.width < size)
    {
        object.width += speed;
        object.timer_largeur = setTimeout(function() { width_up(object, size, speed); }, 15);
    }
    else{
        object.width = size;
	}
}

function width_down(object, size, speed)
{
    object = getId(object);
	
    if (typeof(object.timer_largeur) != 'undefined')
    {
        clearTimeout(object.timer_largeur);
    }

    if (object.width > size)
    {
        object.width -= speed;
        object.timer_largeur = setTimeout(function() { width_down(object, size, speed); }, 15);
    }
    else{
        object.width = size;
	}
}


// 5 ------ roll_up functions:

function roll_up(object, min, max, speed)
{
	object = getId(object);
	
	if( typeof(speed) == 'undefined')
	{
		speed = 10; //-par défaut:10px
	}
	
	if (typeof(object.timer_hauteur) != 'undefined')
	{
        clearTimeout(object.timer_hauteur);
    }

	if (typeof(object.taille) == 'undefined'){object.taille = min;}
	else{
		object.taille += speed;
	}
		
	if (object.taille < max)
	{
		object.style.height = object.taille +"px";
		object.timer_hauteur = setTimeout(function() { roll_up(object, min, max, speed); }, 10);
	}
	else{
		object.style.height = max+"px";
	}
}

function roll_out(object, min, max, speed)
{
	object = getId(object);
	
	if( typeof(speed) == 'undefined')
	{
		speed = 10; //-par défaut:10px
	}

	if (typeof(object.timer_hauteur) != 'undefined')
	{
        clearTimeout(object.timer_hauteur);
    }

	if (typeof(object.taille) == 'undefined'){object.taille = min;}
		else{
			object.taille -= speed;
		}
		
	if (object.taille > min)
	{
		object.style.height = object.taille +"px";
		object.timer_hauteur = setTimeout(function() { roll_out(object, min, max, speed); }, 10);
	}
	else{
		object.style.height = min+"px";
	}
}

function slide_up(object, min, max, speed)
{
	object = getId(object);
	
	if( typeof(speed) == 'undefined')
	{
		speed = 10; //-par défaut:10px
	}
	
	
	
	if (typeof(object.timer_largeur) != 'undefined')
	{
        clearTimeout(object.timer_largeur);
    }

	if (typeof(object.taille) == 'undefined'){object.taille = min;}
	else{
		object.taille += speed;
	}
		
	if (object.taille < max)
	{
		object.style.width = object.taille +"px";
		object.timer_largeur = setTimeout(function() { slide_up(object, min, max, speed); }, 10);
	}
	else{
		object.style.width = max+"px";
	}
}

function slide_out(object, min, max, speed)
{
	object = getId(object);
	
	if( typeof(speed) == 'undefined')
	{
		speed = 10; //-par défaut:10px
	}

	
	if (typeof(object.timer_largeur) != 'undefined')
	{
        clearTimeout(object.timer_largeur);
    }

	if (typeof(object.taille) == 'undefined'){object.taille = min;}
		else{
			object.taille -= speed;
		}
		
	if (object.taille > min)
	{
		object.style.width = object.taille +"px";
		object.timer_largeur = setTimeout(function() { slide_out(object, min, max, speed); }, 10);
	}
	else{
		object.style.width = min+"px";
	}
}

// 6 ------ show functions:

function show_on(object)
{
    object = getId(object);


	
    if (typeof(object.timer_trans) != 'undefined')
	{
        clearTimeout(object.timer_trans);
    }

    if (object.transparency < 100)
	{
        object.transparency += 10;
		object.style.display='block';
        settransparency(object, object.transparency);
        object.timer_trans = setTimeout(function() { show_on(object) }, 15);
    }
	else {
	    object.transparency = 100;
		object.style.display='block';
	    settransparency(object, object.transparency);
	}
}

function show_off(object)
{
    object = getId(object);


	
    if (typeof(object.timer_trans) != 'undefined')
	{
        clearTimeout(object.timer_trans);
    }

    if (object.transparency > 0)
	{
        object.transparency -= 10;
		object.style.display='block';
        settransparency(object, object.transparency);
        object.timer_trans = setTimeout(function() { show_off(object) }, 15);
    }
	else {
	    object.transparency = 0;
		object.style.display='none';
	    settransparency(object, object.transparency);
	}
}
