(function($)
{
$.querySelector = function(callback)
{
var popupExists = $('#popup').length;
if( !popupExists )
{
 $('<div id="popup"></div>').appendTo('#content');
$('<div id="popup-window" class="ui-corner-all"></div>').appendTo('#popup');
$('<div id="popup-window-contents"></div>').appendTo('#popup-window');
$('<div id="toolbar"></div>').appendTo('#popup-window');
 $('<div id="popup-close-button"><a class="button" id="popup-close-link"><span>X</span></a></div>').appendTo('#toolbar').hide();
$('<div id="popup-mask"></div>' ).appendTo('#popup');
 $('<div id="popup-busy"></div>').appendTo('#popup-window-contents');
$('#popup').lusidPopup(callback);
}
else
{
callback();
}
return this;
};
})(jQuery);
(function($)
{
$.fn.lusidPopup = function(callback)
{
  var maskHeight = $(document).height()*5; 
var maskWidth = $(window).width()*5; 
$('#popup-mask').css({ width:maskWidth, height:maskHeight }); 
 $('#popup-mask').fadeTo(0, 0.4, function() {
 $('#popup-window').lusidCenterInWindow( true, false );
$('#popup-window').fadeIn(0);
callback();
});
return this;
};
})(jQuery);
(function($)
{
$.fn.lusidPopuplatePopup = function( options )
{
var DEFAULT_INDENTATION = "-140px";
if( options == undefined )
options = {};
var onCloseCallbackUrl = options.onCloseCallbackUrl;
var onSelectFocusCallbackUrl = options.onSelectFocusCallbackUrl;
 $('#query-elements').find('span').each( function(index) {
$(this).removeAttr('onClick');
});
 $('#popup-close-link').click(function (e)
{
$('#popup').remove(); 
if( onCloseCallbackUrl != undefined && onCloseCallbackUrl != null && onCloseCallbackUrl != "" )
wicketAjaxGet(onCloseCallbackUrl, null, null, null);
});
 $('<div id="mesh-branch-parents"><ul></ul></div>').appendTo('#popup-window-contents');
$('#mesh-branches .mesh-branch-parent').each( function(index) {
  if( index > 2 )
{
$(this).remove();
return;
}
var item = $('<li></li>').appendTo('#mesh-branch-parents ul');
$(this).appendTo(item);
});
$('#mesh-branch-parents ul').lusidCenter(3);
$('#mesh-branch-parents .mesh-branch-parent').each( function(index) {
$(this).children('.japanese').lusidResize({numLines: 2}).lusidCenter();
$(this).children('.english').lusidResize({numLines: 3}).lusidCenter();
$(this).css("border-color", $.getColor(index));
});
 $('#focus-term').appendTo('#popup-window-contents');
$('#focus-term .japanese').lusidResize().lusidCenter();
$('#focus-term .english').lusidResize().lusidCenter();
$('#focus-term').click( function(e) {
$('#popup').remove(); 
if( onSelectFocusCallbackUrl != undefined && onSelectFocusCallbackUrl != null && onSelectFocusCallbackUrl != "" )
wicketAjaxGet(onSelectFocusCallbackUrl, null, null, null);
});
 var zIndexes = new Array();
var selectedChild = -1;
$('<div id="mesh-branches-children"></div>').appendTo('#popup-window-contents');
$('#mesh-branches .mesh-branch-children').each( function(index) {
  if( index > 2 )
{
$(this).remove();
return;
}
var outerDiv = $('<div class="mesh-branches-children-outer"></div>').appendTo('#mesh-branches-children');
var offset = index * 5;
$(outerDiv).css({'top': offset+'px', 'left': offset+'px'});
var containerDiv = $('<div class="carousel-container mesh-branches-children-carousel-container"></div>').appendTo(outerDiv);
var parent = $(containerDiv).parent();
$(this).appendTo(containerDiv);
var zIndex = $(parent).css("z-index");
while( zIndex == "auto" && parent != null )
{
parent = parent.parent();
zIndex = $(parent).css("z-index");
}
var thisZIndex = parseInt(zIndex,10) + index;
$(containerDiv).css("z-index", thisZIndex);
zIndexes[index] = thisZIndex;
$(containerDiv).css("border-color", $.getColor(index));
});
$('#mesh-branches-children .mesh-branch-children').each( function(index) {
$(this).children('li').each( function() {
var id = $(this).attr('id');
$(this).removeAttr('id');
var onClick = $(this).attr('onClick');
$(this).removeAttr('onClick');
var liDiv = $('<div class="mesh-branch-child"></div>').appendTo(this);
$(this).children('span').each( function() {
$(this).appendTo(liDiv);
});
$(liDiv).attr('id', id);
$(liDiv).attr('onClick', onClick);
$(liDiv).click( function() {
if( $(this).hasClass("disabled") != true )
{
$('#popup-window-contents').children().remove();
$('<div id="popup-busy"></div>').appendTo('#popup-window-contents');
}
});
});
});
$('#mesh-branches-children .mesh-branch-child').each( function(index) {
$(this).children('.japanese').lusidResize({numLines: 2}).lusidCenter();
$(this).children('.english').lusidResize({numLines: 2}).lusidCenter();
$(this).mouseenter( function() {
var currentColor = $(this).css("backgroundColor");
$(this).css("backgroundColor", "white");
$(this).animate({backgroundColor: currentColor}, 2000);
});
});
$('#mesh-branches-children ul').each( function(index) {
var numChildren = $(this).children('li').length;
if( numChildren == 0 )
{
$(this).replaceWith('<div class="mesh-branch-children"><span class="english">No child nodes</span></div>');
}
else if( numChildren < 5 )
{
$(this).lusidCenter(10);
}
else
{
$(this).wrap('<div class="mesh-branches-children-carousel-inner"/>');
$(this).css("left", DEFAULT_INDENTATION);
$(this).parent('.mesh-branches-children-carousel-inner').before($('#query-term-selector-resources .left-scroll').clone());
$(this).parent('.mesh-branches-children-carousel-inner').after($('#query-term-selector-resources .right-scroll').clone());
$(this).parents('.mesh-branches-children-carousel-container').lusidCarousel(DEFAULT_INDENTATION);
}
});
 $('#mesh-branch-parents .mesh-branch-parent').each( function(index) {
$(this).mouseenter( function() {
selectedChild = $.selectChild(index, selectedChild, zIndexes);
var currentColor = $(this).css("backgroundColor");
$(this).css("backgroundColor", "white");
$(this).animate({backgroundColor: currentColor}, 2000);
});
});
 $('#mesh-branch-parents .mesh-branch-parent').each( function(index) {
$(this).click( function() {
if( $(this).hasClass("disabled") != true )
{
$('#popup-window-contents').children().remove();
$('<div id="popup-busy"></div>').appendTo('#popup-window-contents');
}
});
});
 $('#translations').appendTo('#popup-window-contents');
 $('#translations').hide();
 $('#synonyms').appendTo('#popup-window-contents');
$('#synonyms').tabs({
show: function(event, ui) {
var divHeight = $(ui.panel).height();
var pHeight = $(ui.panel).children('p').height();
if( pHeight > divHeight )
{
$(ui.panel).children('p').after('<div class="expander"><a href="#" class="ui-icon ui-icon-triangle-1-s">click</a></div>');
$(ui.panel).children('div').click( function() {
if( $(this).find('a').hasClass('ui-icon-triangle-1-s') )
{
$(this).parent().css("height",pHeight);
 $(this).find('a').removeClass('ui-icon-triangle-1-s');
$(this).find('a').addClass('ui-icon-triangle-1-n');
 }
else
{
$(this).parent().css("height",divHeight);
 $(this).find('a').addClass('ui-icon-triangle-1-s');
$(this).find('a').removeClass('ui-icon-triangle-1-n');
 }
});
}
}
});
 $('#usages').appendTo('#popup-window-contents');
$('#usages').prepend('<div class="expander"><a href="#" class="ui-icon ui-icon-triangle-1-n">click</a></div>');
$('#usages dl').wrap('<div class="inner"></div>');
if( $('#usages dl').children().size() > 0 )
{
var divHeight = $('#usages').height();
var dlHeight = $('#usages dl').height();
var top = $('#usages').offset().top;
var maxHeight;
if( dlHeight > top )
maxHeight = top;
else
maxHeight = dlHeight;
if( dlHeight > divHeight )
{
$('#usages .expander').click( function() {
if( $(this).find('a').hasClass('ui-icon-triangle-1-n') )
{
$(this).parent().children('.inner').animate({'height':maxHeight, 'bottom':'10px'}, 'fast', function(){
$(this).parent().find('.expander a').removeClass('ui-icon-triangle-1-n');
$(this).parent().find('.expander a').addClass('ui-icon-triangle-1-s');
});
}
else
{
$(this).parent().children('.inner').animate({'height':divHeight, 'bottom':'10px'}, 'fast', function(){
$(this).parent().find('.expander a').addClass('ui-icon-triangle-1-n');
$(this).parent().find('.expander a').removeClass('ui-icon-triangle-1-s');
});
}
});
}
}
else
{
$('#usages').hide();
}
 var overlayZIndexes = {};
overlayZIndexes.synonyms = parseInt($('#synonyms').css('z-index'));
overlayZIndexes.usages = parseInt($('#usages').css('z-index'));
$('#synonyms').click( function() {
$('#synonyms').css("z-index", overlayZIndexes.synonyms+100);
$('#usages').css("z-index", overlayZIndexes.usages);
});
$('#usages').click( function() {
$('#synonyms').css("z-index", overlayZIndexes.synonyms);
$('#usages').css("z-index", overlayZIndexes.usages+100);
});
 $('#popup-busy').hide();
$('#popup-close-button').show();
};
})(jQuery);
(function($) {
$.fn.lusidCenterInWindow = function( centerH, centerV )
{
if( centerH == true || centerV == true)
$(this).css("position","absolute");
if( centerH == true )
$(this).css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
if( centerV == true )
$(this).css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
return this;
};
})(jQuery);
(function($) {
$.fn.lusidResize = function( options ) {
var numLines;
if( options != null && options.numLines != undefined && options.numLines != null )
numLines = options.numLines;
else
numLines = 1;
var maxHeight = $(this).css('font-size');
maxHeight = parseFloat(maxHeight,10) * numLines;
var parent = $(this).parent();
var maxWidth = parent.width();
var fontSize = $(this).css('font-size');
fontSize = parseFloat(fontSize,10);
var textHeight;
var textWidth;
do {
$(this).css('font-size', fontSize);
$(this).css( 'line-height', '1.2em' );
textHeight = $(this).height();
textWidth = $(this).width();
fontSize = fontSize - 1;
} while (textHeight > maxHeight || textWidth > maxWidth && fontSize > 3);
return this;
}
})(jQuery);
(function($) { 
$.fn.lusidCenter = function(offset)
{
var e0 = this.get(0);
if( e0 == undefined )
return this;
var test = e0.tagName.toLowerCase();
if( "ul" == test )
{
var ulWidth = 0;
var liOffset = 0;
if( offset != null )
liOffset = offset;
$(this).children().each( function() {
var liWidth = $(this).width();
ulWidth = ulWidth + liWidth + offset;
return ulWidth;
});
$(this).width(ulWidth);
}
var parent = $(this).parent();
$(this).css("left", ( parent.width() - this.width() ) / 2 + "px");
return this;
};
})(jQuery);
(function($){
$.getColor = function(index) {
var colors = new Array();
colors[0] = "#2E2EFE";
colors[1] = "#B40404";
colors[2] = "#0B610B";
colors[3] = "#F7FE2E";
colors[4] = "#190707";
colors[5] = "#8A084B";
colors[6] = "#04B4AE";
colors[7] = "#FF8000";
colors[8] = "#AC58FA";
colors[9] = "#58FA58";
if( index > 0 && index < 10 )
return colors[index];
return "#2E2EFE";
};
})(jQuery);
(function($){
$.selectChild = function(current, previous, zIndexes) {
if( current != previous )
{
var DELTA = 50;
zIndexes[previous] = zIndexes[previous] - DELTA;
zIndexes[current] = zIndexes[current] + DELTA;
$('#mesh-branches-children div.mesh-branches-children-outer').each( function(i) {
$(this).css("z-index", zIndexes[i]);
 });
}
return current;
};
})(jQuery);
(function($) {
$.fn.lusidCarousel = function(indentation) {
  $(this).find('ul li:first').before($(this).find('ul li:last').clone(true));
 $(this).find('div.right-scroll img').click(function() {
if( $(this).attr("disabled") != undefined )
return;
$(this).attr("disabled", "disabled");
 var parent = $(this).parents('div.carousel-container');
var itemWidth = $(parent).find('ul li').outerWidth() + 10;
 var leftIndent = parseInt($(parent).find('ul').css('left')) - itemWidth;
$(parent).find('ul').animate({'left':leftIndent}, {queue:false, duration:500, complete: function(){
 $(parent).find('ul li:first').remove();
 $(parent).find('ul li:last').after($(parent).find('ul li:first').clone(true));
 $(parent).find('ul').css({'left': indentation});
$(parent).find('div.right-scroll img').removeAttr("disabled");
}});
});
 $(this).find('.left-scroll img').click(function(){
if( $(this).attr("disabled") != undefined )
return;
$(this).attr("disabled", "disabled");
var parent = $(this).parents('div.carousel-container');
var itemWidth = $(parent).find('ul li').outerWidth() + 10;

var leftIndent = parseInt($(parent).find('ul').css('left')) + itemWidth;
$(parent).find('ul').animate({'left':leftIndent}, {queue:false, duration:500, complete: function(){
 $(parent).find('ul li:last').remove();
 $(parent).find('ul li:first').before($(parent).find('ul li:last').clone(true));
 $(parent).find('ul').css({'left': indentation});
$(parent).find('div.left-scroll img').removeAttr("disabled");
}});
});
return this;
};
})(jQuery);
(function($) { 
$.fn.lusidQueryQueue = function()
{
$('#query-elements .english-element.unknown').each( function() {
$(this).parents('.element-container').css('background-color', '#fbf9ee');
$(this).parents('.element-container').css('border-color', '#fcefa1');
$(this).children('.element-value').css('color', '#1E90FF');
});
return this;
};
})(jQuery);
(function($)
{
$.fn.lusidSearchButton = function(options)
{
if( options == undefined )
options = {};
var text;
if( options != null && options.text != undefined && options.text != null && options.text != "" )
text = options.text;
else
text = "Please enter a value";
$(this).click( function(e) {
var field = $(this).parent('form').children('.search-field');
var defaultText = $(field).attr('title');
var value = $(field).val();
if( value == defaultText || value == null || value == "" )
{
e.preventDefault();
$(field).removeClass('default');
$(field).addClass('search-field-error');
$(this).parents('#query-tool').effect("shake", { times:4, distance:5 }, 50, function() {
$(field).removeClass('search-field-error');
$(field).addClass('default');
});
}
});
return this;
};
})(jQuery);
(function($)
{
$.fn.lusidDisableSubmit = function()
{
$(this).submit(function(){
return false;
}); 
return this;
};
})(jQuery);
(function($)
{
$.fn.showAbstractPreview = function()
{
var abstract = this;
     var citationWidth = $('#search-results').width();
  var citationRight = citationWidth+40;
var abstractTop = 100 + $(window).scrollTop();
$(abstract).offset({top: abstractTop, left: citationRight });
$(abstract).width( $(window).width() - citationRight - 80 );
var maxAbstractHeight = $(window).height() - 200;
if( $(abstract).height() > maxAbstractHeight )
$(abstract).height( $(window).height() - 200 );

$.fn.showAbstractDiv = function(abstract)
{
$(abstract).show();
};
$(this).parents('.search-result').mouseenter( function() {
 var isLocked = $(this).hasClass('locked');
if( !isLocked )
{
$('.abstract-preview').each( function() {
$(this).hide();
});
}

if( !isLocked)
{
$(this).showAbstractDiv(abstract);
}  });
  $(this).parents('.search-result').mouseleave( function() {
if( !$(this).hasClass('selected') )
$(abstract).hide();
});
$(this).parents('.search-result').click( function() {
var isSelected = $(this).hasClass('selected');
if( isSelected )
{
$('.search-result').each( function() {
$(this).removeClass('locked');
});
$(this).removeClass('selected');
}
else
{
$('.search-result').each( function() {
$(this).addClass('locked');
$(this).removeClass('selected');
});
$(this).addClass('selected');
$('.abstract-preview').each( function() {
$(this).hide();
});
$(this).showAbstractDiv(abstract);
}
});
return this;
};
})(jQuery);
(function($)
{
$.fn.showTranslations23 = function()
{


$(this).children("[title]").tooltip({position: 'bottom center'});
      
return this;
};
})(jQuery);
(function($) { 
$.fn.lusidAddReferencePopup = function( options )
{
if( options == undefined )
options = {};
var onCloseCallbackUrl = options.onCloseCallbackUrl;
$(this).find('.add-reference-list').hide();
var t = $(this).find('.add-reference-link');
$(this).find('.add-reference-link').click( function(event) {
if( $(this).parents('.add-reference-panel').find('.add-reference-list').has('li').length )
{
$(this).parents('.add-reference-panel').find('.add-reference-list').show();
}
else
{
if( onCloseCallbackUrl != undefined && onCloseCallbackUrl != null && onCloseCallbackUrl != "" )
wicketAjaxGet(onCloseCallbackUrl, null, null, null);
else
alert('No callback');
}
});
$(this).find('.delete-element-link').button({ icons : { primary: 'ui-icon-close' }, text: false });
$(this).find('.delete-element-link').click( function(event) {
$(this).parents('.add-reference-list.outer').hide();
});;
return this;
};
})(jQuery);

