/*  Prototype: an object-oriented Javascript library, version 1.2.0
 *  (c) 2005 Sam Stephenson <sam@conio.net>
 *
 *  THIS FILE IS AUTOMATICALLY GENERATED. When sending patches, please diff
 *  against the source tree, available from the Prototype darcs repository. 
 *
 *  Prototype is freely distributable under the terms of an MIT-style license.
 *
 *  For details, see the Prototype web site: http://prototype.conio.net/
 *
/*--------------------------------------------------------------------------*/

/*  Added for real time search */
var observerOnclick = '';
/*  End */

/*  Added for demo */
var demo_bgcolor = '';
var demo_hlcolor = '';
var demo_width = '';
var demo_fontsize = '';
var demo_numdisplay = '';
/*  End */

var Prototype = {
  Version: '1.2.0'
}

var Class = {
  create: function() {
    return function() { 
      this.initialize.apply(this, arguments);
    }
  }
}

var Abstract = new Object();

Object.prototype.extend = function(object) {
  for (property in object) {
    this[property] = object[property];
  }
  return this;
}

Function.prototype.bind = function(object) {
  var method = this;
  return function() {
    method.apply(object, arguments);
  }
}

Function.prototype.bindAsEventListener = function(object) {
  var method = this;
  return function(event) {
    method.call(object, event || window.event);
  }
}

Number.prototype.toColorPart = function() {
  var digits = this.toString(16);
  if (this < 16) return '0' + digits;
  return digits;
}

var Try = {
  these: function() {
    var returnValue;
    
    for (var i = 0; i < arguments.length; i++) {
      var lambda = arguments[i];
      try {
        returnValue = lambda();
        break;
      } catch (e) {}
    }
    
    return returnValue;
  }
}

/*--------------------------------------------------------------------------*/

function $() {
  var elements = new Array();
  
  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1) 
      return element;
      
    elements.push(element);
  }
  
  return elements;
}

/*--------------------------------------------------------------------------*/

if (!Array.prototype.push) {
  Array.prototype.push = function() {
		var startLength = this.length;
		for (var i = 0; i < arguments.length; i++)
      this[startLength + i] = arguments[i];
	  return this.length;
  }
}

if (!Function.prototype.apply) {
  // Based on code from http://www.youngpup.net/
  Function.prototype.apply = function(object, parameters) {
    var parameterStrings = new Array();
    if (!object)     object = window;
    if (!parameters) parameters = new Array();
    
    for (var i = 0; i < parameters.length; i++)
      parameterStrings[i] = 'x[' + i + ']';
    
    object.__apply__ = this;
    var result = eval('obj.__apply__(' + 
      parameterStrings[i].join(', ') + ')');
    object.__apply__ = null;
    
    return result;
  }
}

/*--------------------------------------------------------------------------*/

var Ajax = {
  getTransport: function() {
    return Try.these(
      function() {return new ActiveXObject('Msxml2.XMLHTTP')},
      function() {return new ActiveXObject('Microsoft.XMLHTTP')},
      function() {return new XMLHttpRequest()}
    ) || false;
  },
  
  emptyFunction: function() {}
}

Ajax.Base = function() {};
Ajax.Base.prototype = {
  setOptions: function(options) {
    this.options = {
      method:       'post',
      asynchronous: true,
      parameters:   ''
    }.extend(options || {});
  }
}

Ajax.Request = Class.create();
Ajax.Request.Events = 
  ['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete'];

Ajax.Request.prototype = (new Ajax.Base()).extend({
  initialize: function(url, options) {
    this.transport = Ajax.getTransport();
    this.setOptions(options);
  
    try {
      if (this.options.method == 'get')
        url += '?' + this.options.parameters + '&_=';
    
      this.transport.open(this.options.method, url, true);
      
      if (this.options.asynchronous) {
        this.transport.onreadystatechange = this.onStateChange.bind(this);
        setTimeout((function() {this.respondToReadyState(1)}).bind(this), 10);
      }
              
      this.transport.setRequestHeader('X-Ajaxed', 'XMLHttpRequest');
      /* this.transport.setRequestHeader('X-Requested-With', 'XMLHttpRequest');  */
      /* this.transport.setRequestHeader('X-Prototype-Version', Prototype.Version); */

      if (this.options.method == 'post') {
        this.transport.setRequestHeader('Connection', 'close');
        this.transport.setRequestHeader('Content-type',
          'application/x-www-form-urlencoded');
      }
      
      this.transport.send(this.options.method == 'post' ? 
        this.options.parameters + '&_=' : null);
                      
    } catch (e) {
    }    
  },
      
  onStateChange: function() {
    var readyState = this.transport.readyState;
    if (readyState != 1)
      this.respondToReadyState(this.transport.readyState);
  },
  
  respondToReadyState: function(readyState) {
    var event = Ajax.Request.Events[readyState];
    (this.options['on' + event] || Ajax.emptyFunction)(this.transport);
  }
});

