function initLoading() {
	if(document.getElementById('load') != null){
		document.getElementById('load').style.visibility = 'visible';
	}
}

function loadingFinished() {
	if (document.getElementById) {  // DOM3 = IE5, NS6
		if(document.getElementById('load') != null){
			document.getElementById('load').style.visibility = 'hidden';
		}
	}
	else {
		if (document.layers) {  // Netscape 4
			document.hidepage.visibility = 'hidden';
		}
	}
}

/*
Script: extensions.js
  
Copyright:
  copyright (c) 2007 wollzelle GmbH, <http://www.wollzelle.com>

Group: extensions
  collects several helper functions to make work with the DOM easier
*/

Object.callAllMethods = function(object) {
  $each(object, function(method) {
    if ($type(method) == 'function') method();
  });
}

document.redraw = function() { //ugly, but it works, Safari2 only
  window.resizeBy(-1,0);
  window.resizeBy(1,0);
}

Array.prototype.unique = function() {
  var o = {};
  for (var i = 0 ; i < this.length; i++)
    o[this[i]] = true;
  var tmp = new Array();
  for (var i in o) tmp[tmp.length] = i;
    return tmp;
}

String.prototype.truncate = function(length, truncation) {
  length = length || 30;
  truncation = truncation === undefined ? '...' : truncation;
  return this.length > length ? this.slice(0, length - truncation.length) + truncation : String(this);
}


Number.extend({

	/*
	Property: numberFormat
		Format a number with grouped thousands.

	Arguments:
		decimals, optional - integer, number of decimal percision; default, 2
		dec_point, optional - string, decimal point notation; default, '.'
		thousands_sep, optional - string, grouped thousands notation; default, ','

	Returns:
		a formatted version of number.

	Example:
		>(36432.556).numberFormat()  // returns 36,432.56
		>(36432.556).numberFormat(2, '.', ',')  // returns 36,432.56
	*/

	numberFormat : function(decimals, dec_point, thousands_sep) {
		decimals = Math.abs(decimals) + 1 ? decimals : 2;
		dec_point = dec_point || '.';
		thousands_sep = thousands_sep || ',';

		var matches = /(-)?(\d+)(\.\d+)?/.exec((isNaN(this) ? 0 : this) + ''); // returns matches[1] as sign, matches[2] as numbers and matches[2] as decimals
		var remainder = matches[2].length > 3 ? matches[2].length % 3 : 0;
		return (matches[1] ? matches[1] : '') + (remainder ? matches[2].substr(0, remainder) + thousands_sep : '') + matches[2].substr(remainder).replace(/(\d{3})(?=\d)/g, "$1" + thousands_sep) + 
				(decimals ? dec_point + (+matches[3] || 0).toFixed(decimals).substr(2) : '');
	}


});

// TODO: Safari 2 rendering bug:
// extend Fx.Base Class with an onAfterIncrease method which calls document.redraw

Element.extend({
  deactivate: function() {
    if (this.hasDeactivator) {
      this.hasDeactivator.show();
    }
    else {
      var dims = this.getCoordinates();
      this.hasDeactivator = new Element('div').setStyles({
        'top': this.offsetTop,
        'left': this.offsetLeft,
        'width': dims.width,
        'height': dims.height,
        'background': '#fff',
        'z-index': 1000000,
        'position': 'absolute'
      }).setOpacity(0.7).injectInside(this);
    } 
  },
  activate: function() {
    if (!this.hasDeactivator)
      return;
    else
      this.hasDeactivator.hide();
  },
  hide: function() {
    this.setStyle('display', 'none');
  },
  show: function() {
    this.setStyle('display', '');
  },
  toggle: function() {
    this[this.isVisible() ? 'hide' : 'show']();
  },
  isVisible: function() {
    return this.getStyle('display') != 'none';
  },
  isVisibleChild: function(parent) {
    var chk=this;
    var child=this;
    while ((chk=chk.parentNode) && (chk!=parent) && (chk.parentNode)) {
      if (child.offsetTop>(chk.offsetTop+chk.offsetHeight))
        return false;  
      child=chk;
    } ;
    return (chk==parent);
  },
  getHeight: function() {
    return this.getStyle('height').toInt();
  },
  getWidth: function() {
    return this.getStyle('width').toInt();
  },
  shake: function(amount) {
    var start = this.getStyle('margin-left').toInt(), amount = (amount || 20),
        a = start-amount, b = start+amount, f = this.effect('margin-left', { duration:80 }); 
    f.start(start,b).chain(function(){ 
      f.start(b,a); 
    }).chain(function() { 
      f.start(a,b); 
    }).chain(function() { 
      f.start(b,a); 
    }).chain(function() { 
      f.start(a,b); 
    }).chain(function() { 
      f.start(b,start); 
    }); 
  },
  nod: function(amount) {
    var start = this.getStyle('margin-top').toInt(), amount = (amount || 20),
        a = start-amount, b = start+amount, f = this.effect('margin-top', { duration:250 }); 
    f.start(start,b).chain(function(){ 
      f.start(b,a); 
    }).chain(function() { 
      f.start(a,b); 
    }).chain(function() { 
      f.start(b,start); 
    }); 
  } 
  
});

Fx.Morph = Fx.Styles.extend({
	start: function(className) {
    var to = {};
 
		$each(document.styleSheets, function(style) {
			var rules = style.rules || style.cssRules;
			$each(rules, function(rule) {
				if (!rule.selectorText.test('\.' + className + '$')) return;
				Fx.CSS.Styles.each(function(style) {
					if (!rule.style || !rule.style[style]) return;
					var ruleStyle = rule.style[style];
					to[style] = (style.test(/color/i) && ruleStyle.test(/^rgb/)) ? ruleStyle.rgbToHex() : ruleStyle;
				});
			});
		});
		return this.parent(to);
	}
});
 
Fx.CSS.Styles = [
  "backgroundColor", "backgroundPosition", "color", "width", "height", "left", "top", "bottom", "right", 
  "fontSize", "letterSpacing", "lineHeight", "textIndent", "opacity"
];
 
Fx.CSS.Styles.extend(Element.Styles.padding);
Fx.CSS.Styles.extend(Element.Styles.margin);
 
Element.Styles.border.each(function(border) {
	['Width', 'Color'].each(function(property) {
		Fx.CSS.Styles.push(border + property);
	});
});

window.getInnerDimensions = function() {
  if (self.innerHeight) 
    return { height: self.innerHeight, width: self.innerWidth }; // != IE
  else if (document.documentElement && document.documentElement.clientHeight) // IE7/IE6 Strict
    return { height: document.documentElement.clientHeight, width: document.documentElement.clientWidth };
  else if (document.body) // IE
    return { height: document.body.clientHeight, width: document.body.clientWidth };
}
