jQuery.fn.QuickMenu = function()
{
  $('ul.quickmenu-data li').addClass('quickmenuitem');
  $('ul.quickmenu-data li:has(ul)').addClass('quickmenuitem-haschildren');
  $('ul.quickmenu-data, ul.quickmenu-data ul').each(assigneachPaneId);
  $('ul.quickmenupane').each(addNavigationLinks);
  $('.quickmenuitem a').wrapInner('<div class="item"></div>');
  $('#menuholder').empty();
  $('.quickmenupane').appendTo('#menuholder');
  $('#quickmenupane0').show();
}

function addNavigationLinks()
{    
  var parentPageId = $(this).attr('id');
  $(this).children('li has(ul)').each(function()
  {
    var parentCallback = 'unshowPane(\'#' + parentPageId + '\', \'#' + $(this).children('ul:first').attr('id') + '\')';
    var parentName = $(this).children('a:first').text();
    var linkId = parentPageId + '_link';
    $(this).children('ul').prepend('<div onclick="' + parentCallback + '" class="parentLink">' + parentName + '</div>')
  });
}

var n = 0;
var paneId = 0;

function assigneachItem()
{
  this.id = 'quickmenuitem' + n++;
}

function assigneachPaneId() 
{
  var newId = 'quickmenupane' + paneId++;
  this.id = newId;

  $(this).addClass('quickmenupane');
  $(this).css('display', 'none');

  var callback = 'showPane(\'#' + newId + '\');';

  $(this).parent().children('a').attr('href', 'javascript://');
  $(this).parent().click(function()
  {
    eval(callback);
  });
}

function showPane(paneId)
{
  var title = $('' + paneId + ' .parentLink').get(0);
  if(title)
  {
    var pp = $('.parentLinkStart');
    pp.addClass('path');
    var p = pp.get(0);
    p.innerHTML = p.innerHTML.replace(/<\/?strong>/ig, '') + ' &gt; ' + '<strong>' + title.innerHTML + '</strong>';
  }
  $(paneId).menuLeft(200, '', '');
}

jQuery.fn.menuLeft = function(speed, easing, callback)
{
  $(this).css('width', '0px');
  $(this).css('margin-left', '220px');
  $(this).show();
  return $(this).animate({ width: '220px', marginLeft: '0px' }, speed);
}

jQuery.fn.menuRight = function(speed, easing, callback)
{
  $(this).css('width', '0px');
  $(this).css('margin-right', '0px');
  return $(this).animate({ width: '220px', marginRight: '220px' }, speed, null, callback);
}

function unshowPane(paneId, unshowpaneId)
{
  $(unshowpaneId).fadeOut(200);
  $(paneId).fadeIn(200);
  var pp = $('.parentLinkStart');
  var p = pp.get(0);
  p.innerHTML = p.innerHTML.replace(/ &gt;[^&]*?$/, '').replace(/( &gt;)([^&]*?)$/, '$1<strong>$2</strong>');
  if(!/<strong>/i.test(p.innerHTML))
    pp.removeClass('path');
}