Ajax.Updater = Class.create();
Ajax.Updater.prototype = (new Ajax.Base()).extend({
  initialize: function(container, url, options) {
    this.container = $(container);
    this.setOptions(options);
  
    if (this.options.asynchronous) {
      this.onComplete = this.options.onComplete;
      this.options.onComplete = this.updateContent.bind(this);
    }
    
    this.request = new Ajax.Request(url, this.options);
    
    if (!this.options.asynchronous)
      this.updateContent();
  },
  
  updateContent: function() {
    if (this.options.insertion) {
      new this.options.insertion(this.container,
        this.request.transport.responseText);
    } else {
      this.container.innerHTML = this.request.transport.responseText;
    }

    if (this.onComplete) {
      setTimeout((function() {this.onComplete(this.request)}).bind(this), 10);
    }
  }
});

/*--------------------------------------------------------------------------*/

var Field = {
  clear: function() {
    for (var i = 0; i < arguments.length; i++)
      $(arguments[i]).value = '';
  },

  focus: function(element) {
    $(element).focus();
  },
  
  present: function() {
    for (var i = 0; i < arguments.length; i++)
      if ($(arguments[i]).value == '') return false;
    return true;
  },
  
  select: function(element) {
    $(element).select();
  },
   
  activate: function(element) {
    $(element).focus();
    $(element).select();
  }
}

/*--------------------------------------------------------------------------*/

var Form = {
  serialize: function(form) {
    var elements = Form.getElements($(form));
    var queryComponents = new Array();
    
    for (var i = 0; i < elements.length; i++) {
      var queryComponent = Form.Element.serialize(elements[i]);
      if (queryComponent)
        queryComponents.push(queryComponent);
    }
    
    return queryComponents.join('&');
  },
  
  getElements: function(form) {
    form = $(form);
    var elements = new Array();

    for (tagName in Form.Element.Serializers) {
      var tagElements = form.getElementsByTagName(tagName);
      for (var j = 0; j < tagElements.length; j++)
        elements.push(tagElements[j]);
    }
    return elements;
  },
  
  disable: function(form) {
    var elements = Form.getElements(form);
    for (var i = 0; i < elements.length; i++) {
      var element = elements[i];
      element.blur();
      element.disable = 'true';
    }
  },

  focusFirstElement: function(form) {
    form = $(form);
    var elements = Form.getElements(form);
    for (var i = 0; i < elements.length; i++) {
      var element = elements[i];
      if (element.type != 'hidden' && !element.disabled) {
        Field.activate(element);
        break;
      }
    }
  },

  reset: function(form) {
    $(form).reset();
  }
}

Form.Element = {
  serialize: function(element) {
    element = $(element);
    var method = element.tagName.toLowerCase();
    var parameter = Form.Element.Serializers[method](element);
    
    if (parameter)
      return encodeURIComponent(parameter[0]) + '=' + 
        encodeURIComponent(parameter[1]);                   
  },
  
  getValue: function(element) {
    element = $(element);
    var method = element.tagName.toLowerCase();
    var parameter = Form.Element.Serializers[method](element);
    
    if (parameter) 
      return parameter[1];
  }
}

Form.Element.Serializers = {
  input: function(element) {
    switch (element.type.toLowerCase()) {
      case 'hidden':
      case 'password':
      case 'text':
        return Form.Element.Serializers.textarea(element);
      case 'checkbox':  
      case 'radio':
        return Form.Element.Serializers.inputSelector(element);
    }
    return false;
  },

  inputSelector: function(element) {
    if (element.checked)
      return [element.name, element.value];
  },

  textarea: function(element) {
    return [element.name, element.value];
  },

  select: function(element) {
    var index = element.selectedIndex;
    var value = element.options[index].value || element.options[index].text;
    return [element.name, (index >= 0) ? value : ''];
  }
}

/*--------------------------------------------------------------------------*/

var $F = Form.Element.getValue;

/*--------------------------------------------------------------------------*/

