////////////////////////////////////////////////////////////////////////////////
//         FONCTIONS pour le book redéfinissant celle du main                 //
////////////////////////////////////////////////////////////////////////////////

var introMode = false;

function setIntroMode(){
    introMode = true;
}


initElements = function(){
	Element.hide('book_intro_texte');
    Element.hide('content');
    Element.hide('background');
    Element.setStyle("works_box", {visibility: "hidden"} );
	animCurtains = true;
	
	for (i=0 ; i<id.length; i++){
		new Effect.Move('work_'+id[i], {delay:0, duration: 0, x:40*i, y:-150, mode: 'absolute'});
	}
	
}

onload = function(){
    background = document.getElementById("background").src;

    correctPNG();
    resizeBackground();
    
    if (animCurtains) initCurtains();   
}


function initCurtains(){   
    Element.setStyle("curtain_1", {width: '3000px', height: px(window_h), top: px(-window_h),   left: '0px' } );      
    Element.setStyle("curtain_2", {width: '3000px', height: '70px',  top: px(window_h), left: '0px' } );        
    
    new Effect.Move('curtain_1', {delay:0, duration: 1.5, y:(window_h-370), mode: 'relative'});
    new Effect.Opacity('curtain_1', {delay:0, duration: 1.5, from : 0, to : 0.90 } );
    new Effect.Move('curtain_2', {delay:0, duration: 1.5, x: 0, y:-70, mode: 'relative' });
    new Effect.Opacity('curtain_2', {delay:0, duration: 1.5, from : 0, to : 0.90 } );     
    
    if (!introMode) {
        for (i=0 ; i<id.length; i++){
            new Effect.Move('work_'+id[i], {delay:0, duration: 0, x:posx[i], y:posy[i], mode: 'absolute'});
        }
        new Effect.Appear('content', {delay:1.5, duration: 0 } );    
        window.setTimeout( function(){Element.setStyle("works_box", {visibility: "visible"} );}, 1500);
    }
    else window.setTimeout(showIntro,1800);
    
    window.setTimeout(function() {
                          Element.setStyle("curtain_1", {top: '', bottom: '370px'} );      
                          Element.setStyle("curtain_2", {top: '', bottom: '0px'} );
                          document.getElementById("curtain_2").style.bottom = px(0);      
                      }, 2000); 
}

function showIntro(){   
    Element.setStyle("works_box", {visibility: "visible"} );
    
    var tps=0;
    
    for (i=0 ; i<id.length; i++){
        tps = (0.2*i);
        new Effect.Move('work_'+id[i], {delay:tps, duration: 0.9, x:posx[i], y:posy[i], mode: 'absolute'});
    }
    
    tps = tps+0.9;
    
    new Effect.Appear('content', {delay:tps, duration: 0 } );
    new Effect.Appear('book_intro_texte', {delay:tps, duration: 0.8 } );
    
} 


////////////////////////////////////////////////////////////////////////////////
//                            FONCTIONS   souris et liens                     //
////////////////////////////////////////////////////////////////////////////////


document.onmousemove = function(e){
        if (!e) e = window.event;
        xm = (e.x || e.pageX || e.clientX);
        ym = (e.y || e.pageY || e.clientY);
    return false;
}

function showWorkInfo(id, title, type){
    if (title!="") document.getElementById("book_infos").innerHTML = "<nobr><span class='magenta'><b>"+title+"</b></span><nobr><br>"+type;
    else document.getElementById("book_infos").innerHTML = "<nobr>"+type+"</nobr>";
    document.getElementById("book_infos").style.top = px(ym);
    document.getElementById("book_infos").style.left = px(xm);
    document.getElementById("book_infos").style.visibility = "visible";
}

function hideWorkInfo(){
    document.getElementById("book_infos").style.visibility = "hidden";
}
