step = 1;
images_loc = "images/cube/";
nb_max = 60;
img_num = 56;
mouse_x = 0;
mouse_x_ref = 0;
images_loaded = 0;
auto_drag = true;

var links = new Array();
links[1] = "poly#2,31,188,14,205,199,32,209#infos.php@poly#194,13,209,4,222,153,209,196#photos/photos.php";
links[2] = "poly#2,32,179,13,200,204,33,206#infos.php@poly#184,13,222,4,236,156,203,202#photos/photos.php";
links[3] = "poly#3,30,168,13,189,206,31,203#infos.php@poly#172,11,233,4,245,159,194,204#photos/photos.php";
links[4] = "poly#2,28,154,10,174,207,29,199#infos.php@poly#158,10,238,4,252,162,178,206#photos/photos.php";
links[5] = "poly#1,26,136,7,158,205,26,195#infos.php@poly#141,7,241,5,254,165,162,206#photos/photos.php";
links[6] = "poly#3,24,118,4,137,206,22,192#infos.php@poly#122,4,243,3,255,169,140,206#photos/photos.php";
links[7] = "poly#2,25,98,4,114,206,19,189#infos.php@poly#102,4,239,8,249,174,119,206#photos/photos.php";
links[8] = "poly#1,28,79,4,91,206,15,191#infos.php@poly#82,5,234,10,242,182,95,207#photos/photos.php";
links[9] = "poly#1,31,58,6,67,204,8,192#infos.php@poly#63,3,227,13,233,190,72,205#photos/photos.php";
links[10] = "poly#1,35,38,5,43,207,6,193#infos.php@poly#41,4,219,16,219,197,47,205#photos/photos.php";
links[11] = "poly#1,41,21,6,20,204,2,195#infos.php@poly#23,4,207,16,207,202,24,203#photos/photos.php";
links[12] = "poly#5,2,199,15,195,204,4,203#photos/photos.php@poly##";
links[13] = "poly#7,4,203,13,196,208,1,201#photos/photos.php@poly##";
links[14] = "poly#7,3,205,13,194,210,1,201#photos/photos.php@poly##";
links[15] = "poly#9,5,206,15,192,214,2,197#photos/photos.php@poly#209,17,216,33,204,190,195,213#videos.php";
links[16] = "poly#10,4,202,15,185,218,2,194#photos/photos.php@poly#205,16,231,31,216,189,187,219#videos.php";

//links[16] = "poly##photos/photos.php@poly##videos.php";


document.onmousemove = UpdateMouseX;

function UpdateMouseX(e)
{
    mouse_x = parseInt(document.all ? event.clientX : e.pageX);
}

function StartDrag()
{
    auto_drag = false;
    mouse_x_ref = mouse_x;
}

function AutoDrag()
{
    var cube = document.getElementById("cube");
    img_num++;
    if (img_num > nb_max) { img_num = 1; }
    cube.src = images_loc + img_num + ".jpg";
    if (auto_drag) { setTimeout("AutoDrag()", 100); }
}

function DoDrag()
{
    var cube = document.getElementById("cube");
    
    if (mouse_x > (mouse_x_ref+step))
    {
        img_num++;
        if (img_num > nb_max) { img_num = 1; }
        cube.src = images_loc + img_num + ".jpg";
        mouse_x_ref = mouse_x;    
    }

    if (mouse_x < (mouse_x_ref-step))
    {
        img_num--;
        if (img_num < 1) { img_num = nb_max; }
        cube.src = images_loc + img_num + ".jpg";
        mouse_x_ref = mouse_x;
    }
    
    if (img_num <= 16) { UpdateMap(links[img_num]); }
    else { UpdateMap("poly#0,0,0,0,0,0#@poly#0,0,0,0,0,0#"); }
}

function UpdateMap(data)
{
    var link1 = document.getElementById("link1");
    var link2 = document.getElementById("link2");

    //Clear
    link1.shape = "poly"; link1.coords = "0,0,0,0,0,0"; link1.href = "";
    link2.shape = "poly"; link2.coords = "0,0,0,0,0,0"; link2.href = "";

    //Update
    var shapes = data.split("@");
    var values1 = shapes[0].split("#");
    var values2 = shapes[1].split("#");
    link1.shape = values1[0];
    link1.coords = values1[1];
    link1.href = values1[2];
    link1.onmousemove = DoDrag;
    link2.shape = values2[0];
    link2.coords = values2[1];
    link2.href = values2[2];
    link2.onmousemove = DoDrag;
}

function ImageLoaded()
{
    images_loaded++;
    percent = parseInt(images_loaded/nb_max*100);
    
    bar = document.getElementById("loading_bar");
    bar.style.width = (percent*2)+"px";
    bar.innerHTML = percent + "%";
    if (percent > 95)
    {
        document.getElementById("loading").style.display = "none";
        document.getElementById("cube").style.display = "block";
    }
}