Abstract.TimedObserver = function() {}
Abstract.TimedObserver.prototype = {
  initialize: function(element, frequency, callback) {
    this.frequency = frequency;
    this.element   = $(element);
    this.callback  = callback;
    
    this.lastValue = this.getValue();
    this.registerCallback();
  },
  
  registerCallback: function() {
    setTimeout(this.onTimerEvent.bind(this), this.frequency * 1000);
  },
  
  onTimerEvent: function() {
    var value = this.getValue();
    /* Added for real time search */
    if (observerOnclick != null && observerOnclick != '') {
      observerOnclick = '';
      this.lastValue = value;
    }
    /* End */
    if (this.lastValue != value && value.length > 0) {
      this.callback(this.element, value);
      this.lastValue = value;
    }
    
    this.registerCallback();
  }
}

/* Added to observe hidden iframe and detect when it has finished loading */
Abstract.TimedIframeObserver = function() {}
Abstract.TimedIframeObserver.prototype = {
  initialize: function(element, frequency, callback) {
    this.frequency = frequency;
    this.element   = element;
    this.callback  = callback;
    this.lasturl = '';
    
    this.registerCallback();
  },
  
  registerCallback: function() {
    setTimeout(this.onTimerEvent.bind(this), this.frequency * 1000);
  },
  
  onTimerEvent: function() {
    var value = '';
    try {
      value = frames[this.element].document.body.innerHTML;
      if (value.indexOf('.') >= 0 && this.lasturl != frames[this.element].location.href) {
        this.lasturl = frames[this.element].location.href;
        this.callback(value);
      }
    } catch(e) {}
      finally {
        this.registerCallback();
      }
    
  }
}

Form.Element.IframeObserver = Class.create();
Form.Element.IframeObserver.prototype = (new Abstract.TimedIframeObserver()).extend({
  getValue: function() {
    try {
      value = this.frames[element].document.body.innerHTML;
      return value;
    } catch(e) {
      return '';
    }
  }
});

Form.Element.Observer = Class.create();
Form.Element.Observer.prototype = (new Abstract.TimedObserver()).extend({
  getValue: function() {
    return Form.Element.getValue(this.element);
  }
});

Form.Observer = Class.create();
Form.Observer.prototype = (new Abstract.TimedObserver()).extend({
  getValue: function() {
    return Form.serialize(this.element);
  }
});


/*--------------------------------------------------------------------------*/

document.getElementsByClassName = function(className) {
  var children = document.getElementsByTagName('*') || document.all;
  var elements = new Array();
  
  for (var i = 0; i < children.length; i++) {
    var child = children[i];
    var classNames = child.className.split(' ');
    for (var j = 0; j < classNames.length; j++) {
      if (classNames[j] == className) {
        elements.push(child);
        break;
      }
    }
  }
  
  return elements;
}

/*--------------------------------------------------------------------------*/

var Element = {
  toggle: function() {
    for (var i = 0; i < arguments.length; i++) {
      var element = $(arguments[i]);
      element.style.display = 
        (element.style.display == 'none' ? '' : 'none');
    }
  },

  hide: function() {
    for (var i = 0; i < arguments.length; i++) {
      var element = $(arguments[i]);
      element.style.display = 'none';
    }
  },

  show: function() {
    for (var i = 0; i < arguments.length; i++) {
      var element = $(arguments[i]);
      element.style.display = '';
    }
  },

  remove: function(element) {
    element = $(element);
    element.parentNode.removeChild(element);
  },
   
  getHeight: function(element) {
    element = $(element);
    return element.offsetHeight; 
  }
}

var Toggle = new Object();
Toggle.display = Element.toggle;

/*--------------------------------------------------------------------------*/

Abstract.Insertion = function(adjacency) {
  this.adjacency = adjacency;
}

Abstract.Insertion.prototype = {
  initialize: function(element, content) {
    this.element = $(element);
    this.content = content;
    
    if (this.adjacency && this.element.insertAdjacentHTML) {
      this.element.insertAdjacentHTML(this.adjacency, this.content);
    } else {
      this.range = this.element.ownerDocument.createRange();
      if (this.initializeRange) this.initializeRange();
      this.fragment = this.range.createContextualFragment(this.content);
      this.insertContent();
    }
  }
}

var Insertion = new Object();

Insertion.Before = Class.create();
Insertion.Before.prototype = (new Abstract.Insertion('beforeBegin')).extend({
  initializeRange: function() {
    this.range.setStartBefore(this.element);
  },
  
  insertContent: function() {
    this.element.parentNode.insertBefore(this.fragment, this.element);
  }
});

