$(function(){
  footerMenuTableEqualHeight();
});

function footerMenuTableEqualHeight(){
  var h = 0;
  $('#footerMenuTable ul').each(function(){
    var tH = $(this).outerHeight();
    if(h < tH){
      h = tH;
    }
    $(this).height(h);
  });
}


function setVerticalMiddle(tgt){
	var h = $(tgt).outerHeight();
	var ph = $(tgt).parent().height();
	var mt = (ph - h)/2;
	$(tgt).css({"margin-top": mt});
}

// Random Karuta
function random_karuta() {
title = new Array();
link = new Array();
thumb = new Array();

title[0] = '【京】きょうから　はじめる　　セキュリティ';
link[0] = 'http://securityblog.jp/iroha_karuta/794.html';
thumb[0] = 'left_iroha_048kyo.jpg';
title[1] = '【す】鈴木さん　パスワードまで　suzuki3';
link[1] = 'http://securityblog.jp/iroha_karuta/791.html';
thumb[1] = 'left_iroha_047su.jpg';
title[2] = '【せ】セキュリティ　想定外は　想定内';
link[2] = 'http://securityblog.jp/iroha_karuta/789.html';
thumb[2] = 'left_iroha_046se.jpg';
title[3] = '【も】「漏らしました」　その一言を　いう勇気';
link[3] = 'http://securityblog.jp/iroha_karuta/788.html';
thumb[3] = 'left_iroha_045mo.jpg';
title[4] = '【ひ】秘密のファイル　世界デビュー';
link[4] = 'http://securityblog.jp/iroha_karuta/787.html';
thumb[4] = 'left_iroha_044hi.jpg';
title[5] = '【ゑ】ウェブのリンクは　地雷原';
link[5] = 'http://securityblog.jp/iroha_karuta/782.html';
thumb[5] = 'left_iroha_043we.jpg';
title[6] = '【し】社長様　そのパソコンは　裸です';
link[6] = 'http://securityblog.jp/iroha_karuta/779.html';
thumb[6] = 'left_iroha_042shi.jpg';
title[7] = '【み】みんなで共有　みんなで漏えい';
link[7] = 'http://securityblog.jp/iroha_karuta/777.html';
thumb[7] = 'left_iroha_041mi.jpg';
title[8] = '【め】めったに　クラッシュ　するもんだ';
link[8] = 'http://securityblog.jp/iroha_karuta/774.html';
thumb[8] = 'left_iroha_040me.jpg';
title[9] = '【ゆ】油断やミスは　仕組みで　フォロー';
link[9] = 'http://securityblog.jp/iroha_karuta/769.html';
thumb[9] = 'left_iroha_039yu.jpg';
title[10] = '【き】記憶とともに　記録も消えた';
link[10] = 'http://securityblog.jp/iroha_karuta/766.html';
thumb[10] = 'left_iroha_038ki.jpg';
title[11] = '【さ】さきほどの　鍵は別便　別ルート';
link[11] = 'http://securityblog.jp/iroha_karuta/764.html';
thumb[11] = 'left_iroha_037sa.jpg';
title[12] = '【あ】宛先よし　CC確認　出してよし';
link[12] = 'http://securityblog.jp/iroha_karuta/760.html';
thumb[12] = 'left_iroha_036a.jpg';
title[13] = '【て】敵は　煩悩時にあり';
link[13] = 'http://securityblog.jp/iroha_karuta/758.html';
thumb[13] = 'left_iroha_035te.jpg';
title[14] = '【え】「エコだよ」と　裏紙つかって　情報漏えい';
link[14] = 'http://securityblog.jp/iroha_karuta/754.html';
thumb[14] = 'left_iroha_034e.jpg';
title[15] = '【こ】こっそり見ても　ごっそり感染';
link[15] = 'http://securityblog.jp/iroha_karuta/752.html';
thumb[15] = 'left_iroha_033ko.jpg';
title[16] = '【ふ】ブログから　もれて広まる　社内事情';
link[16] = 'http://securityblog.jp/iroha_karuta/747.html';
thumb[16] = 'left_iroha_032fu.jpg';
title[17] = '【け】「消した」は　実は消えてない';
link[17] = 'http://securityblog.jp/iroha_karuta/744.html';
thumb[17] = 'left_iroha_031ke.jpg';
title[18] = '【ま】まるみえ　アドレス　おまけつき';
link[18] = 'http://securityblog.jp/iroha_karuta/742.html';
thumb[18] = 'left_iroha_030ma.jpg';
title[19] = '【や】やっておこうよ　こまめな更新';
link[19] = 'http://securityblog.jp/iroha_karuta/739.html';
thumb[19] = 'left_iroha_029ya.jpg';
title[20] = '【く】クリック危険　添付に注意';
link[20] = 'http://securityblog.jp/iroha_karuta/736.html';
thumb[20] = 'left_iroha_028ku.jpg';
title[21] = '【お】おいらウイルス　USBにも　ひそんでる';
link[21] = 'http://securityblog.jp/iroha_karuta/732.html';
thumb[21] = 'left_iroha_027o.jpg';
title[22] = '【の】残された　その裏口が　命取り';
link[22] = 'http://securityblog.jp/iroha_karuta/727.html';
thumb[22] = 'left_iroha_026no.jpg';
title[23] = '【ゐ】ウィンドウ　ログインしたまま　閉じちゃダメ';
link[23] = 'http://securityblog.jp/iroha_karuta/724.html';
thumb[23] = 'left_iroha_025wi.jpg';
title[24] = '【う】牛にハエ　メアドにスパム';
link[24] = 'http://securityblog.jp/iroha_karuta/722.html';
thumb[24] = 'left_iroha_024u.jpg';
title[25] = '【む】無茶な規則で　オフィスが停止';
link[25] = 'http://securityblog.jp/iroha_karuta/718.html';
thumb[25] = 'left_iroha_023mu.jpg';
title[26] = '【ら】来客に　必要ないのに　情報開示';
link[26] = 'http://securityblog.jp/iroha_karuta/713.html';
thumb[26] = 'left_iroha_022ra.jpg';
title[27] = '【な】夏でも重ね着　風邪予防';
link[27] = 'http://securityblog.jp/iroha_karuta/709.html';
thumb[27] = 'left_iroha_021na.jpg';
title[28] = '【ね】寝かせても　パソコン　だもの...';
link[28] = 'http://securityblog.jp/iroha_karuta/704.html';
thumb[28] = 'left_iroha_020ne.jpg';
title[29] = '【つ】続けなきゃ 継続こそが セキュリティ';
link[29] = 'http://securityblog.jp/iroha_karuta/700.html';
thumb[29] = 'left_iroha_019tsu.jpg';
title[30] = '【そ】その口がセキュリティホール';
link[30] = 'http://securityblog.jp/iroha_karuta/696.html';
thumb[30] = 'left_iroha_018so.jpg';
title[31] = '【れ】霊じゃないあなたの肩ごしのぞいてる';
link[31] = 'http://securityblog.jp/iroha_karuta/691.html';
thumb[31] = 'left_iroha_017re.jpg';
title[32] = '【た】誰かいる　ふたりをつなぐ　糸の上';
link[32] = 'http://securityblog.jp/iroha_karuta/685.html';
thumb[32] = 'left_iroha_016ta.jpg';
title[33] = '【よ】よく言えば共有　実はタダ漏れ？';
link[33] = 'http://securityblog.jp/iroha_karuta/681.html';
thumb[33] = 'left_iroha_015yo.jpg';
title[34] = '【か】架空請求　読まずに捨てた';
link[34] = 'http://securityblog.jp/iroha_karuta/677.html';
thumb[34] = 'left_iroha_014ka.jpg';
title[35] = '【わ】罠がいっぱい野良無線';
link[35] = 'http://securityblog.jp/iroha_karuta/672.html';
thumb[35] = 'left_iroha_013wa.jpg';
title[36] = '【を】ウォッチできちゃうあなたの足跡';
link[36] = 'http://securityblog.jp/iroha_karuta/667.html';
thumb[36] = 'left_iroha_012wo.jpg';
title[37] = '【る】ルール決めてもスルーじゃ台無し';
link[37] = 'http://securityblog.jp/iroha_karuta/662.html';
thumb[37] = 'left_iroha_011ru.jpg';
title[38] = '【ぬ】盗まれた手元にあるけど盗まれた';
link[38] = 'http://securityblog.jp/iroha_karuta/657.html';
thumb[38] = 'left_iroha_010nu.jpg';
title[39] = '【り】理解せず「同意」を押して大失敗';
link[39] = 'http://securityblog.jp/iroha_karuta/652.html';
thumb[39] = 'left_iroha_009ri.jpg';
title[40] = '【ち】躊躇しないでLANから隔離';
link[40] = 'http://securityblog.jp/iroha_karuta/648.html';
thumb[40] = 'left_iroha_008chi.jpg';
title[41] = '【と】匿名と思っているのはあなただけ';
link[41] = 'http://securityblog.jp/iroha_karuta/643.html';
thumb[41] = 'left_iroha_007to.jpg';
title[42] = '【へ】ヘタすりゃスパム善意のチェーン';
link[42] = 'http://securityblog.jp/iroha_karuta/639.html';
thumb[42] = 'left_iroha_006he.jpg';
title[43] = '【ほ】ボット出のウィルスです';
link[43] = 'http://securityblog.jp/iroha_karuta/634.html';
thumb[43] = 'left_iroha_005ho.jpg';
title[44] = '【に】にせ者が にせアドレスで こんにちは';
link[44] = 'http://securityblog.jp/iroha_karuta/631.html';
thumb[44] = 'left_iroha_004ni.jpg';
title[45] = '【は】パスワード　桁けちるな';
link[45] = 'http://securityblog.jp/iroha_karuta/592.html';
thumb[45] = 'left_iroha_003ha.jpg';
title[46] = '【ろ】漏えいで　流れた社運';
link[46] = 'http://securityblog.jp/iroha_karuta/590.html';
thumb[46] = 'left_iroha_002ro.jpg';
title[47] = '【い】いつのまに　デスクトップが　ゴミ屋敷';
link[47] = 'http://securityblog.jp/iroha_karuta/586.html';
thumb[47] = 'left_iroha_001i.jpg';

i=Math.floor(Math.random() * 48);
document.write("<div class='randomKaruta'>");
document.write("<h2><a href='http://securityblog.jp/iroha_karuta.html'><img src='/common/images/sidekaruta_title.jpg' width='188' height='35' alt='セキュリティいろはかるた' /></a></h2>");
document.write("<span class='thumbnail'><a href='" + link[i] + "'><img alt='" + title[i] + "' src='/common/images/karuta/" + thumb[i] + "' width='80' height='105' /></a></span>");
document.write("<span><a class='yomifuda' href='" + link[i] + "'>" + title[i] + "</a></span>");
document.write("<span class='tRight'><a class='list' href='http://securityblog.jp/iroha_karuta.html'>絵札一覧</a></span>");
document.write("</div>");
}



