function jiggle_tooldrawer() {
  new Element.hide ('tooldrawer');
  new Element.show ('tooldrawer');
}
function resize_handle(id) {
  $('handle_' + id).style.height = Element.getHeight($('v_stretch_' + id) ) + 'px';
}
function hide_tip() {
  new Effect.BlindUp($('tip_of_the_day_anchor'));
}
function show_indicator(el) {
  Element.show($('loading'));
  $('_body').style.cursor = 'wait';

  if (el && !($('loading_' + el))) {
    html = '<div class="loading" id="loading_' + el + '"><img src="/images/pixel_loading.gif"></div>';
    new Insertion.Top(el, html);
  }
}
function hide_indicator() {
  hide_indicator(null);
}
function hide_indicator(el) {
  if ($('loading') ) Effect.Fade($('loading'));
  if ($('_body') ) $('_body').style.cursor = '';
  if (el) new Element.remove($('loading_' + el));
}
function show_tooldrawer_indicator() {
  show_indicator();
  $('h_menu_3').className = '';
  $('h_menu_3').innerHTML = 'Loading&#8230;';
}
function add_load_event(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

add_load_event(hide_indicator);

function show_add_cat() {
  new Effect.toggle('add_category', 'blind');
  new Effect.toggle('categories', 'blind');
}

function hide_add_cat() {
  new Effect.BlindUp('add_category');
  new Effect.BlindDown('categories');
}

function show_edit_cat(id, colour) {
  $('edit_label_name').value = $("folder_label_" + id).innerHTML;
  $('edit_label_id').value = id;
  $('edit_label_' + colour).checked = "checked";
  new Effect.Appear('edit_category');
}

function hide_edit_cat() {
  new Effect.Fade('edit_category');
}

// Keeps track of the current active folder, set to -1 when no folder is active

var active_folder_id = -1;

function change_task_count(delta)
{
    if (active_folder_id > -1)
    {
        el = $("label_count_" + active_folder_id);
        x = parseInt(el.innerHTML);
        el.innerHTML = x + delta;
    }
}

// used in _categories.rhtml
/*
   note: dragdrop.js has been modified for this to work, lookout for:
        // start excuseme edit
        [code change]
        // end excuseme edit

        there is also a global defined called 'is_dragging'
*/


var LabelWatcher = Class.create();

// defining the rest of the class implementation
// which we shouldn't be defining over and over
// but if it is moved out of this code block it fails in moz

LabelWatcher.prototype = {

  initialize: function(dropEl, dropElImg, colour) {
    this.dropEl = $(dropEl);
    this.dropElImg = $(dropElImg);
    this.colour = colour;
    //assigning our method to the event

    this.dropEl.onmouseout  = this.deactivate.bindAsEventListener(this);
    this.dropEl.onmouseover = this.activate.bindAsEventListener(this);
  },

  activate: function(evt) {
    if (is_dragging) {
      this.dropElImg.src = eval(this.colour + '_on.src');
    } else {
      this.dropElImg.src = eval(this.colour + '_over.src');
    }
  },

  deactivate: function(evt) {
    this.dropElImg.src = eval(this.colour + '_off.src');
  }
};


function setCookie(cookieName,cookieValue,nDays) {
  var today = new Date();
  var expire = new Date();
  if (nDays==null || nDays==0) nDays=1;
  expire.setTime(today.getTime() + 3600000*24*nDays);
  document.cookie = cookieName+'='+escape(cookieValue)
                 + ';expires='+expire.toGMTString();
}

function readCookie(cookieName) {
  var theCookie=''+document.cookie;
  var ind=theCookie.indexOf(cookieName);
  if (ind==-1 || cookieName=='') return '';
  var ind1=theCookie.indexOf(';',ind);
  if (ind1==-1) ind1=theCookie.length;
  return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}




/***********************************************
* Floating Top Bar script- © Dynamic Drive (www.dynamicdrive.com)
* Sliding routine by Roy Whittle (http://www.javascript-fx.com/)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

var startX = 0;
var startY = 0; //set y offset of bar in pixels
var minY = 0; // Don't scroll above this
var float_once = true;

function iecompattest() {
    return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function init_tooldrawer_following() {

    var ns = (navigator.appName.indexOf("Netscape") != -1);
    var d = document;

    function ml(id) {
        var el = d.getElementById(id);
        el.sP = function(x,y) { this.style.left = x + "px";
                                this.style.top  = y + "px"; };
        el.x = startX;
        el.y = startY;
        return el;
    }

    window.stayTopLeft=function (){
        var tY = ns ? pageYOffset : iecompattest().scrollTop;
        var bY = ns ? pageYOffset + innerHeight : iecompattest().scrollTop + iecompattest().clientHeight;

        ftlObj.y += (tY + startY - ftlObj.y)/8;
        ftlObj.x = 0;

        // The additional is for the decoration above and below the div
        h = Element.getHeight("tooldrawer_content") + 210;

        // Only auto scroll if the content is completely within the view port
        if (bY - tY > h) {
            ftlObj.sP(ftlObj.x, ftlObj.y);
        }
        if (float_once) {
            ftlObj.sP(ftlObj.x, ftlObj.y);
            float_once = false;
        }
        setTimeout("stayTopLeft()", 10);

    }
    ftlObj = ml("tooldrawer_anchor");
    stayTopLeft();
}


var tooldrawer_scroll_offset;

function saveScroll()
{
    Position.prepare();
    offset = Position.realOffset($('categories') );
    tooldrawer_scroll_offset = offset[1] - Position.deltaY;
}

function loadScroll() {
    setTimeout("$('categories').scrollTop = tooldrawer_scroll_offset",50);
}
