/*(c) Ger Versluis 2003-2004*/


/********************************************************
*    Create a div with transparent place holder in your html        *
*    <div id="Book" style="position:relative">            *
*        <img src="placeholder.gif" width="404" height="152">    *
*    </div>                            *
*    width = 2*book image width +4 height = book image height+2    *
*                                *
*    Insert onload in body tag                    *
*        <body onload="ImageBook()">            *
*                                *
*                                *
*    8 variables you can edit to control behavior             *
*********************************************************/
    /*
    var Book_Image_Width=200;        // Image width
    var Book_Image_Height=150;    // Image height
    var Book_Border=true;        // Sets border true or false
    var Book_Border_Color="white";    // Border color
    var Book_Speed=15;        // Controls the speed of the page turn
    var Book_NextPage_Delay=500;    // Controls the delay before a new turn starts
    */
    var Book_BackWard=false;        // false or true; false is normal page turn
    var Book_Auto=true;        // false or true; false stops after page turn

/*********************************************************************************************************
*    There are also 6 functions to change the behavior of the book dynamically.                            *
*    You don't need to use them. If you set Book_Auto to true the script will simply run.                        *
*    They can be called from other scripts or through HTML elements that support event handling.                    *
*    For instance an image, anchor or button support onclick: <input type="button" value="MyValue" onclick="Book_ChangeDirection()">    *
*    The functions are:                                                    *
*        Book_ChangeDirection()    Toggles the page turn direction. If Book_Auto is false it also turns 1 page            *
*        Book_GoBackWard()    Changes the page turn direction to backward if needed. If Book_Auto is false it also turns 1 page    *
*        Book_GoForWard()        Changes the page turn direction to forward if needed. If Book_Auto is false it also turns 1 page    *
*        Book_ChangeAuto()    Toggles between manual and auto                            *
*        Book_Automated()        Changes the book to auto                                *
*        Book_Manual()        Changes the book to manual                                *
*                                                            *
*                                                            *
*    Array to specify images and optional links and targets. At least 4 images are needed.                         *
*    For best results keep the number even.                                        *
*    Target can be "top" , "new" or "framename" Quotation marks must be included.                        *
*    If target is empty ("") the current window or frame is used as target.                            *
*    If link is not wanted keep it ""                                            *
**********************************************************************************************************/
    /*
    Book_Image_Sources=new Array(
        "Image1","Link1","",
        "Image2","Link2","",
        "Image3","Link3","",
        "Image4","Link4","",
        "Image5","Link5","",
        "Image6","Link6","",
        "Image7","Link7","",
        "Image8","Link8",""    // NOTE No comma after last line
        );
        */

