$(document).ready(function(){
	$(".openIt").each(function(){
		$(this).load("/toah/content/mma_pubs/pub"+$(this).attr("rel")+".html",function(){
			$(".sepBibItems2").css({"display":"none"});
		});
	})
	
	$("#indexResultsBibliography ul,.soloHov").hover(function(){
		$(this).addClass("hoveredUL");
	}, function(){
		$(this).removeClass("hoveredUL");
	})
	
	$(".authorNameFinal").hide();
})


	var stallVariable = 0;
	var c=0;
	var t;
	
	function setDept(targ,selObj,restore){ 
	  eval(targ+".location='Default.aspx?sort=department&range="+selObj.options[selObj.selectedIndex].value+"'");
	  if (restore) selObj.selectedIndex=0;
	}
	function setType(targ,selObj,restore){ 
	  eval(targ+".location='Default.aspx?sort=type&range="+selObj.options[selObj.selectedIndex].value+"'");
	  if (restore) selObj.selectedIndex=0;
	}
	function pubReveal(uniqueID) {
	var el = document.getElementById('pubReveal'+uniqueID);
	var elArrow = document.getElementById('pubArrow'+uniqueID);
	var elParent = document.getElementById('pub'+uniqueID);
	if (stallVariable == 0) {
		if (el.style.display == 'none' || el.style.display == '') {
			el.style.display='none';
			ajaxpage('/toah/content/mma_pubs/pub'+uniqueID+'.html', 'pubReveal'+uniqueID);
			elArrow.src = '/toah/art/close.png';
			$('#pubReveal'+uniqueID).slideDown("fast");
			elParent.className='stayHighlightPub';
			document.getElementById("thematicSlideIndex"+uniqueID).style.display = "block";
			pubHighlighter();
		} else {
			$('#pubReveal'+uniqueID).slideUp("fast");
			elArrow.src = '/toah/art/open.png';
			elParent.className='publicationContent';
			document.getElementById("thematicSlideIndex"+uniqueID).style.display = "none";
		}
	}
	}
function unStallSwap() {
	stallVariable = 0;
}

function stallSwap() {
	stallVariable = 1;
	clearTimeout(t);
	t=setTimeout("unStallSwap()",1000);
}
function swapCategory(theID) {
	if (stallVariable == 0) {
		var el = document.getElementById(theID);
		var elArrow = document.getElementById(theID+'Arrow');
			if (el.style.display == 'none' || el.style.display == '') {
				$('#'+theID).slideDown("fast");
				elArrow.src = '/toah/art/thematic_arrow_down.gif';
			} else {
				$('#'+theID).slideUp("fast");
				elArrow.src = '/toah/art/thematic_arrow_right.gif';
			}
	}
	//alert(el.style.display);
}
function highlightIndex(theNum,whichOne) {
	var el = document.getElementById('pub'+theNum);
	if (el.className != 'stayHighlightPub') {
		el.className='indexHighlightPub';
	}
}

