// requires PEOPLEGIS.wa.constants.res_path

// uses data attributes - data-text, data-error-text

		if (typeof PEOPLEGIS === 'undefined') {var PEOPLEGIS = {};}
		if (typeof PEOPLEGIS.wa === 'undefined') {PEOPLEGIS.wa = {};}
//		if (typeof PEOPLEGIS.wa.constants === 'undefined') {PEOPLEGIS.wa.constants = {};}
		if (typeof PEOPLEGIS.wa.hoverImages === 'undefined') {PEOPLEGIS.wa.hoverImages = {};}
// requires PEOPLEGIS.wa.constants.res_path

		PEOPLEGIS.wa.hoverImages.hoverPanel = false;

		
		jQuery(".tab_panel_photo img").error (function () {
			if (typeof $panel !== 'undefined') {
			$panel.css('width','200px');
			if (PEOPLEGIS.wa.hoverImages.hoverPanel) {
				jQuery(this).hide().siblings('span').show();
				jQuery(this).load();
			}
			}
		});
		jQuery(".tab_panel_photo").hover(function () {
			PEOPLEGIS.wa.hoverImages.hideAll();
		});

		jQuery("#results_list, #clear_button").delegate("a.hover_link","hover", 
			function (ev) {
				PEOPLEGIS.wa.hoverImages.hideAll();
				var szText;
				$link = jQuery(this);
				$panel = jQuery(".tab_panel_photo");				
				
				if (ev.type == 'mouseenter') {
					PEOPLEGIS.wa.hoverImages.hoverPanel = true;
					$panel.find("img").unbind('load');
					if ($link.data('title')) {
						szText = $link.data('title');
						if ($link.data('quickdisplay1') && $link.data('quickdisplay1').length > 0) {
							szText += '<br>'+$link.data('quickdisplay1');
						}
						if ($link.data('quickdisplay2') && $link.data('quickdisplay2').length > 0) {
							szText += '<br>'+$link.data('quickdisplay2');
						}						
						$panel.css('width','200px');
						$panel.find("span").show().html(szText);
						PEOPLEGIS.wa.hoverImages.displayImagePanel($link,$panel);
					} else {
						$panel.css('width','');
						if ($link.data('error-text')) {
							$panel.find("span").hide().text($link.data('error-text'));					
						}
						$panel.find("img").load ( function () {
							PEOPLEGIS.wa.hoverImages.displayImagePanel($link,$panel);
						}).show().attr('src',$link.attr('href'));
					}
				} else {
					PEOPLEGIS.wa.hoverImages.hoverPanel = false;
				}
			}
		);
		PEOPLEGIS.wa.bSearchLoaded = true; // used to determine login submit action

	PEOPLEGIS.wa.hoverImages.hideAll = function () {
			jQuery(".panel").hide();
			jQuery(".panel").find('img,span').hide();
	};
	PEOPLEGIS.wa.hoverImages.displayImagePanel = function ($link,$panel) {
	//console.log('display Photo');
		if (PEOPLEGIS.wa.hoverImages.hoverPanel) {
			$panel.css({ top: 0, left: 0 }).position({
				of:  $link.find('img'),
				my: "right bottom",
				at : "center top",
				offset : "30 0",
				collision:"flip"
			}).show();		
			if ($panel.offset().top >$link.offset().top) {
				jQuery(".calloutUp").show();
				jQuery(".calloutDown").hide();	
			} else {
				jQuery(".calloutUp").hide();
				jQuery(".calloutDown").show();			
			}		
		}
	};
		 

