function bindItem(elem) {
    var toggleFunc = function () {
        $(this).toggleClass(elem + 'Selected');
    };
    var elemSelector = '.' + elem;
    $(elemSelector).hover(toggleFunc, toggleFunc);
    $(elemSelector).click(function () {
        var url = $(elemSelector + ' > a').attr("href");
        document.location.assign(url);
    });
}

function showDialog() {
    $("#dialog").dialog({
        autoOpen: false,
        show: 'fold',
        bgiframe: true,
        modal: false
    });
    $('#dialog').dialog('open');
}


function openPicture(src, width, title){
    var origSrc = $('#viewerPict').attr("src");
    $('#viewerPict').attr("src", src);

    $("#loadingImage").dialog({
        autoOpen: false,
        bgiframe: true,
        resizable: false,
        minHeight: 0, 
        modal: false
    });
    $('#loadingImage').dialog('open');

    // load the picture
    $.ajax({
        type: "GET",
        url: src,
        complete: function() {
            setTimeout("doShowPicture()", 100);
        }
    });

    doShowPicture = function() {
        $("#imageViewer").dialog({
            autoOpen: false,
            //show: 'blind',
            //show: 'clip',
            show: 'drop',
            //show: 'explode',
            //show: 'fold',
            //show: 'puff',
            //show: 'shake',
            //show: 'slide',
            bgiframe: true,
            resizable: false,
            modal: true,
            open: function(event, ui) {
                $('#loadingImage').dialog('close');
            },
            close: function(event, ui) {
                $('#viewerPict').attr("src", origSrc);
            }
        });
        $('#imageViewer').dialog('option', 'width', width);
        $('#imageViewer').dialog('option', 'height', 'auto');
        $('#imageViewer').dialog('option', 'title', title == null ? '' : title);
        $('#imageViewer').dialog('open');
    }
}

