/*
 * menu
 */
jQuery.fn.sprites = function(settings) {
  settings = jQuery.extend({
    allowClick: true,
    show: {opacity: 'show'},
    hide: {opacity: 'hide'},
    active: 'active',
    click: 'click'
  }, settings);

  // Attach events to each child
  $(this).children().each(function(){
    // Do not attach events to active children
    if(!$(this).hasClass(settings.active)){
      //hide the css defined :hover background
      $(this).children('a').css({background: "none"});
      $(this).hover(function() {
          $('<div id="sprites_action" style="display:none"></div>').prependTo(this).animate(settings.show);		
        },
        function(){
          $(this).children('div').animate(settings.hide, function(){
            $("#sprites_action").remove();
          });
      });
      //click events on the a if allowClick is true
      if(settings.allowClick){
        $(this).children('a').mousedown(function(){
            $(this).prev().addClass('click');
          }).mouseup(function(){
            $(this).prev().removeClass('click');
          });
      }
    }
  });
};

/*
 * BASE64 (RFC2045) Encode/Decode for string in JavaScript
 * Version 1.1 Oct. 25 2003 written by MIZUTANI Tociyuki
 * Copyright 2003-2004 MIZUTANI Tociyuki
 *
 * This code is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 * caution:
 * 1) Wide characters like japanese kanji are not supported. Use only in Latin-1.
 * 2) base64decode() cannot generate a string including null characters.
 */
var base64list = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';

function base64encode(s) {
  var t = '', p = -6, a = 0, i = 0, v = 0, c;

  while ( (i < s.length) || (p > -6) ) {
    if ( p < 0 ) {
      if ( i < s.length ) {
        c = s.charCodeAt(i++);
        v += 8;
      } else {
        c = 0;
      }
      a = ((a&255)<<8)|(c&255);
      p += 8;
    }
    if ( v > 0 )
      t += base64list.charAt((a>>p)&63);
    else
      t += base64list.charAt(64);
    p -= 6;
    v -= 6;
  }
  return t;
}

function base64decode(s) {
  var t = '', p = -8, a = 0, q = 0, c, m, n;

  for( var i = 0; i < s.length; i++ ) {
    c = base64list.indexOf(s.charAt(i));
    if ( c < 0 )
      continue;
    a = (a<<6)|(c&63);
    p += 6;
    if ( p >= 0 ) {
      c = (a>>p)&255;
      if ( c > 0 )
        t += String.fromCharCode(c);
      a &= 63;
      p -= 8;
    }
  }
  return t;
}
