/*  Prototype JavaScript framework, version 1.3.1
 *  (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/
 *
/*--------------------------------------------------------------------------*/

var Prototype = {
  Version: '1.3.1',
  emptyFunction: function() {}
}

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

var Abstract = new Object();

Object.extend = function(destination, source) {
  for (property in source) {
    destination[property] = source[property];
  }
  return destination;
}

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);
  }
}

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

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 (!Array.prototype.remove) {
  Array.prototype.remove = function(item) {
	for(var i=0; i < this.length; i++)
      if(this[i] == item){
		this.splice(i,1);
		return true;
	  }
	return false;
  }
}

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] = 'parameters[' + i + ']';
    
    object.__apply__ = this;
    var result = eval('object.__apply__(' + 
      parameterStrings.join(', ') + ')');
    object.__apply__ = null;
    
    return result;
  }
}


if (!window.Event) {
  var Event = new Object();
}

Object.extend(Event, {

  element: function(event) {
    return event.target || event.srcElement;
  },

  isLeftClick: function(event) {
    return (((event.which) && (event.which == 1)) ||
            ((event.button) && (event.button == 1)));
  },

  // find the first node with the given tagName, starting from the
  // node the event was triggered on; traverses the DOM upwards
  findElement: function(event, tagName) {
    var element = Event.element(event);
    while (element.parentNode && (!element.tagName ||
        (element.tagName.toUpperCase() != tagName.toUpperCase())))
      element = element.parentNode;
    return element;
  },

  observers: false,
  
  _observeAndCache: function(element, name, observer, useCapture) {
    if (!this.observers) this.observers = [];
    if (element.addEventListener) {
      this.observers.push([element, name, observer, useCapture]);
      element.addEventListener(name, observer, useCapture);
    } else if (element.attachEvent) {
      this.observers.push([element, name, observer, useCapture]);
      element.attachEvent('on' + name, observer);
    }
  },
  
  unloadCache: function() {
    if (!Event.observers) return;
    for (var i = 0; i < Event.observers.length; i++) {
      Event.stopObserving.apply(this, Event.observers[i]);
      Event.observers[i][0] = null;
    }
    Event.observers = false;
  },

  observe: function(element, name, observer, useCapture) {
    var element = $(element);
    useCapture = useCapture || false;
    
    if (name == 'keypress' &&
        ((navigator.appVersion.indexOf('AppleWebKit') > 0) 
        || element.attachEvent))
      name = 'keydown';
    
    this._observeAndCache(element, name, observer, useCapture);
  },

  stopObserving: function(element, name, observer, useCapture) {
    var element = $(element);
    useCapture = useCapture || false;
    
    if (name == 'keypress' &&
        ((navigator.appVersion.indexOf('AppleWebKit') > 0) 
        || element.detachEvent))
      name = 'keydown';
    
    if (element.removeEventListener) {
      element.removeEventListener(name, observer, useCapture);
    } else if (element.detachEvent) {
      element.detachEvent('on' + name, observer);
    }
  }
});

/* prevent memory leaks in IE */
Event.observe(window, 'unload', Event.unloadCache, false);

// Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
//
// Parts (c) 2005 Justin Palmer (http://encytemedia.com/)
// Parts (c) 2005 Mark Pilgrim (http://diveintomark.org/)
// 
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


Effect = {}

/* ------------- transitions ------------- */

Effect.Transitions = {}

Effect.Transitions.sinoidal = function(pos) {
  return (-Math.cos(pos*Math.PI)/2) + 0.5;
}

/* ------------- core effects ------------- */

