$(document).ready(function() {
 $("#breadcrumb1 a").each(function(){
              $(this).attr("title",$(this).text());
			  });
 // Move footers2, the container for the feedback mechanisms to a pos'n above the Page Maintainer
  var x =  $("#footers2").remove();$("#footers1").before(x);
  // Move The LJMU Banner to the top of the page
  var y =  $("#ljmulogobanner").remove();$("#pagecontent").before(y);
 
 /* Has an item been removed by an iterative process? */
var itemsIterativelyRemoved = 0; 
 
 
 
// THE HIGHER THE VALUE OF QUICKFIX_BR_ITEM_CUT_DOWN, the more items are removed
// MUST BE AN EVEN NUMBER
// TO Remove just 1 item, put 2
// to remove two items put 4
// and so on

 
 
var QUICKFIX_BR_ITEM_CUT_DOWN = 6	; 
 
 
 
 
 
 
 
 
 // Ensure that the central area "content1" is sufficient to accommodate menus
 var menus1Height =   $("#menus1").height();  
  var menus2Height =  $("#menus2").height();  
   var content1Height =   $("#content1").height();  
    // alert(content1Height);
   var tallest;
   (menus1Height > menus2Height )? tallest = menus1Height : tallest = menus2Height;
  // alert(tallest); 
   if ( tallest> content1Height) {$("#content1").css('min-height',tallest+"px");  }
 
 
 
// Handle initial focus of the Search Form's qt element
$('#qt').focus(function() {
  var sT = $('#qt').attr("value");
  if (sT == "Search") {$('#qt').attr("value","");  }
});

// Handle submit event of the Search Form	 
$('#searchform').submit(function() {
  var sT = $('#qt').attr("value");
  if (sT == "Search") {$('#qt').attr("value","");  }
 
});
	      
	      
	//var mX, mY;
//	$(document).mousemove(function(e){
   //   mX = e.pageX ;
    //  mY  = e.pageY;
 //  }); 

/*
Measure the size of the breadcrumb iteratively until it fits into the width of the BC space

*/
//alert('Click OK to begin rewriting the Breadcrumb trail. When complete, a report of the what has changed, how and why will appear as a pop-up.\n\n\n\n');
var reporter = "HOW WERE HANDLING THE BREADCRUMB\n\n";
 var bcCharClim = 20;  
 reporter +="First, truncate any link text over "+bcCharClim+" characters\n";


reporter +="\n\nKeep checking to see if the number of links exceeds the width of the Breadcrumb trail area";
   $('<div id=\"bubbleholder\"></div>').prependTo( $("body"));
 // Breadcrumb actions
 var bcThrh = 10; // Threshold of x pixels
 var bciC; // Breadcrumb content item count - how many as and spans are there
 var bcCWT = 0;
 var bciCThrh = 3;
 
 
 
  
  
 // work around the page minimum:
 
 var mainW = parseInt($('#main').width());
   if (mainW  > 730) {
  var measure = parseInt(mainW*0.50);
 
		$("#breadcrumb1").css('width', measure+'px'); 
  }
 
  var bcW = $("#breadcrumb1").width();  //current width of the BC content
  var bcH = $("#breadcrumb1").height(); //current height of the BC content
 var bcpos = $("#breadcrumb1").position();
 

 //
 var initialGWOC = getWidthOfContent();
 if (bcW >= initialGWOC) {
 }
 else {
 $("#breadcrumb1 a").each(function(){
               
if (( $(this).html().length) > bcCharClim) {
	reporter +="\n"+"Truncating: '"+$(this).html()+"'";
       
        $(this).html($(this).html().substr(0,bcCharClim)+"&hellip;");
        
}
              
});

}
 //
 
 
 
//alert(bcpos.top);
 bciC = $("#breadcrumb1 a, #breadcrumb1 span").size();
 bCicF = $("#breadcrumb1 a").size();
var s="";

if (bciC > QUICKFIX_BR_ITEM_CUT_DOWN) {

//calc back to QUICKFIX_BR_ITEM_CUT_DOWN
var removestart = (bciC - QUICKFIX_BR_ITEM_CUT_DOWN);
var rmst=-removestart;

//alert("big " + rmst + " " + rmend);
$("#breadcrumb1 a,#breadcrumb1 span").slice(2,rmst).remove();

}
 $('<span>&hellip;&nbsp;</span>').insertAfter( $("#breadcrumb1 span").first());
 $("#breadcrumb1 a, #breadcrumb1 span").each(function() {
s += "\n"+$(this).html();
 });
 
//  alert("number of items="+bciC+"\n\n"+s);
 

 
  var tempbciC = $("#breadcrumb1 a").size();
 //alert(bciC);
 // if the number of items in the bc is over the thresh' value - 3 for example
 // then perform item truncation
 // iteratively remove early middle items
 // replace them with ellipsis.
 
 if (bciC >= bciCThrh) {
		//var lastitem = $("#breadcrumb1 a").last().clone();
	//	var lastspan = $("#breadcrumb1 span").last().clone();
	//	$("#breadcrumb1 a, #breadcrumb1 span").slice(1).remove();
	//	$("#breadcrumb1").append(lastspan);
	//	$("#breadcrumb1").append(lastitem);
 }
 function getWidthOfContent() {
              var gwoc = 0;
  $("#breadcrumb1>*").each(function() {gwoc += $(this).width();});
	reporter +="\n\n"+"width of the Breadcrumb trail area = "+$("#breadcrumb1").width()+"\nWidth of it's content  = '"+gwoc+"'";
        if ( $("#breadcrumb1").width()  <= gwoc) {
              	reporter +="\n---exceeded or matched, so remove a high level link\n";
     
        }
  return gwoc;
 }
 reporter = "";
 cdc = 0;
while (getWidthOfContent()>$("#breadcrumb1").width())
  {

	reporter +="num link breadcrumb = "+ tempbciC +"----Now removing item: '" +$("#breadcrumb1 a").slice(1,2).html()+"'";
  		 if ( tempbciC >= bciCThrh) {
		$("#breadcrumb1 a,#breadcrumb1 span").slice(2,3).remove();
		itemsIterativelyRemoved++;
  tempbciC --;
  }
  

  }
if (itemsIterativelyRemoved > 0) {
 $('<span>&hellip;&nbsp;</span>').insertAfter( $("#breadcrumb1 span").first());
 }
 reporter +="\n\n\n\n"+"Added ellipis between home link and the rest\n\n        ... and we're done     \n\n";
 //alert(reporter);
 
 //$("#breadcrumb1").css("width","400px");
 var linkC = 0;
 $("#breadcrumb1 a").each(function() {
	// Create a new bubble node for every link
	linkC++;
	 
	$(this).attr("id","bclink"+linkC); // added a unique ID
	// create a new bubble set
	
 
	var ts = $("<div id=\"bubbleholder"+linkC+"\" class=\"bubblehold\"></div>");
	ts.append("<div class=\"bubble\">"+$(this).attr("title")+"</div><div class=\"bubblepoint\"></div>");
$('#bubbleholder').append(ts);
$(this).attr("title","");
var t = "#bubbleholder"+linkC;
 $(this).mouseenter(function(e) {
	
 
	$(t).css("top",$(this).offset().top + 15);
 
	$(t).css("left",$(this).offset().left );
 
	$(t).css("opacity",0.5);
	$(t).show();
	$(t).animate({
    opacity: 1.0, top: ($(this).offset().top + 20)
  }, 110, function() {
    // Animation complete.
  });
 
 });
  $(this).mouseleave(function(e) {
	 $(t).animate({
    opacity: 0.59, top: ($(this).offset().top + 53)
  }, 120, function() {
    $(t).hide();
  });
  
 
 
 });
  });
  
  });