function unhighlightIndex(theNum,whichOne) {
	var el = document.getElementById('pub'+theNum);
	if (el.className != 'stayHighlightPub') {
		el.className='publicationContent';
	}
}
function unhighlightIndex2(theNum,whichOne) {
	var el = document.getElementById('pub'+theNum);
	if (el.className != 'stayHighlightPub') {
		el.className='publicationContent2';
	}
}
function showInfo(uniqueID) {
    window.location='#'+uniqueID;
    pubReveal(uniqueID);
}

	function pageload(hash) {
		if(hash) {
				var el = document.getElementById('pubReveal'+hash);
				var elArrow = document.getElementById('pubArrow'+hash);
				var elParent = document.getElementById('pub'+hash);
				if (stallVariable == 0) {
					if (el.style.display == 'none' || el.style.display == '') {
						el.style.display='none';
						ajaxpage('/toah/content/mma_pubs/pub'+hash+'.html', 'pubReveal'+hash);
						elArrow.src = '/toah/art/close.png';
						$('#pubReveal'+hash).slideDown("fast");
						elParent.className='stayHighlightPub';
					}
				}
		} else {
			$("#load").empty();
		}
	}
	
	$(document).ready(function(){
		//$.historyInit(pageload);
		
		// set onlick event for buttons
		/*$("a[@rel='history']").click(function(){
			// 
			var hash = this.href;
			hash = hash.replace(/^.*#/, '');
			// moves to a new page. 
			// pageload is called at once. 
			$.historyLoad(hash);
			return false;
		});

	  var container = $('<div id="essayPopupContainer">'
	      + '<table width="" border="0" cellspacing="0" cellpadding="0" align="center" class="essayPopupPopup">'
	      + '<tr>'
	      + '   <td class="corner topLeft"></td>'
	      + '   <td class="top"></td>'
	      + '   <td class="corner topRight"></td>'
	      + '</tr>'
	      + '<tr>'
	      + '   <td class="left">&nbsp;</td>'
	      + '   <td class="whiteBG"><div id="essayPopupContent"></div></td>'
	      + '   <td class="right">&nbsp;</td>'
	      + '</tr>'
	      + '<tr>'
	      + '   <td class="corner bottomLeft">&nbsp;</td>'
	      + '   <td class="bottom">&nbsp;</td>'
	      + '   <td class="corner bottomRight"></td>'
	      + '</tr>'
	      + '</table>'
	      + '</div>');
	
	  $('body').append(container);
	  
	  */
	  $(".showPDF").live("click", function(){
    	$(this).parent().children(".pdfList").toggle();
	  })
	  
	});
	function showTooltipOBJ() {
	  var container = $('<div id="toahPopupContainer">'
	      + '<table width="" border="0" cellspacing="0" cellpadding="0" align="center" class="toahPopupPopup">'
	      + '<tr>'
	      + '   <td class="corner topLeft"></td>'
	      + '   <td class="top"></td>'
	      + '   <td class="corner topRight"></td>'
	      + '</tr>'
	      + '<tr>'
	      + '   <td class="left">&nbsp;</td>'
	      + '   <td class="whiteBG"><div id="toahPopupContent"></div></td>'
	      + '   <td class="right">&nbsp;</td>'
	      + '</tr>'
	      + '<tr>'
	      + '   <td class="corner bottomLeft">&nbsp;</td>'
	      + '   <td class="bottom">&nbsp;</td>'
	      + '   <td class="corner bottomRight"></td>'
	      + '</tr>'
	      + '</table>'
	      + '</div>');
	
	  $('body').append(container);

		var objAccNo;
		var re = new RegExp('.*ho_(.*)\.htm','ig');
		objAccNo = $(this).attr("href");
		objAccNo = objAccNo.replace(re,"$1")

		var offset = $(this).offset();
			$("#toahPopupContent").load('/toah/content/ho/preview/ho_'+objAccNo+'.htm');
			var tipHeight = jQuery('#toahPopupContainer').height();
			var winHeight = jQuery(window).height();
			var scrollTop = $(window).scrollTop();

			var totalDivHeight = tipHeight + 180;
			var orientDiv = offset.top-scrollTop;
			
			$("#toahPopupContainer").css('left',offset.left);
			$("#toahPopupContent").css('width',250);
	/*
			if (orientDiv > (winHeight/2)) {
				$("#toahPopupContainer").css('top',offset.top-totalDivHeight-40);
			} else {
				$("#toahPopupContainer").css('top',offset.top+20);
			}
	*/
			$("#toahPopupContainer").css('top',offset.top+20);

			$("div.adSpace").remove();
			$("div.readMore").remove();
			container.fadeIn(100);
	}
	function hideTooltipOBJ() {
		$("#toahPopupContainer").remove();
	}
	function showTooltipTE() {
	  var container = $('<div id="toahPopupContainer">'
	      + '<table width="" border="0" cellspacing="0" cellpadding="0" align="center" class="toahPopupPopup">'
	      + '<tr>'
	      + '   <td class="corner topLeft"></td>'
	      + '   <td class="top"></td>'
	      + '   <td class="corner topRight"></td>'
	      + '</tr>'
	      + '<tr>'
	      + '   <td class="left">&nbsp;</td>'
	      + '   <td class="whiteBG"><div id="toahPopupContent"></div></td>'
	      + '   <td class="right">&nbsp;</td>'
	      + '</tr>'
	      + '<tr>'
	      + '   <td class="corner bottomLeft">&nbsp;</td>'
	      + '   <td class="bottom">&nbsp;</td>'
	      + '   <td class="corner bottomRight"></td>'
	      + '</tr>'
	      + '</table>'
	      + '</div>');
	
	  $('body').append(container);

		var objAccNo;
		var re = new RegExp('.*hd_(.*)\.htm','ig');
		objAccNo = $(this).attr("href");
		objAccNo = objAccNo.replace(re,"$1")

		var offset = $(this).offset();
			ajaxpage('/toah/content/te_ads/hd_'+objAccNo+'.html', 'toahPopupContent');
			var winHeight = jQuery(window).height();
			var scrollTop = $(window).scrollTop();
			var tipHeight = jQuery('#toahPopupContainer').height();
			
			var totalDivHeight = tipHeight + 230;
			var orientDiv = offset.top-scrollTop;
			
			$("#toahPopupContainer").css('left',offset.left);
			$("#toahPopupContent").css('width',295);
			
	/*
			if (orientDiv > (winHeight/2)) {
				$("#toahPopupContainer").css('top',offset.top-totalDivHeight-60);
			} else {
				$("#toahPopupContainer").css('top',offset.top+20);
			}
	*/
			$("#toahPopupContainer").css('top',offset.top+20);
			
			container.fadeIn(100);
	}
	function hideTooltipTE() {
		$("#toahPopupContainer").remove();
	}

	var pubHighlighter = function() {
	  var hideDelay = 10;  
	  var currentID;
	  var hideTimer = null;
		$(".toahTipObj").hoverIntent(showTooltipOBJ,hideTooltipOBJ);
		$(".toahTipTE").hoverIntent(showTooltipTE,hideTooltipTE);
	}