/**
 * Part of Showkase web site management package
 *
 * @package Showkase
 * @author Jack Hardie {@link http://www.jhardie.com}
 * @copyright Copyright (c) 2012, SimpleViewer Inc.
 */
 
/**
 * Handle click events on cancel button and image thumbnails
 * Thumbnail url is sent to CKEditor or to customize screen form input depending on value of callback variable
 * Name of form input is passed via name of popup window
 * Note that the second argument to the $ function supplies the context
 */
$(function() {
  if (!window.top.opener) return true;
  $('a.closewindow')
  .on('click', function(event) {
    event.preventDefault();
    window.top.close();
    window.top.opener.focus();
  });
  $('td.ilthumbnail a')
  .on('click', function(event) {
    event.preventDefault();
    if (callback == 'none') {
      $('input[name='+window.name+']', window.opener.document).val(this.href);
    }
    else {
      window.opener.CKEDITOR.tools.callFunction(callback, this.href);
    }
    window.top.close() ;
    window.top.opener.focus() ;
  });
});