/**
 * maing function to show gallery/prepary thumbnails
 */
function LoadGallery()
{
    //alert("xxx");
    
    $("photos").set("html", "loading images...");
    
    // prepare thumbs
    if (!isThumbnailsReady())
    {
        $("photos").setStyle("display", "none");
        $("photos").set("html", "no thumbnails");
        return true;
    }
    
    // prepare inline html and script
    if (!(oThumbs = thumbsHtmlCompact()))
    {
        $("photos").setStyle("display", "none");
        $("photos").set("html", "thumbs html error");
        return true;
    }
    
    if (oThumbs.count == 0)
    {
        $("photos").set("html", "");
        $("photos").setStyle("display", "none");
        return true;
    }
    
    $("photos").set("html", oThumbs.html);
    
/*     // show gallery thumbnail
    var nS1 = new noobSlide({
        box: $('pilisbox'),
        items: ArrayItems(oThumbs.count),
        size: (100 + 2)*5,
        autoPlay: true,
        interval: 4000
    }); */
    
    // load simplebox
    Slimbox.scanPage();
    
    return true;
}

/**
 * prepare thumnails
 */
function isThumbnailsReady()
{
    var lReady = false;
    // create thumbnails
    var oRequests = new Request.JSON(
        {
            "method" : "POST",
            "url" : "/photolib/thumbnails.php?obj=" + nObj + "&prop_id=" + nPropID,
            "async" : false,
            onSuccess : function (oVar) { lReady = oVar.generated; }
        }).send();
        
    return lReady;
}

/**
 * generate html for thumbs
 */
function thumbsHtmlCompact()
{
    var oThumbs = "";
    // create thumbnails
    var oRequests = new Request.JSON(
        {
            "method" : "POST",
            "url" : "/photolib/html_compact.php?obj=" + nObj + "&prop_id=" + nPropID,
            "async" : false,
            onSuccess : function (oVar, cHtml) { oThumbs = oVar; }
        }).send();
        
    return oThumbs;
}

/**
 *
 */
function ViewImage(nImgID, nWidth, nHeight)
{
    window.open('/a_pnm/img.php?id=' + nImgID,'bilde','width='+ nWidth +',height='+ nHeight +',menu=no');
}

/**
         * array with items from 0 to itemCount
         * @return array
         */
function ArrayItems(nItems)
{
    nItems = nItems /5;
    var aArray = new Array();
    for(var i = 0; i<nItems; i++)
        aArray[i] = i;
    return aArray;
}