Effect.Base = function() {};
Effect.Base.prototype = {
  setOptions: function(options) {
    this.options = Object.extend({
      transition: Effect.Transitions.sinoidal,
      duration:   0.4,   // seconds
      fps:        25.0,  // max. 100fps
      sync:       false, // true for combining
      from:       0.0,
      to:         1.0
    }, 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() {
    var timePos = new Date().getTime();
    if(timePos >= this.finishOn) {
      this.render(1.0);
      if(this.finish) this.finish(); 
      if(this.options.afterFinish) this.options.afterFinish(this);
	  this.finished = true;
      return;  
    }
    var pos   = (timePos - this.startOn) / (this.finishOn - this.startOn);
    var frame = Math.round(pos * this.options.fps * this.options.duration);
    if(frame > this.currentFrame) {
      this.render(pos);
      this.currentFrame = frame;
    }
    this.timeout = setTimeout(this.loop.bind(this), 10);
  },
  render: function(pos) {
    if(this.options.transition) pos = this.options.transition(pos);
    pos *= (this.options.to-this.options.from);
    pos += this.options.from; 
    if(this.options.beforeUpdate) this.options.beforeUpdate(this);
    if(this.update) this.update(pos);
    if(this.options.afterUpdate) this.options.afterUpdate(this);  
  },
  cancel: function() {
    if(this.timeout) clearTimeout(this.timeout);
	this.finished = true;
  }
}


// Copyright (c) 2006 Rowan Nairn (eurekaman.com)

Effect.Interpolate = Class.create();
Object.extend(Object.extend(Effect.Interpolate.prototype, Effect.Base.prototype), {
	initialize: function(from, to, callback) {
		this.from = from;
		this.delta = [];
		this.degenerate = true;
		for (var i=0; i<from.length; ++i) {
			this.delta[i] = (to[i] || 0) - from[i];
			this.degenerate &= this.delta[i] == 0;
		}
			
		this.callback = callback;
		if (this.degenerate) {
			this.setOptions(arguments[3] || {});
			if(this.options.beforeStart) this.options.beforeStart(this);
			if(this.finish) this.finish();
			if(this.options.afterFinish) this.options.afterFinish(this);
		} else {
			this.start(arguments[3]);
		}
	},
	update: function(position) {
		var values = [];
		for (var i=0; i<this.from.length; ++i)
			values[i] = this.from[i] + this.delta[i]*position;
		this.callback.apply(window,values);
	}
});

var postSize = 200;
var magnified = null;

function magnify(id, magnifier){
	demagnify();
		
	var post = document.getElementById(id);
	var container = post.parentNode;
	
	magnified = {
		post: post,
		container: container,
		magnifier: magnifier
	};
	
	if (!container.originalOffsetLeft) {
		Object.extend(container,{
			originalOffsetLeft: container.offsetLeft,
			originalOffsetTop: container.offsetTop,
			originalOffsetWidth: container.offsetWidth,
			originalOffsetHeight: container.offsetHeight
		});
	}
	
	Object.extend(document.getElementById('postshadow').style,{
		left: (container.offsetLeft + 10) + 'px',
		top: (container.offsetTop + 10) + 'px',
		width: (container.offsetWidth ) + 'px',
		height: (container.offsetHeight ) + 'px',
		visibility: 'visible'
	});
	
	if (container.magnifyEffect)
		container.magnifyEffect.cancel();
	container.magnifyEffect = new Effect.Interpolate(
		[container.offsetLeft,
			container.offsetTop,
			container.offsetWidth,
			container.offsetHeight],
		[(document.getElementById('content').offsetWidth - post.offsetWidth)/2,
			container.originalOffsetTop - 13,
			post.offsetWidth,
			post.offsetHeight],
			
		function (left,top,width,height) {
			
			Object.extend(container.style,{
				left: left + 'px',
				top: top + 'px',
				width: width + 'px',
				height: height + 'px',
				zIndex: 1000
			});
				
			if (magnified && magnified.container == container) {
				Object.extend(document.getElementById('postshadow').style,{
					left: (left + 10) + 'px',
					top: (top + 10) + 'px',
					width: (width ) + 'px',
					height: (height ) + 'px'
				});
			}
		}
	);

	magnifier.style.display = 'none';
}

function demagnify() {
	if (magnified) {
		var container = magnified.container;
		
		container.style.zIndex = '20';
		document.getElementById('postshadow').style.visibility = 'hidden';
		
		if(container.magnifyEffect)
			container.magnifyEffect.cancel();
		container.magnifyEffect = new Effect.Interpolate(
			[container.offsetLeft,
				container.offsetTop,
				container.offsetWidth,
				container.offsetHeight],
			[container.originalOffsetLeft,
				container.originalOffsetTop,
				container.originalOffsetWidth,
				container.originalOffsetHeight],
				
			function (left,top,width,height) {
				Object.extend(container.style,{
					left: left + 'px',
					top: top + 'px',
					width: width + 'px',
					height: height + 'px'
				});
			},
			{
				afterFinish: function() {
					Object.extend(container.style,{
						left: '',
						top: '',
						width: '',
						height: '',
						zIndex: ''
					});
				}
			}
		);

		magnified.magnifier.style.display = '';
	
		magnified = null;
	}
}

function stopEvent(event) {
	if (event.stopPropagation)
		event.stopPropagation();
	else
		event.cancelBubble = true;
}

document.onclick = demagnify;