Insertion.Top = Class.create();
Insertion.Top.prototype = (new Abstract.Insertion('afterBegin')).extend({
  initializeRange: function() {
    this.range.selectNodeContents(this.element);
    this.range.collapse(true);
  },
  
  insertContent: function() {  
    this.element.insertBefore(this.fragment, this.element.firstChild);
  }
});

Insertion.Bottom = Class.create();
Insertion.Bottom.prototype = (new Abstract.Insertion('beforeEnd')).extend({
  initializeRange: function() {
    this.range.selectNodeContents(this.element);
    this.range.collapse(this.element);
  },
  
  insertContent: function() {
    this.element.appendChild(this.fragment);
  }
});

Insertion.After = Class.create();
Insertion.After.prototype = (new Abstract.Insertion('afterEnd')).extend({
  initializeRange: function() {
    this.range.setStartAfter(this.element);
  },
  
  insertContent: function() {
    this.element.parentNode.insertBefore(this.fragment, 
      this.element.nextSibling);
  }
});

/*--------------------------------------------------------------------------*/

var Effect = new Object();

Effect.Highlight = Class.create();
Effect.Highlight.prototype = {
  initialize: function(element) {
    this.element = $(element);
    this.start  = 153;
    this.finish = 255;
    this.current = this.start;
    this.fade();
  },
  
  fade: function() {
    if (this.isFinished()) return;
    if (this.timer) clearTimeout(this.timer);
    this.highlight(this.element, this.current);
    this.current += 17;
    this.timer = setTimeout(this.fade.bind(this), 250);
  },
  
  isFinished: function() {
    return this.current > this.finish;
  },
  
  highlight: function(element, current) {
    element.style.backgroundColor = "#ffff" + current.toColorPart();
  }
}


Effect.Fade = Class.create();
Effect.Fade.prototype = {
  initialize: function(element) {
    this.element = $(element);
    this.start  = 100;
    this.finish = 0;
    this.current = this.start;
    this.fade();
  },
  
  fade: function() {
    if (this.isFinished()) { this.element.style.display = 'none'; return; }
    if (this.timer) clearTimeout(this.timer);
    this.setOpacity(this.element, this.current);
    this.current -= 10;
    this.timer = setTimeout(this.fade.bind(this), 50);
  },
  
  isFinished: function() {
    return this.current <= this.finish;
  },
  
  setOpacity: function(element, opacity) {
    opacity = (opacity == 100) ? 99.999 : opacity;
    element.style.filter = "alpha(opacity:"+opacity+")";
    element.style.opacity = opacity/100 /*//*/;
  }
}

Effect.Scale = Class.create();
Effect.Scale.prototype = {
  initialize: function(element, percent) {
    this.element = $(element);
    this.startScale    = 1.0;
    this.startHeight   = this.element.offsetHeight;
    this.startWidth    = this.element.offsetWidth;
    this.currentHeight = this.startHeight;
    this.currentWidth  = this.startWidth;
    this.finishScale   = (percent/100) /*//*/;
    if (this.element.style.fontSize=="") this.sizeEm = 1.0;
    if (this.element.style.fontSize.indexOf("em")>0)
       this.sizeEm      = parseFloat(this.element.style.fontSize);
    if(this.element.effect_scale) {
      clearTimeout(this.element.effect_scale.timer);
      this.startScale  = this.element.effect_scale.currentScale;
      this.startHeight = this.element.effect_scale.startHeight;
      this.startWidth  = this.element.effect_scale.startWidth;
      if(this.element.effect_scale.sizeEm) 
        this.sizeEm    = this.element.effect_scale.sizeEm;      
    }
    this.element.effect_scale = this;
    this.currentScale  = this.startScale;
    this.factor        = this.finishScale - this.startScale;
    this.options       = arguments[2] || {}; 
    this.scale();
  },
  
  scale: function() {
    if (this.isFinished()) { 
      this.setDimensions(this.element, this.startWidth*this.finishScale, this.startHeight*this.finishScale);
      if(this.sizeEm) this.element.style.fontSize = this.sizeEm*this.finishScale + "em";
      if(this.options.complete) this.options.complete(this);
      return; 
    }
    if (this.timer) clearTimeout(this.timer);
    if (this.options.step) this.options.step(this);
    this.setDimensions(this.element, this.currentWidth, this.currentHeight);
    if(this.sizeEm) this.element.style.fontSize = this.sizeEm*this.currentScale + "em";
    this.currentScale += (this.factor/10) /*//*/;
    this.currentWidth = this.startWidth * this.currentScale;
    this.currentHeight = this.startHeight * this.currentScale;
    this.timer = setTimeout(this.scale.bind(this), 50);
  },
  
  isFinished: function() {
    return (this.factor < 0) ? 
      this.currentScale <= this.finishScale : this.currentScale >= this.finishScale;
  },
  
  setDimensions: function(element, width, height) {
    element.style.width = width + 'px';
    element.style.height = height + 'px';
  }
}

