
// Set thickbox loading image
var tb_pathToImage = "/images/loading-thickbox.gif";

var dockCarousel_itemList;
var description='';

/* initialisation des variables globales */
var dockCarousel_currentItemList;
var step = 7;
var start = 0;
var stop = step;

function goToNext(){
    loadItemListNext();
    goTo();
}

function goToPrevious(){
    loadItemListPrev();
    goTo();
}

function goTo() {
    var content = '';
    for(var i= 0;i<step;i++){
        if(dockCarousel_currentItemList[i] != undefined) {
            content += '<a class="dock-item" href="javascript:afficheItemInfos(\''+dockCarousel_currentItemList[i].link+'\')">' ;
            content += '<img src="'+dockCarousel_currentItemList[i].url+'" alt="'+dockCarousel_currentItemList[i].title+'" /><span></span></a>&nbsp;';
        }
    }

    $(document).ready(
        function() {
            $("#dock-container").fadeIn("slow");
            $("#dock-container").html(content);
//            document.getElementById("dock-container").innerHTML=content;
            $('#dock').Fisheye(
            {
                container: '#dock-container',
                items: 'a',
                itemsText: 'span',
                maxWidth: 35,
                itemWidth: 120,
                proximity: 120,
                valign : 'top',
                halign : 'center'
            }
            )
        }
        );
}

function loadItemListNext(){
    stop = start + step;
    loadItem(start);
}

function loadItemListPrev(){
    stop = start - step;
    var currentStart = stop - step;
    if(currentStart < 0) {
        currentStart = currentStart + dockCarousel_itemList.length;
    }
    stop = currentStart + step;
    loadItem(currentStart);
}

function loadItem(currentStart) {
    dockCarousel_currentItemList = new Array();
    var tabUrlG = new Array();
    var tabUrlD = new Array();
    var tabTitle = new Array();
    var tabLink = new Array();
    var j = 0;
    for(var i = currentStart; i < stop && tabUrlG.length < dockCarousel_itemList.length; i++){
        while(i < 0){
            i = i + dockCarousel_itemList.length;
            stop = stop % dockCarousel_itemList.length;
        }

        if(i >= dockCarousel_itemList.length){
            i = i % dockCarousel_itemList.length;
            stop = stop % dockCarousel_itemList.length;
        }
        tabUrlG[j] = dockCarousel_itemList[i].urlG;
        tabUrlD[j] = dockCarousel_itemList[i].urlD;
        tabTitle[j] = dockCarousel_itemList[i].title;
        tabLink[j] = dockCarousel_itemList[i].link;
        j++;
    }

    var s= '[';
    for(var k= 0; k < tabUrlG.length; k++){
        orientation = (k%2 == 0) ? 'G' : 'D';
        linkPhotoCarousel = (k%2 == 0) ? tabUrlG[k] : tabUrlD[k];
        linkProduit = tabLink[k]+'&amp;orientation='+orientation;
        s += '{url: "'+linkPhotoCarousel+'", title: "'+tabTitle[k] +'", link: "'+linkProduit+'"}';
        s += (k == tabUrlG.length-1) ? '' : ',';
    }
    s+=']';
    dockCarousel_currentItemList = eval(s);
    start = stop;
    if(start == dockCarousel_itemList.length) {
        start = 0;
    }
}
