$(document).ready(function() {
	// Collapse everything but the first menu:
	$("#Menu a").not(":first").find("+ ul").slideUp(1);
	$("#Menu li:first a").addClass("active")
	$("#Menu ul li a").not(":first").find("p").slideUp(1);
	
	// Expand or collapse:
	$("#Menu>li>a").click(function() {
       if($(this).is(".active")) return false;
       $("#Menu a").not(this).removeClass("active");
	   $("#Menu ul:visible").not($(this).next("ul")[0]).slideUp();
		$(this).addClass("active").find("+ ul").slideDown("fast", function(){$(this).css("height", "auto")});
        $("+ ul p:first", this).show();
		return false;
	});
	$("#Menu ul li a").click(function() {
	   $(this).find("p").slideToggle("fast");
	   return false;
	});
});

$(document).ready(function() {
  $(".picform").change(function() {
    $(this).trigger('submit')
  });;
  $(".picform input[@type=submit]").hide()
  
  if ($(".caledit").is("body")) {
    $("#main .admin a.ajax").bind('click', function(event) {
      $("#cal").load(this.href + " #cal", function(){
        $(".pagination :first").html("<img src='/images/leftarrow.png' width='16' height='16' />")
        $(".pagination :last").html("<img src='/images/rightarrow.png' width='16' height='16' />")

      })
      return false;
    });
    $(".pagination :first").html("<img src='/images/leftarrow.png' width='16' height='16' />")
    $(".pagination :last").html("<img src='/images/rightarrow.png' width='16' height='16' />")
  };
  
  if ($(".current-picture").is("p")){
    $("input:file").parent().hide()
    $("#image_upload h1").css('cursor', 'pointer').append('<span>(Click To Update)</span>')
    $("#image_upload .current-picture").bind('click', function(event) {
      $("input:file").parent().show()
      $("#image_upload .current-picture").hide()
    });
    $("#image_upload h1").toggle(function() {
      $("input:file").parent().hide()
      $("#image_upload .current-picture").show()
      $("#image_upload h1 span").html('(Click To Update)')
    }, function() {
      $("input:file").parent().show()
      $("#image_upload .current-picture").hide()
      $("#image_upload h1 span").html('(Click To Cancel)')
  });
  };
});