/* Mouse-Over
--------------------------------------------------------*/

$(function(over){
    $(".over").mouseover(function(){
        $(this).attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_over$2"))
    }).mouseout(function(){
        $(this).attr("src",$(this).attr("src").replace(/^(.+)_over(\.[a-z]+)$/, "$1$2"));
    }).each(function(){
        $("<img>").attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_over$2"))
    })
});

/*** focus text  ***/

$(function(){
	$(".textInput").val("検索キーワードを入力")
	   .css("color","#969696");
	$(".textInput").focus(function(){
		if(this.value == "検索キーワードを入力"){
			$(this).val("").css("color","#000");
		}
	});
	$(".textInput").blur(function(){
		if(this.value == ""){
			$(this).val("検索キーワードを入力")
			     .css("color","#969696");
		}
		if(this.value != "検索キーワードを入力"){
			$(this).css("color","#000");
		}
	});
});

$(function(){
	$(".searchBox").val("検索キーワードを入力")
	   .css("color","#969696");
	$(".searchBox").focus(function(){
		if(this.value == "検索キーワードを入力"){
			$(this).val("").css("color","#000");
		}
	});
	$(".searchBox").blur(function(){
		if(this.value == ""){
			$(this).val("検索キーワードを入力")
			     .css("color","#969696");
		}
		if(this.value != "検索キーワードを入力"){
			$(this).css("color","#000");
		}
	});
});