Effect.Squish = Class.create();
Effect.Squish.prototype = {
  initialize: function(element) {
    this.element = $(element);
    new Effect.Scale(this.element, 1, { complete: this.hide.bind(this) } );
  },
  hide: function() {
    this.element.style.display = 'none';
  } 
}

Effect.Puff = Class.create();
Effect.Puff.prototype = {
  initialize: function(element) {
    this.element = $(element);
    this.opacity = 100;
    this.startTop  = this.element.top || this.element.offsetTop;
    this.startLeft = this.element.left || this.element.offsetLeft;
    new Effect.Scale(this.element, 200, { step: this.fade.bind(this), complete: this.hide.bind(this) } );
  },
  fade: function(effect) {
    topd    = (((effect.currentScale)*effect.startHeight) - effect.startHeight)/2;
    leftd   = (((effect.currentScale)*effect.startWidth) - effect.startWidth)/2;
    this.element.style.position='absolute';
    this.element.style.top = this.startTop-topd + "px";
    this.element.style.left = this.startLeft-leftd + "px";
    this.opacity -= 10;
    this.setOpacity(this.element, this.opacity); 
    if(navigator.appVersion.indexOf('AppleWebKit')>0) this.element.innerHTML += ''; //force redraw on safari
  },
  hide: function() {
    this.element.style.display = 'none';
  },
  setOpacity: function(element, opacity) {
    opacity = (opacity == 100) ? 99.999 : opacity;
    element.style.filter = "alpha(opacity:"+opacity+")";
    element.style.opacity = opacity/100 /*//*/;
  }
}

Effect.Appear = Class.create();
Effect.Appear.prototype = {
  initialize: function(element) {
    this.element = $(element);
    this.start  = 0;
    this.finish = 100;
    this.current = this.start;
    this.fade();
  },
  
  fade: function() {
    if (this.isFinished()) return;
    if (this.timer) clearTimeout(this.timer);
    this.setOpacity(this.element, this.current);
    this.current += 10;
    this.timer = setTimeout(this.fade.bind(this), 50);
  },
  
  isFinished: function() {
    return this.current > this.finish;
  },
  
  setOpacity: function(element, opacity) {
    opacity = (opacity == 100) ? 99.999 : opacity;
    element.style.filter = "alpha(opacity:"+opacity+")";
    element.style.opacity = opacity/100 /*//*/;
    element.style.display = '';
  }
}

Effect.ContentZoom = Class.create();
Effect.ContentZoom.prototype = {
  initialize: function(element, percent) {
    this.element = $(element);
    if (this.element.style.fontSize=="") this.sizeEm = 1.0;
    if (this.element.style.fontSize.indexOf("em")>0)
       this.sizeEm = parseFloat(this.element.style.fontSize);
    if(this.element.effect_contentzoom) {
      this.sizeEm = this.element.effect_contentzoom.sizeEm;
    }
    this.element.effect_contentzoom = this;
    this.element.style.fontSize = this.sizeEm*(percent/100) + "em" /*//*/;
    if(navigator.appVersion.indexOf('AppleWebKit')>0) { this.element.scrollTop -= 1; };
  }
}

