jQuery.cookie = function (key, value, options) {

    // key and value given, set cookie...
    if (arguments.length > 1 && (value === null || typeof value !== "object")) {
        options = jQuery.extend({}, options);

        if (value === null) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }

        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? String(value) : encodeURIComponent(String(value)),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};

$(document).ready(function() {
  var mbr_name = $.cookie('membername');
  if (mbr_name && mbr_name.length > 2) {
    if (mbr_name.charAt(0) == '"')
      mbr_name = mbr_name.slice(1,-1);
    $('span.welcome').text('Welcome ' + mbr_name);
  }

  $("#pde a:nth-child(2)").click(function() {window.open("/forms/download"+window.location.pathname, 'resizable,scrollbars'); return false;});

  var page = $("body").attr("class");
  if (page.indexOf("about") != -1) {$("ul.about").show(); $("b#about").addClass("fixed");}
  if (page.indexOf("members") != -1) {$("ul.members").show(); $("b#members").addClass("fixed");}
  if (page.indexOf("meetings") != -1) {$("ul.meetings").show(); $("b#meetings").addClass("fixed");}
  if (page.indexOf("news") != -1) {$("ul.news").show(); $("b#news").addClass("fixed");}
  if (page.indexOf("publications") != -1) {$("ul.publications").show(); $("b#publications").addClass("fixed");}
  if (page.indexOf("pressroom") != -1) {$("ul.pressroom").show(); $("b#pressroom").addClass("fixed");}
  if (page.indexOf("aprlmember") != -1) {$("ul.aprlmember").show(); $("b#aprlmember").addClass("fixed");}

  $("b.sub").click(function(){
  	if(this.className.indexOf("fixed") != -1) {
  		$("b.current").next().slideUp(400);
  		$("b.current").removeClass("current");
  	}

  	if(this.className.indexOf("fixed") == -1) {
	if(this.className.indexOf("current") == -1) {
		$("b.current").css("backgroundImage","url(/images/arrowa.gif)");
		$("b.current").css("backgroundRepeat","no-repeat");
		$("b.current").css("backgroundPosition","10px center");
		id = $(this).attr("id");
		$('b.sub').each(function() {
			id = $(this).attr("id");
			if (page.indexOf(id) == -1) {
			$(this).next().slideUp(400);
			}
		});
		$("b.sub").removeClass("current");
		$(this).next().slideDown(400);
		$(this).addClass("current");
	}
	else {
		$(this).removeClass("current");
		$(this).next().slideUp(400);
	}
	}
  });

  $("b.sub").mouseover(function(){
	$(this).css("backgroundImage","url(/images/arrowb.gif)");
	$(this).css("backgroundRepeat","no-repeat");
	$(this).css("backgroundPosition","10px center");
  });
  $("b.sub").mouseout(function(){
	if(this.className.indexOf("current") == -1 && this.className.indexOf("fixed") == -1 ) {
	$(this).css("backgroundImage","url(/images/arrowa.gif)");
	$(this).css("backgroundRepeat","no-repeat");
	$(this).css("backgroundPosition","10px center");
	}
  });

});