/* Suggest
--------------------------------------------------------
suggest.js - Input Suggest
Version 2.1.1 (Update 2009/10/04)
Copyright (c) 2006-2009 onozaty (http://www.enjoyxstudy.com)
Released under an MIT-style license.
For details, see the web site:
 http://www.enjoyxstudy.com/javascript/suggest/
--------------------------------------------------------*/

if (!Suggest) {
  var Suggest = {};
}

Suggest.Key = {
  TAB:     9,
  RETURN: 13,
  ESC:    27,
  UP:     38,
  DOWN:   40
};

Suggest.copyProperties = function(dest, src) {
  for (var property in src) {
    dest[property] = src[property];
  }
  return dest;
};

Suggest.Local = function() {
  this.initialize.apply(this, arguments);
};
Suggest.Local.prototype = {
  initialize: function(input, suggestArea, candidateList) {

    this.input = this._getElement(input);
    this.suggestArea = this._getElement(suggestArea);
    this.candidateList = candidateList;
    this.oldText = this.getInputText();

    if (arguments[3]) this.setOptions(arguments[3]);

    // reg event
    this._addEvent(this.input, 'focus', this._bind(this.checkLoop));
    this._addEvent(this.input, 'blur', this._bind(this.inputBlur));

    var keyevent = 'keydown';
    if (window.opera || (navigator.userAgent.indexOf('Gecko') >= 0 && navigator.userAgent.indexOf('KHTML') == -1)) {
      keyevent = 'keypress';
    }
    this._addEvent(this.input, keyevent, this._bindEvent(this.keyEvent));

    // init
    this.clearSuggestArea();
  },

  // options
  interval: 500,
  dispMax: 20,
  listTagName: 'div',
  prefix: false,
  ignoreCase: true,
  highlight: false,
  dispAllKey: false,
  classMouseOver: 'over',
  classSelect: 'select',
  hookBeforeSearch: function(){},

  setOptions: function(options) {
    Suggest.copyProperties(this, options);
  },

  inputBlur: function() {

    this.changeUnactive();
    this.oldText = this.getInputText();

    if (this.timerId) clearTimeout(this.timerId);
    this.timerId = null;

    setTimeout(this._bind(this.clearSuggestArea), 500);
  },

  checkLoop: function() {
    var text = this.getInputText();
    if (text != this.oldText) {
      this.oldText = text;
      this.search();
    }
    if (this.timerId) clearTimeout(this.timerId);
    this.timerId = setTimeout(this._bind(this.checkLoop), this.interval);
  },

  search: function() {

    // init
    this.clearSuggestArea();

    var text = this.getInputText();

    if (text == '' || text == null) return;

    this.hookBeforeSearch(text);
    var resultList = this._search(text);
    if (resultList.length != 0) this.createSuggestArea(resultList);
  },

  _search: function(text) {

    var resultList = [];
    var temp; 
    this.suggestIndexList = [];

    for (var i = 0, length = this.candidateList.length; i < length; i++) {
      if ((temp = this.isMatch(this.candidateList[i], text)) != null) {
        resultList.push(temp);
        this.suggestIndexList.push(i);

        if (this.dispMax != 0 && resultList.length >= this.dispMax) break;
      }
    }
    return resultList;
  },

  isMatch: function(value, pattern) {

    if (value == null) return null;

    var pos = (this.ignoreCase) ?
      value.toLowerCase().indexOf(pattern.toLowerCase())
      : value.indexOf(pattern);

    if ((pos == -1) || (this.prefix && pos != 0)) return null;

    if (this.highlight) {
      return (this._escapeHTML(value.substr(0, pos)) + '<strong>' 
             + this._escapeHTML(value.substr(pos, pattern.length)) 
               + '</strong>' + this._escapeHTML(value.substr(pos + pattern.length)));
    } else {
      return this._escapeHTML(value);
    }
  },

  clearSuggestArea: function() {
    this.suggestArea.innerHTML = '';
    this.suggestArea.style.display = 'none';
    this.suggestList = null;
    this.suggestIndexList = null;
    this.activePosition = null;
  },

  createSuggestArea: function(resultList) {

    this.suggestList = [];
    this.inputValueBackup = this.input.value;

    for (var i = 0, length = resultList.length; i < length; i++) {
      var element = document.createElement(this.listTagName);
      element.innerHTML = resultList[i];
      this.suggestArea.appendChild(element);

      this._addEvent(element, 'click', this._bindEvent(this.listClick, i));
      this._addEvent(element, 'mouseover', this._bindEvent(this.listMouseOver, i));
      this._addEvent(element, 'mouseout', this._bindEvent(this.listMouseOut, i));

      this.suggestList.push(element);
    }

    this.suggestArea.style.display = '';
  },

  getInputText: function() {
    return this.input.value;
  },

  setInputText: function(text) {
    this.input.value = text;
  },

  // key event
  keyEvent: function(event) {

    if (!this.timerId) {
      this.timerId = setTimeout(this._bind(this.checkLoop), this.interval);
    }

    if (this.dispAllKey && event.ctrlKey 
        && this.getInputText() == ''
        && !this.suggestList
        && event.keyCode == Suggest.Key.DOWN) {
      // dispAll
      this._stopEvent(event);
      this.keyEventDispAll();
    } else if (event.keyCode == Suggest.Key.UP ||
               event.keyCode == Suggest.Key.DOWN) {
      // key move
      if (this.suggestList && this.suggestList.length != 0) {
        this._stopEvent(event);
        this.keyEventMove(event.keyCode);
      }
    } else if (event.keyCode == Suggest.Key.RETURN) {
      // fix
      if (this.suggestList && this.suggestList.length != 0) {
        this._stopEvent(event);
        this.keyEventReturn();
      }
    } else if (event.keyCode == Suggest.Key.ESC) {
      // cancel
      if (this.suggestList && this.suggestList.length != 0) {
        this._stopEvent(event);
        this.keyEventEsc();
      }
    } else {
      this.keyEventOther(event);
    }
  },

  keyEventDispAll: function() {

    // init
    this.clearSuggestArea();

    this.oldText = this.getInputText();

    this.suggestIndexList = [];
    for (var i = 0, length = this.candidateList.length; i < length; i++) {
      this.suggestIndexList.push(i);
    }

    this.createSuggestArea(this.candidateList);
  },

  keyEventMove: function(keyCode) {

    this.changeUnactive();

    if (keyCode == Suggest.Key.UP) {
      // up
      if (this.activePosition == null) {
        this.activePosition = this.suggestList.length -1;
      }else{
        this.activePosition--;
        if (this.activePosition < 0) {
          this.activePosition = null;
          this.input.value = this.inputValueBackup;
          return;
        }
      }
    }else{
      // down
      if (this.activePosition == null) {
        this.activePosition = 0;
      }else{
        this.activePosition++;
      }

      if (this.activePosition >= this.suggestList.length) {
        this.activePosition = null;
        this.input.value = this.inputValueBackup;
        return;
      }
    }

    this.changeActive(this.activePosition);
  },

  keyEventReturn: function() {

    this.clearSuggestArea();
    this.moveEnd();
  },

  keyEventEsc: function() {

    this.clearSuggestArea();
    this.input.value = this.inputValueBackup;
    this.oldText = this.getInputText();

    if (window.opera) setTimeout(this._bind(this.moveEnd), 5);
  },

  keyEventOther: function(event) {},

  changeActive: function(index) {

    this.setStyleActive(this.suggestList[index]);

    this.setInputText(this.candidateList[this.suggestIndexList[index]]);

    this.oldText = this.getInputText();
    this.input.focus();
  },

  changeUnactive: function() {

    if (this.suggestList != null 
        && this.suggestList.length > 0
        && this.activePosition != null) {
      this.setStyleUnactive(this.suggestList[this.activePosition]);
    }
  },

  listClick: function(event, index) {

    this.changeUnactive();
    this.activePosition = index;
    this.changeActive(index);

    this.moveEnd();
  },

  listMouseOver: function(event, index) {
    this.setStyleMouseOver(this._getEventElement(event));
  },

  listMouseOut: function(event, index) {

    if (!this.suggestList) return;

    var element = this._getEventElement(event);

    if (index == this.activePosition) {
      this.setStyleActive(element);
    }else{
      this.setStyleUnactive(element);
    }
  },

  setStyleActive: function(element) {
    element.className = this.classSelect;
  },

  setStyleUnactive: function(element) {
    element.className = '';
  },

  setStyleMouseOver: function(element) {
    element.className = this.classMouseOver;
  },

  moveEnd: function() {

    if (this.input.createTextRange) {
      this.input.focus(); // Opera
      var range = this.input.createTextRange();
      range.move('character', this.input.value.length);
      range.select();
    } else if (this.input.setSelectionRange) {
      this.input.setSelectionRange(this.input.value.length, this.input.value.length);
    }
  },

  // Utils
  _getElement: function(element) {
    return (typeof element == 'string') ? document.getElementById(element) : element;
  },
  _addEvent: (window.addEventListener ?
    function(element, type, func) {
      element.addEventListener(type, func, false);
    } :
    function(element, type, func) {
      element.attachEvent('on' + type, func);
    }),
  _stopEvent: function(event) {
    if (event.preventDefault) {
      event.preventDefault();
      event.stopPropagation();
    } else {
      event.returnValue = false;
      event.cancelBubble = true;
    }
  },
  _getEventElement: function(event) {
    return event.target || event.srcElement;
  },
  _bind: function(func) {
    var self = this;
    var args = Array.prototype.slice.call(arguments, 1);
    return function(){ func.apply(self, args); };
  },
  _bindEvent: function(func) {
    var self = this;
    var args = Array.prototype.slice.call(arguments, 1);
    return function(event){ event = event || window.event; func.apply(self, [event].concat(args)); };
  },
  _escapeHTML: function(value) {
    return value.replace(/\&/g, '&amp;').replace( /</g, '&lt;').replace(/>/g, '&gt;')
             .replace(/\"/g, '&quot;').replace(/\'/g, '&#39;');
  }
};

Suggest.LocalMulti = function() {
  this.initialize.apply(this, arguments);
};
Suggest.copyProperties(Suggest.LocalMulti.prototype, Suggest.Local.prototype);

Suggest.LocalMulti.prototype.delim = ' '; // delimiter

Suggest.LocalMulti.prototype.keyEventReturn = function() {

  this.clearSuggestArea();
  this.input.value += this.delim;
  this.moveEnd();
};

Suggest.LocalMulti.prototype.keyEventOther = function(event) {

  if (event.keyCode == Suggest.Key.TAB) {
    // fix
    if (this.suggestList && this.suggestList.length != 0) {
      this._stopEvent(event);

      if (!this.activePosition) {
        this.activePosition = 0;
        this.changeActive(this.activePosition);
      }

      this.clearSuggestArea();
      this.input.value += this.delim;
      if (window.opera) {
        setTimeout(this._bind(this.moveEnd), 5);
      } else {
        this.moveEnd();
      }
    }
  }
};

Suggest.LocalMulti.prototype.listClick = function(event, index) {

  this.changeUnactive();
  this.activePosition = index;
  this.changeActive(index);

  this.input.value += this.delim;
  this.moveEnd();
};

Suggest.LocalMulti.prototype.getInputText = function() {

  var pos = this.getLastTokenPos();

  if (pos == -1) {
    return this.input.value;
  } else {
    return this.input.value.substr(pos + 1);
  }
};

Suggest.LocalMulti.prototype.setInputText = function(text) {

  var pos = this.getLastTokenPos();

  if (pos == -1) {
    this.input.value = text;
  } else {
    this.input.value = this.input.value.substr(0 , pos + 1) + text;
  }
};

Suggest.LocalMulti.prototype.getLastTokenPos = function() {
  return this.input.value.lastIndexOf(this.delim);
};

// SmoothScroll

var ss = {
  fixAllLinks: function() {
    // Get a list of all links in the page
    var allLinks = document.getElementsByTagName('a');
    // Walk through the list
    for (var i=0;i<allLinks.length;i++) {
      var lnk = allLinks[i];
      if ((lnk.href && lnk.href.indexOf('#') != -1) && 
          ( (lnk.pathname == location.pathname) ||
	    ('/'+lnk.pathname == location.pathname) ) && 
          (lnk.search == location.search)) {
        // If the link is internal to the page (begins in #)
        // then attach the smoothScroll function as an onclick
        // event handler
        ss.addEvent(lnk,'click',ss.smoothScroll);
      }
    }
  },

  smoothScroll: function(e) {
    // This is an event handler; get the clicked on element,
    // in a cross-browser fashion
    if (window.event) {
      target = window.event.srcElement;
    } else if (e) {
      target = e.target;
    } else return;

    // Make sure that the target is an element, not a text node
    // within an element
    if (target.nodeName.toLowerCase() != 'a') {
      target = target.parentNode;
    }
  
    // Paranoia; check this is an A tag
    if (target.nodeName.toLowerCase() != 'a') return;
  
    // Find the <a name> tag corresponding to this href
    // First strip off the hash (first character)
    anchor = target.hash.substr(1);
    // Now loop all A tags until we find one with that name
    var allLinks = document.getElementsByTagName('a');
    var destinationLink = null;
    for (var i=0;i<allLinks.length;i++) {
      var lnk = allLinks[i];
      if (lnk.name && (lnk.name == anchor)) {
        destinationLink = lnk;
        break;
      }
    }
  
    // If we didn't find a destination, give up and let the browser do
    // its thing
    if (!destinationLink) return true;
  
    // Find the destination's position
    var destx = destinationLink.offsetLeft; 
    var desty = destinationLink.offsetTop;
    var thisNode = destinationLink;
    while (thisNode.offsetParent && 
          (thisNode.offsetParent != document.body)) {
      thisNode = thisNode.offsetParent;
      destx += thisNode.offsetLeft;
      desty += thisNode.offsetTop;
    }
  
    // Stop any current scrolling
    clearInterval(ss.INTERVAL);
  
    cypos = ss.getCurrentYPos();
  
    ss_stepsize = parseInt((desty-cypos)/ss.STEPS);
    ss.INTERVAL =
setInterval('ss.scrollWindow('+ss_stepsize+','+desty+',"'+anchor+'")',10);
  
    // And stop the actual click happening
    if (window.event) {
      window.event.cancelBubble = true;
      window.event.returnValue = false;
    }
    if (e && e.preventDefault && e.stopPropagation) {
      e.preventDefault();
      e.stopPropagation();
    }
  },

  scrollWindow: function(scramount,dest,anchor) {
    wascypos = ss.getCurrentYPos();
    isAbove = (wascypos < dest);
    window.scrollTo(0,wascypos + scramount);
    iscypos = ss.getCurrentYPos();
    isAboveNow = (iscypos < dest);
    if ((isAbove != isAboveNow) || (wascypos == iscypos)) {
      // if we've just scrolled past the destination, or
      // we haven't moved from the last scroll (i.e., we're at the
      // bottom of the page) then scroll exactly to the link
      window.scrollTo(0,dest);
      // cancel the repeating timer
      clearInterval(ss.INTERVAL);
      // and jump to the link directly so the URL's right
      location.hash = anchor;
    }
  },

  getCurrentYPos: function() {
    if (document.body && document.body.scrollTop)
      return document.body.scrollTop;
    if (document.documentElement && document.documentElement.scrollTop)
      return document.documentElement.scrollTop;
    if (window.pageYOffset)
      return window.pageYOffset;
    return 0;
  },

  addEvent: function(elm, evType, fn, useCapture) {
    // addEvent and removeEvent
    // cross-browser event handling for IE5+,  NS6 and Mozilla
    // By Scott Andrew
    if (elm.addEventListener){
      elm.addEventListener(evType, fn, useCapture);
      return true;
    } else if (elm.attachEvent){
      var r = elm.attachEvent("on"+evType, fn);
      return r;
    } else {
      alert("Handler could not be removed");
    }
  } 
}

ss.STEPS = 25;
ss.addEvent(window,"load",ss.fixAllLinks);