/*--------------------------------------------------------------------------*/

	// Copyright (c) 2005 Thomas Fuchs
	// Permission granted to use this code as you like

	Effect2 = {}

	Effect2.Transitions = {}
	Effect2.Transitions.linear = function(pos) {
		return pos;
	}
	Effect2.Transitions.sinoidal = function(pos) {
		return (-Math.cos(pos*Math.PI)/2) + 0.5;
	}
	Effect2.Transitions.reverse  = function(pos) {
		return 1-pos;
	}
	Effect2.Transitions.flicker = function(pos) {
		return ((-Math.cos(pos*Math.PI)/4) + 0.25) + Math.random(0.5);
	}
	Effect2.Transitions.wobble = function(pos) {
		return (-Math.cos(pos*Math.PI*(9*pos))/2) + 0.5;
	}

	Effect2.Base = function() {};
	Effect2.Base.prototype = {
	  setOptions: function(options) {
	    this.options = {
	      transition: Effect2.Transitions.sinoidal,
	      duration:   1.0,   // seconds
	      fps:        25.0,  // max. 100fps
	      sync:       false  // true for combining
	    }.extend(options || {});
	  },
	  start: function(options) {
	  	 this.setOptions(options || {});
	  	 this.currentFrame    = 0;
		 this.startOn  = new Date().getTime();
		 this.finishOn = this.startOn + (this.options.duration*1000);
		 if(this.options.beforeStart) this.options.beforeStart(this);
	    if(!this.options.sync) this.loop();	
	  },
	  loop: function() {
		 timePos = new Date().getTime();
		 if(timePos >= this.finishOn) {
			if(this.finish) this.finish(); 
			if(this.options.afterFinish) this.options.afterFinish(this);
			return;	
		 }
		 pos   = (timePos - this.startOn) / (this.finishOn - this.startOn);
		 frame = Math.round(pos * this.options.fps * this.options.duration);
		 if(this.options.transition) pos = this.options.transition(pos);
		 if(frame > this.currentFrame) {
			if(this.options.beforeUpdate) this.options.beforeUpdate(this);
			if(this.update) this.update(pos);
			if(this.options.afterUpdate) this.options.afterUpdate(this);
			this.currentFrame = frame;
		 }
		 this.timeout = setTimeout(this.loop.bind(this), 10);
	  },
	  cancel: function() {
		 if(this.timeout) clearTimeout(this.timeout);
	  }
	}


	Effect2.Fade = Class.create();
	Effect2.Fade.prototype = (new Effect2.Base()).extend({
	  initialize: function() {
	  	 this.element = $(arguments[0] || document.rootElement);
	    this.start(arguments[1]);
	  },
	  update: function(position) {
		 this.setOpacity(100-(position*100));
	  },
	  finish: function() {
		 this.setOpacity(0);
	    Element.hide(this.element);
	  },
	  setOpacity: function(opacity) {
	    opacity = (opacity == 100) ? 99.999 : opacity;
	    this.element.style.opacity = opacity/100;
	    this.element.style.filter = "alpha(opacity:"+opacity+")";
	  }
	});

	Effect2.Appear = Class.create();
	Effect2.Appear.prototype = (new Effect2.Base()).extend({
	  initialize: function() {
	  	 this.element = $(arguments[0] || document.rootElement);
	    Element.show(this.element);
	    this.start(arguments[1]);
	  },
	  update: function(position) {
		 this.setOpacity(position*100);
	  },
	  finish: function() {
		 this.setOpacity(100);
	  },
	  setOpacity: function(opacity) {
	    opacity = (opacity == 100) ? 99.999 : opacity;
	    this.element.style.opacity = opacity/100;
	    this.element.style.filter = "alpha(opacity:"+opacity+")";
	  }
	});

	Effect2.MoveBy = Class.create();
   Effect2.MoveBy.prototype = (new Effect2.Base()).extend({
     initialize: function(element, toTop, toLeft) {
     	 this.element      = $(element);
    	 this.originalTop  = 
         this.element.style.top ? parseFloat(this.element.style.top) : 0;
       this.originalLeft = 
         this.element.style.left ? parseFloat(this.element.style.left) : 0;
       this.toTop        = toTop;
     	 this.toLeft       = toLeft;
       if(this.element.style.position == "")
         this.element.style.position = "relative";
       this.start(arguments[3]);
     },
     update: function(position) {
	    topd  = this.toTop  * position + this.originalTop;
	    leftd = this.toLeft * position + this.originalLeft;
   	 this.setPosition(topd, leftd);
     },
     finish: function() {
   	 this.setPosition(this.toTop + this.originalTop, this.toLeft + this.originalLeft);
     },
     setPosition: function(topd, leftd) {
     	 this.element.style.top  = topd  + "px";
       this.element.style.left = leftd + "px";
     }
	});

	Effect2.Scale = Class.create();
	Effect2.Scale.prototype = (new Effect2.Base()).extend({
	  initialize: function(element, percent) {
	    this.element = $(element);
	    this.originalHeight = this.element.clientHeight;
	    this.originalWidth  = this.element.clientWidth;
	    this.originalTop    = this.element.offsetTop;
	    this.originalLeft   = this.element.offsetLeft;
	    if (this.element.style.fontSize=="") this.sizeEm = 1.0;
	    if (this.element.style.fontSize && this.element.style.fontSize.indexOf("em")>0)
	       this.sizeEm      = parseFloat(this.element.style.fontSize);
	    this.factor         = (percent/100) - 1.0;
	    options = {
		   scaleX: true,
		   scaleY: true,
		   scaleContent: true,
		   scaleFromCenter: false
		 }
	    options = options.extend(arguments[2] || {});
	    this.start(options);
	  },

	  update: function(position) {
	    currentScale = 1.0 + (this.factor * position);
	    if(this.options.scaleContent && this.sizeEm) 
	      this.element.style.fontSize = this.sizeEm*currentScale + "em";
	    this.setDimensions(
		   this.originalWidth * currentScale, 
		   this.originalHeight * currentScale);
	  },

	  finish: function() {
		 finishScale = 1.0 + this.factor;
	  	 this.setDimensions(this.originalWidth*finishScale, this.originalHeight*finishScale);
	  	 if(this.options.scaleContent && this.sizeEm) 
	      this.element.style.fontSize = this.sizeEm*finishScale + "em";
	  },

	  setDimensions: function(width, height) {
	    if(this.options.scaleX) this.element.style.width = width + 'px';
	    if(this.options.scaleY) this.element.style.height = height + 'px';
	    if(this.options.scaleFromCenter) {
	      topd  = (height - this.originalHeight)/2;
	      leftd = (width  - this.originalWidth)/2;
	      if(this.element.style.position=='absolute') {
	        if(this.options.scaleY) this.element.style.top = this.originalTop-topd + "px";
	        if(this.options.scaleX) this.element.style.left = this.originalLeft-leftd + "px";
	      } else {
	        if(this.options.scaleY) this.element.style.top = -topd + "px";
	        if(this.options.scaleX) this.element.style.left = -leftd + "px";
	      }
	    }
	  }
	});

	Effect2.Parallel = Class.create();
	Effect2.Parallel.prototype = (new Effect2.Base()).extend({
	  initialize: function(effects) {
	    this.effects = effects || [];
	  	 this.start(arguments[1]);
	  },
	  update: function(position) {
	  	 for (var i = 0; i < this.effects.length; i++)
	  		this.effects[i].update(position);	
	  },
	  finish: function(position) {
	  	 for (var i = 0; i < this.effects.length; i++)
	  	  	this.effects[i].finish(position);
	  }
	});

	Effect2.Puff = function(element) {
	  new Effect2.Parallel(
	   [ new Effect2.Scale(element, 200, { sync: true, scaleFromCenter: true }), 
	     new Effect2.Fade(element, { sync: true } ) ], 
	     { duration: 1.0, 
		    afterUpdate: function(effect) 
		     { effect.effects[0].element.style.position = 'absolute'; } 
	     }
     );
	}

	Effect2.Blind = function(element) {
	  $(element).style.overflow = 'hidden';
	  new Effect2.Scale(element, 1, 
		 { scaleContent: false, 
			scaleX: false, 
			afterFinish: function(effect) 
			  { Element.hide(effect.element) } 
		 } 
	  );
	}
	
	Effect2.SwitchOff = function(element) {
		new Effect2.Appear(element,
		  { duration: 0.4,
			 transition: Effect2.Transitions.flicker,
			 afterFinish: function(effect)
			  {  effect.element.style.overflow = 'hidden';
				  new Effect2.Scale(effect.element, 1, 
				   { duration: 0.3, scaleFromCenter: true,
					  scaleX: false, scaleContent: false,
					  afterUpdate: function(effect) { 
						 if(effect.element.style.position=="")
						   effect.element.style.position = 'relative'; },
					  afterFinish: function(effect) { Element.hide(effect.element); }
				   } )
			  }
		  } )
	}

