$(document).ready(function() {
	h = $("#content").height();
	H = $("#avmenu").height();
	HE = $("#extras").height();
	if (H > h) { 
		H = H + 20;
		$("#content").height(H);
		h = H;
	}
	if (HE > h) {
		H = HE + 20
		$("#content").height(H);
		h = H;
	}
	$("#menuwrapper").height(h);
	$("#extraswrapper").height(h);

	movebars();

});

$(function(){

 $('input[name=searchphoneno]').keyup(function(){
    var keywords = $('input[name=searchphoneno]').val().toLowerCase();
    $('table.phoneno tbody tr').search(keywords, function(keywords){
      var matches = $.map(this.children('td'), function(td){
        return $(td).text().toLowerCase().match(keywords)
      })
      return !matches.length
    })
  })

});

$(window).scroll(function () {
	movebars();
});
	

function movebars() {
	if ($(document).scrollTop() < $("#menuwrapper").position().top) {
		offset = "0px";
	} else {
		if (($(document).scrollTop()) < $("#menuwrapper").height()) {
			offset = $(document).scrollTop() - $("#header").height() - $("#topmenu").height() - 15 +"px";
		} else {
			offset = $("#menuwrapper").height() - $("#avmenu").height() + "px";
		}
	}
        $("#avmenu").animate({top:offset},{duration:400,queue:false});


	if ($(document).scrollTop() < $("#extraswrapper").position().top) {
		offset = "0px";
	} else {
		if (($(document).scrollTop()) < $("#extraswrapper").height()) {
			offset = $(document).scrollTop() - $("#header").height() - $("#topmenu").height() - 15 +"px";
		} else {
			offset = $("#extraswrapper").height() - $("#extras").height() + "px";
		}
	}
        $("#extras").animate({top:offset},{duration:400,queue:false});
}

