var fond_opacity_incr = 0.10;
var fond_opacity_time = 15;
var fond_opacity_max = 0.70;
var fond_opacity_min = 0;


var fond_timer;

function getStyleInfo(obj, style) {
    if (obj.currentStyle)
        return obj.currentStyle[style];
    if (document.defaultView && document.defaultView.getComputedStyle)
	return document.defaultView.getComputedStyle(obj, null)[style];
}

/* Fonctions de fondu du fond */
function fond_on_opacity() {
    var dom_main_overlay = $('fond_edition');

    //Event.stopObserving(dom_main_overlay, 'click', fond_clear_opacity, 'false');

    var size = getPageSize();

    var width = size[0];
    var height = size[1];

    dom_main_overlay.style.width = width+"px" ;
    dom_main_overlay.style.height = height+"px" ;

    dom_main_overlay.style.display = "block";

    fond_incr_opacity(fond_opacity_min);
}
/**
 * Code from Lightbox v2.04
 * by Lokesh Dhakar - http://www.lokeshdhakar.com
 * For more information, visit:
 * http://lokeshdhakar.com/projects/lightbox2/
 * Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/
 *  - Free for use in both personal and commercial projects
 *  - Attribution requires leaving author name, author link, and the license info intact.
 */
function getPageSize() {
    var xScroll, yScroll;
   
    if (window.innerHeight && window.scrollMaxY) {
        xScroll = window.innerWidth + window.scrollMaxX;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }

    var windowWidth, windowHeight;

    if (self.innerHeight) {	// all except Explorer
        if(document.documentElement.clientWidth){
            windowWidth = document.documentElement.clientWidth;
        } else {
            windowWidth = self.innerWidth;
        }
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }
    
    // for small pages with total height less then height of the viewport
    if(yScroll < windowHeight){
        pageHeight = windowHeight;
    } else {
        pageHeight = yScroll;
    }

    // for small pages with total width less then width of the viewport
    if(xScroll < windowWidth){
        pageWidth = xScroll;
    } else {
        pageWidth = windowWidth;
    }
    
    return [pageWidth,pageHeight];
}

/* fonction qui modifie l'opacité de l'élément */
function fond_set_opacity(opacity)
{
    var dom_main_overlay = $('fond_edition');

    if(dom_main_overlay.filters)
        {dom_main_overlay.filters['alpha'].opacity = opacity * 100;}
    else
        {dom_main_overlay.style.opacity = opacity;}
}

/* fonction récursive qui augmente l'opacité de l'élément */
function fond_incr_opacity(opacity)
{
    var dom_main_overlay = $('fond_edition');
    if (opacity >= fond_opacity_max) // test de fin de fondu
        {
            window.clearTimeout(fond_timer);
            $('widget_box').style.display = "block";
            //Event.observe(dom_main_overlay, 'click', fond_clear_opacity, 'false');
            return;
        }
    new_opacity = opacity + fond_opacity_incr;
    fond_set_opacity(new_opacity);
    fond_timer = window.setTimeout("fond_incr_opacity("+new_opacity+")",fond_opacity_time); // re-appel de la fonction : récursivité
}

/* fonction qui enléve le layer */
function fond_clear_opacity(evt)
{
    var dom_main_overlay = $('fond_edition');
    $('widget_box').style.display = "none";
    dom_main_overlay.style.display = "none";
    $('widget_box').src = "";
    hide_flash(false);
}

/* Fin des fonctions de fondu */
function edition(champ)	{
    window.scrollTo(0,0);
    hide_flash(true);
    $('widget_box').src = "/iframe/?edit=" + champ;
    fond_on_opacity();
}

// les objets
function hide_flash(hide){
    var visibility = "visible";
    if (hide) {
        visibility = "hidden";
    }
    $$('select', 'object', 'embed').each(function(node){ node.style.visibility = visibility; });
}
