function previewImg() {

  var src = this.src;

  myImage = new Image();
  myImage.src = src;

  var preview_dialog = $('<div id="previewDialog"></div>').dialog({
      autoOpen: false,
      height: myImage.height + 55,
      modal: true,
      width: myImage.width + 30,
      resizable: false,
      draggable: false,
      title:''
    }
  );

  preview_dialog.bind(
    'dialogclose',
    function (event, ui) {
      preview_dialog.dialog('destroy');
      $('#previewDialog').remove();
    }
  );

  var html = '<div style="text-align:center; padding-top:5px">' + '<img src="' + src + '"/></div>';
  preview_dialog.html(html);
  preview_dialog.dialog('open');
}


function previewImgFixedSizeEx(img, w, h, text) {

  var src = img.src;
  src = src.replace("_small", "");

  fullName = src;
  var shortName = src.match(/[^\/\\]+$/);
  var str = new String(shortName);
  var str = str.replace(".png", "");
  var title = $('#' + str).val();
  var height = 55;

  var innerHtml = '';

  if (title != undefined) {
   height = 55 + 60;
   innerHtml = '<div style="text-align: center"><h2>' + title + '</h2></div>';
  }

  if (text != undefined) {
   text = text.replace("\n", "<br />");
   innerHtml += '<div style="text-align: center">' + text + '</div>';
  }

  var preview_dialog = $('<div id="previewDialog"></div>').dialog({
      autoOpen: false,
      height: h ? h : (600 + height),
      modal: true,
      width: w ? w : (600 + 30),
      resizable: false,
      draggable: false,
      title:''
    }
  );

  preview_dialog.bind(
    'dialogclose',
    function (event, ui) {
      preview_dialog.dialog('destroy');
      $('#previewDialog').remove();
    }
  );

  var html = '<div style="text-align:center; padding-top:5px">' + '<img src="' + src + '"/></div>' + innerHtml;
  preview_dialog.html(html);
  preview_dialog.dialog('open');
}



function previewImgFixedSize() {
  return previewImgFixedSizeEx(this);
}

function previewImgFixedSize2(img, title, b_chips, cpus, os, hci_transport, profiles) {
  var src = img;
  var innerHtml = '';


  var hci_transportHtml = '';
  for (x in hci_transport)
  {
    hci_transportHtml += '<li>' + hci_transport[x]  + '</li>';
  }
  
  var profilesHtml = '';
  for (x in profiles)
  {
    profilesHtml += '<li>' + profiles[x]  + '</li>';
  }

  height = 55 /* + 60 + 80 */;
  innerHtml  = '<div class="hatching" style="float: right; margin-left: 15px; height: 98%; width: 155px; padding: 0px 10px 10px 10px; font-size: 12px;">';
  innerHtml += '  <div class="div_header" style="margin-top:0px; text-align: center"><h3>' + title + '</h3></div>';
  innerHtml += '  <b><i>Bluetooth</i> chip:</b> <ul style="margin-bottom: 10px;" class="ul_without_margin_in_div"><li>' + b_chips + '</li></ul>';
  innerHtml += '  <b>CPU:</b> <ul style="margin-bottom: 10px;" class="ul_without_margin_in_div"><li>' + cpus + '</li></ul>';
  innerHtml += '  <b>Operating System:</b> <ul style="margin-bottom: 10px;" class="ul_without_margin_in_div"><li>' + os + '</li></ul>';
  innerHtml += '  <b>HCI transport:</b><ul style="margin-bottom: 10px;" class="ul_without_margin_in_div"> ' + hci_transportHtml + '</ul>';
  innerHtml += '  <b>Profiles supported:</b><ul style="margin-bottom: 10px;" class="ul_without_margin_in_div"> ' + profilesHtml + '</ul>';
  innerHtml += '</div>';

  var preview_dialog = $('<div id="previewDialog"></div>').dialog({
      autoOpen: false,
      height: 600 + height,
      modal: true,
      width: 600 + 30 + 190 + 12,
      resizable: false,
      draggable: false,
      title:''
    }
  );

  preview_dialog.bind(
    'dialogclose',
    function (event, ui) {
      preview_dialog.dialog('destroy');
      $('#previewDialog').remove();
    }
  );

  var html = '<div><div style="height: 610px;"><div style="text-align:center; padding-top:5px; float: left">' + '<img src="' + src + '"/></div>' + innerHtml + '</div>';
  preview_dialog.html(html);
  preview_dialog.dialog('open');
}


function galleryInit() {
  $('.gallery').click(previewImg);
  $('.small_gallery_image').click(previewImgFixedSize);
}