/*--------------------------------------------------------------------------*/

/* Custom Functions */

  /* Get target iframe and update */
  function renderKeywords(target,id,value) {
    frames[target].location.href = "http://www.ajaxed.com/site/viewlist_url/"+id+'?search='+escape(value)+'&src='+escape(document.location.host);
  }
  
  function renderDiv(value) {
    start = 0;
    end = 0;
    index = 0;
    html = '';
    bgcolor = '';
    hlcolor = '';
    width = '';
    fontSize = '';
    tokens = getURLParam('tokens');
    prefs  = getURLParam('prefs');
    if (tokens == "" || prefs == "" ) {
      document.getElementById('target').innerHTML = "";
      return false;
    }
    /* Get prefs */
    start = 0;
    end = prefs.indexOf('+',0);
    bgcolor = prefs.substring(start,end);
    start = end;
    end = prefs.indexOf('+',start+1);
    hlcolor = prefs.substring(start+1,end);
    start = end;
    end = prefs.indexOf('+',start+1);
    width = prefs.substring(start+1,end);
    start = end;
    end = prefs.indexOf('+',start+1);
    fontSize =  prefs.substring(start+1,end);
    
    /* Build list */
    index = 0;
    start = 0;
    end = 0;
    token = '';
    html += '<div style="position:absolute; z-index:100;background-color:'+bgcolor+';border:1px solid black;width:'+width+'px;font-size:'+fontSize+';overflow: hidden;">'
    html += '<ul style="margin:0;padding:0;">';
    index = tokens.indexOf('+',0);
    while (index >= 0 ) {
      end = index;
      if (start == 0) {
        token = tokens.substring(start,end);
      }
      else {
        token = tokens.substring(start+1,end);
      }
      html += '<li onmouseout="this.style.backgroundColor=\''+bgcolor+'\';" onmouseover="this.style.backgroundColor=\''+hlcolor+'\';" onclick="killBox(\''+unescape(token)+'\');">'+unescape(token)+'</li>';
      start = index;
      index = tokens.indexOf('+',index+1);
    }
    html += '</ul></div>';
    document.getElementById('target').innerHTML = html;
  }

  /* This function retrieves results through an iframe */
  function getKeywords(id) {
    new Form.Element.Observer('search', 1.0, function(element, value) {renderKeywords('targetframe',id,value)});
    new Form.Element.IframeObserver('targetframe', 0.25, function(value) {renderDiv(value);});
  }
  
  /* This function retrieves results through an xmlhttprequest - only works on same origin basis */
  function getKeywordsLocal(id) {
    new Form.Element.Observer('search', 0.5, function(element, value) {new Ajax.Updater('target', '/site/viewlist/'+id, {parameters:'search=' + escape(value), asynchronous:true})});
  }

  function getKeywordsLocalWithPrefs(id,bgcolor,hlcolor,width,fontsize,numdisplay) {
    new Form.Element.Observer('search', 0.5, function(element, value) {new Ajax.Updater('target', '/site/viewlist_with_prefs/'+id, {parameters:'search='+escape(value)+'&prefs='+escape(bgcolor)+','+escape(hlcolor)+','+escape(width)+','+escape(fontsize)+','+escape(numdisplay), asynchronous:true})});
  }

  /* This function retrieves results through an xmlhttprequest - only works on same origin basis */
  function getKeywordsAt(id,target) {
    new Form.Element.Observer('search', 0.5, function(element, value) {new Ajax.Updater(target, '/site/viewlist/'+id, {parameters:'search=' + escape(value), asynchronous:true})});
  }
  
  function killBox(value) {
    document.getElementById('search').value = value; 
    document.getElementById('target').innerHTML = ''; 
    observerOnclick = 'click';
  }

	function getTopURLParam(strParamName){
    var strReturn = "";
    var strHref = top.document.location.href;
    if ( strHref.indexOf("?") > -1 ){
      var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
      var aQueryString = strQueryString.split("&");
      for ( var iParam = 0; iParam < aQueryString.length; iParam++ )
      {
        if (aQueryString[iParam].indexOf(strParamName + "=") > -1 )
        {
          var aParam = aQueryString[iParam].split("=");
          strReturn = aParam[1];
          break;
        }
      }
    }
    return strReturn;
  }

	function getURLParam(strParamName){
    var strReturn = "";
    var strHref = frames['targetframe'].location.href;
    if ( strHref.indexOf("?") > -1 ){
      var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
      var aQueryString = strQueryString.split("&");
      for ( var iParam = 0; iParam < aQueryString.length; iParam++ )
      {
        if (aQueryString[iParam].indexOf(strParamName + "=") > -1 )
        {
          var aParam = aQueryString[iParam].split("=");
          strReturn = aParam[1];
          break;
        }
      }
    }
    return strReturn;
  }

  function confirm_prompt(text) {
    if (confirm(text)) {      
    }
  }
  
  function ghost(eltName) {
    var show=document.getElementById(eltName).style.display;
  //  new Effect.Highlight(document.getElementById(eltName));
    if(show == 'none'){
      new Effect2.Appear(document.getElementById(eltName),{transition: Effect2.Transitions.linear }); 
    } else {
      new Effect2.Fade(document.getElementById(eltName),{transition: Effect2.Transitions.linear});
    }
  }
