/* diagram_gallery_stub.js   ** Copyright (C) 2008. olivier mai. All Rights Reserved.
**
*/

IconDictionary = {};

function DiagramSetDescriptor(tn, p,t,i, y)
        {
                this.path= p; this.title= t; this.items= i; this.ytop=y;
                this.treenode = tn;
//
                this.displayImage  = (function($,label){
                                        var e = $('div#gallery_icon_template').find('img.galleryico').clone();
//debugger;
                                        e.attr('id', 'image_'+label);
                                        $('body').append(e);
                                        return e.get(0);
                                        })(jQuery, this.title);
//
                this.displayText   = (function($,label){
                                        var e = $('div#gallery_icon_template').find('div.gallerytitle').clone();
                                        e.attr('id', 'title_'+label);
                                        $('body').append(e);
                                        e.text(label);
                                        return e.get(0);
                                        })(jQuery, this.title);
//
                this.dispatcher = function(ev) {
                    var id = jQuery(this).attr('id');
                    id = id.replace('image_','');
                    var obj = IconDictionary[id];
                    parent.ShowDiagramGallery(obj.path, obj.title, obj.items);
                };
                this.showBitmap = function() {
                   jQuery(this.displayImage).css({position:'absolute', left:'66%', display:'block'});
                   jQuery(this.displayText).css({position:'absolute', left:'66%', display: 'block'});
                   LINEUPICONS();
                   jQuery(this.displayImage).click(this.dispatcher);
                };
                this.hideBitmap = function() {
                   jQuery(this.displayImage).hide();
                   jQuery(this.displayText).hide();
                   LINEUPICONS();
                };
        }



function DiagramGalleryStub( resourcepath , title, items) {
   // here parent is presumably ...the top window (where the function symbol is defined, if it matters.)
   // calls into script code of ?_?_parts.htm
   //
   parent.ShowDiagramGallery(resourcepath,title, items);
}


function LINEUPICONS() {
   var $=jQuery;
   for (i in IconDictionary) {
        var obj = IconDictionary[i];
        var oimage = obj.displayImage;
        var otext  = obj.displayText;

        var y = $(obj.treenode).offset().top;
        var h = $(oimage).height();

        $(oimage).css('top', y + 'px');
        $(oimage).css('left', '66%');

        $(otext).css('top', y+h+2 + 'px');
        $(otext).css('left', '66%');
   }

}

function SHOWDIAGRAMICON(treenode, resourcepath, title, items, ytop) {
//debugger;
   if ( undefined == IconDictionary[title]) {
            IconDictionary[title] =  new DiagramSetDescriptor(treenode, resourcepath, title, items, ytop);
   }
   var icon = IconDictionary[title];
//debugger;
   icon.showBitmap();
}

function HIDEDIAGRAMICON(title) {
   if ( undefined == IconDictionary[title]) return;
   var icon =IconDictionary[title]
   icon.hideBitmap();
}

jQuery(document).ready(function(){
   var $ = jQuery;
   // fix the grey background of most pages ...
   $('body').css('backgroundColor','white');
   //
   $('body').append('<div id="gallery_icon_template" style="display:none"><img  class="galleryico" src="/omlib/img/gallery.png" /><div class="gallerytitle" style="border:1px solid grey" >&nbsp;</div></div>');
   $('div#gallery_icon_template').css({position:'absolute', top:'0px', left:'66%' });
   $('img.galleryico').css({width:'150px', height:'111px'});

   $('div.gallerytitle').css({ position: 'absolute'});
   $('div.gallerytitle').css({  left:'66%'                      });
   $('div.gallerytitle').css({  backgroundColor: 'lightyellow'  });
   $('div.gallerytitle').css({  fontSize: '11pt'                });
   $('div.gallerytitle').css({  fontWeight: 'bold'              });
   $('div.gallerytitle').css({  fontFamily: 'sans-serif'        });
   $('div.gallerytitle').css({  padding: '0px 3px 0px 2px'      });

   //
   // let's assume the treeview is done building by now...
   //
   $(foldersTree.children).each( function() {
     if( (typeof GETASSEMBLIES)=='function' ) {
        if (this.isOpen) {
           GETASSEMBLIES(this.getID());
        }
     }
   });
});