/********************************** DO NOT EDIT BELOW *******************************************************/

    var B_LI,B_MI,B_RI,B_TI;
    var B_Angle=0,B_CrMImg,B_CrSImg,B_MaxW,B_Drctn=true,B_DirChngd=false;
    var B_Srcs=Book_Image_Sources,B_SrcL=B_Srcs.length-1,B_ChngDirFlg=false;
    var B_MSz,B_Stppd=Book_Auto?false:true;B_Pre_Img=new Array(B_SrcL);

    function ImageBook(){
        if(document.getElementById){
            for(var i=0;i<B_SrcL;i+=3){B_Pre_Img[i]=new Image();B_Pre_Img[i].src=B_Srcs[i]}
            Book_Div=document.getElementById("Book");
            B_LI=document.createElement("img");Book_Div.appendChild(B_LI);
            B_RI=document.createElement("img");Book_Div.appendChild(B_RI);
            B_MI=document.createElement("img");Book_Div.appendChild(B_MI);
            B_LI.style.position=B_MI.style.position=B_RI.style.position="absolute";
            B_LI.style.zIndex=B_RI.style.zIndex=0;B_MI.style.zIndex=1;
            B_LI.style.top=B_LI.style.left=B_MI.style.top=B_RI.style.top=0+"px";
            B_MI.style.left=(Book_BackWard?0:Book_Image_Width+1)+"px";
            B_RI.style.left=Book_Image_Width+1+"px";
            B_LI.style.height=B_MI.style.height=B_RI.style.height=Book_Image_Height+"px";
            B_LI.style.width=B_MI.style.width=B_RI.style.width=Book_Image_Width+"px";
            if(Book_Border){
                B_LI.style.borderStyle=B_MI.style.borderStyle=B_RI.style.borderStyle="solid";
                B_LI.style.borderWidth=B_MI.style.borderWidth=B_RI.style.borderWidth=1+"px";
                B_LI.style.borderColor=B_MI.style.borderColor=B_RI.style.borderColor=Book_Border_Color}
            B_LI.src=Book_BackWard?B_Srcs[B_SrcL-12]:B_Srcs[0];
            B_LI.lnk=Book_BackWard?B_Srcs[B_SrcL-11]:B_Srcs[1];
            B_LI.trgt=Book_BackWard?B_Srcs[B_SrcL-10]:B_Srcs[2];
            B_MI.src=Book_BackWard?B_Srcs[B_SrcL-6]:B_Srcs[3];
            B_MI.lnk=Book_BackWard?B_Srcs[B_SrcL-5]:B_Srcs[4];
            B_MI.trgt=Book_BackWard?B_Srcs[B_SrcL-4]:B_Srcs[5];
            B_RI.src=Book_BackWard?B_Srcs[B_SrcL-3]:B_Srcs[9];
            B_RI.lnk=Book_BackWard?B_Srcs[B_SrcL-2]:B_Srcs[10];
            B_RI.trgt=Book_BackWard?B_Srcs[B_SrcL-1]:B_Srcs[11];
            B_CrMImg=Book_BackWard?B_SrcL-9:6;
            B_CrSImg=Book_BackWard?B_SrcL-18:15;
            B_LI.onclick=B_MI.onclick=B_RI.onclick=B_LdLnk;
            B_LI.onmouseover=B_MI.onmouseover=B_RI.onmouseover=B_Stp;
            B_LI.onmouseout=B_MI.onmouseout=B_RI.onmouseout=B_Rstrt;
            BookImages()}}

    function BookImages(){
        if(!B_Stppd){
            if(B_ChngDirFlg)B_ChngDrctn();
            B_MSz=Math.abs(Math.round(Math.cos(B_Angle)*Book_Image_Width));
            MidOffset=!Book_BackWard?B_Drctn?Book_Image_Width+1:Book_Image_Width-B_MSz:
                B_Drctn?Book_Image_Width-B_MSz:Book_Image_Width+1;
            B_MI.style.left=MidOffset+"px";
            B_MI.style.width=B_MSz+"px";
            B_Angle+=Book_Speed/720*Math.PI;
            if(B_Angle>=Math.PI/2&&B_Drctn){
                B_Drctn=false;
                B_MI.src=B_Srcs[B_CrMImg];B_MI.lnk=B_Srcs[B_CrMImg+1];B_MI.trgt=B_Srcs[B_CrMImg+2];
                B_CrMImg+=(Book_BackWard?-6:6);
                if(B_CrMImg>=B_SrcL)B_CrMImg-=B_SrcL;
                if(B_CrMImg<0)B_CrMImg+=B_SrcL}
            if(B_Angle>=Math.PI){
                B_Drctn=true;
                if(!Book_BackWard){
                    B_TI=B_LI;B_LI=B_MI;B_MI=B_TI;
                    B_MI.style.left=Book_Image_Width+1+"px";
                    B_MI.src=B_RI.src;    B_MI.lnk=B_RI.lnk;B_MI.trgt=B_RI.trgt}
                else{    B_TI=B_RI;B_RI=B_MI;B_MI=B_TI;
                    B_MI.style.left=0+"px";
                    B_MI.src=B_LI.src;B_MI.lnk=B_LI.lnk;B_MI.trgt=B_LI.trgt}
                setTimeout("Book_Next_Delay()",Book_NextPage_Delay)}
            else setTimeout("BookImages()",50)}
        else setTimeout("BookImages()",50)}

    function Book_Next_Delay(){
            if(!Book_BackWard){
                B_RI.src=B_Srcs[B_CrSImg];    B_RI.lnk=B_Srcs[B_CrSImg+1];B_RI.trgt=B_Srcs[B_CrSImg+2];
                B_LI.style.zIndex=1}
            else{    B_LI.src=B_Srcs[B_CrSImg];    B_LI.lnk=B_Srcs[B_CrSImg+1];B_LI.trgt=B_Srcs[B_CrSImg+2];
                B_RI.style.zIndex=1}
            B_MI.style.zIndex=2;B_Angle=0;
            B_CrSImg+=(Book_BackWard?-6:6);
            if(B_CrSImg>=B_SrcL&&!Book_BackWard)B_CrSImg-=B_SrcL;
            if(B_CrSImg<0&&Book_BackWard)B_CrSImg+=B_SrcL;
        if(!Book_Auto&&!B_DirChngd)B_Stppd=true;B_DirChngd=false;
        setTimeout("BookImages()",50)}

    function B_ChngDrctn(){
        B_Stppd=true;
        Book_BackWard=Book_BackWard?false:true;B_Drctn=B_Drctn?false:true;
        B_Angle=Math.PI-B_Angle;
        B_ChngDirFlg=B_Stppd=false;
        B_CrMImg+=(Book_BackWard?-9:9);
        if(B_CrMImg>=B_SrcL)B_CrMImg-=B_SrcL;
        if(B_CrMImg<0)B_CrMImg+=B_SrcL;
        B_CrSImg+=(Book_BackWard?-21:21);
        if(B_CrSImg>=B_SrcL)B_CrSImg-=B_SrcL;
        if(B_CrSImg<0)B_CrSImg+=B_SrcL;
        B_DirChngd=true}

    function Book_ChangeDirection(){B_Stppd=false;B_ChngDirFlg=true}
    function Book_GoBackWard(){B_Stppd=false;if(!Book_BackWard)Book_ChangeDirection()}
    function Book_GoForWard(){B_Stppd=false;if(Book_BackWard)Book_ChangeDirection()}
    function Book_ChangeAuto(){B_Stppd=false;Book_Auto=Book_Auto?false:true}
    function Book_Automated(){B_Stppd=false;Book_Auto=true}
    function Book_Manual(){Book_Auto=false}
    function B_Stp(){if(Book_Auto)B_Stppd=true;this.style.cursor=this.lnk?"pointer":"default"}
    function B_Rstrt(){if(Book_Auto)B_Stppd=false}
    function B_LdLnk(){
        var B_Frame;
        if(this.lnk){
            if(!this.trgt)location.href=this.lnk;
            else if(this.trgt=="top")top.location.href=this.lnk;
            else if(this.trgt=="new")window.open(this.lnk);
            else if(B_Frame=parent.frames[this.trgt])B_Frame.location.href=this.lnk;
            else location.href=this.lnk}}
