var Base = function() {
	if (arguments.length) {
		if (this == window) { // cast an object to this class
			Base.prototype.extend.call(arguments[0], arguments.callee.prototype);
		} else {
			this.extend(arguments[0]);
		}
	}
};
Base.version = "1.0.2";
Base.prototype = {
	extend: function(source, value) {
		var extend = Base.prototype.extend;
		if (arguments.length == 2) {
			var ancestor = this[source];
			// overriding?
			if ((ancestor instanceof Function) && (value instanceof Function) &&
				ancestor.valueOf() != value.valueOf() && /\bbase\b/.test(value)) {
				var method = value;
			//	var _prototype = this.constructor.prototype;
			//	var fromPrototype = !Base._prototyping && _prototype[source] == ancestor;
				value = function() {
					var previous = this.base;
				//	this.base = fromPrototype ? _prototype[source] : ancestor;
					this.base = ancestor;
					var returnValue = method.apply(this, arguments);
					this.base = previous;
					return returnValue;
				};
				// point to the underlying method
				value.valueOf = function() {
					return method;
				};
				value.toString = function() {
					return String(method);
				};
			}
			return this[source] = value;
		} else if (source) {
			var _prototype = {toSource: null};
			// do the "toString" and other methods manually
			var _protected = ["toString", "valueOf"];
			// if we are prototyping then include the constructor
			if (Base._prototyping) _protected[2] = "constructor";
			for (var i = 0; (name = _protected[i]); i++) {
				if (source[name] != _prototype[name]) {
					extend.call(this, name, source[name]);
				}
			}
			// copy each of the source object's properties to this object
			for (var name in source) {
				if (!_prototype[name]) {
					extend.call(this, name, source[name]);
				}
			}
		}
		return this;
	},

	base: function() {
		// call this method from any other method to invoke that method's ancestor
	}
};

Base.extend = function(_instance, _static) {
	var extend = Base.prototype.extend;
	if (!_instance) _instance = {};
	// build the prototype
	Base._prototyping = true;
	var _prototype = new this;
	extend.call(_prototype, _instance);
	var constructor = _prototype.constructor;
	_prototype.constructor = this;
	delete Base._prototyping;
	// create the wrapper for the constructor function
	var klass = function() {
		if (!Base._prototyping) constructor.apply(this, arguments);
		this.constructor = klass;
	};
	klass.prototype = _prototype;
	// build the class interface
	klass.extend = this.extend;
	klass.implement = this.implement;
	klass.toString = function() {
		return String(constructor);
	};
	extend.call(klass, _static);
	// single instance
	var object = constructor ? klass : _prototype;
	// class initialisation
	if (object.init instanceof Function) object.init();
	return object;
};

Base.implement = function(_interface) {
	if (_interface instanceof Function) _interface = _interface.prototype;
	this.prototype.extend(_interface);
};

var Lib = {};
Lib.delegate =				function(that, thatMethod){
							
							var _params = [];
							for(var n = 2; n < arguments.length; n++) _params.push(arguments[n]);
							return function() {
							 
						         var paramsToUse = [];
						         for(var n = 0; n < arguments.length; n++) {
						         	paramsToUse.push(arguments[n]);
						         }
						         for(var n = 0; n < _params.length; n++) {
						         	paramsToUse.push(_params[n]);
						         }
						         
							 try {
							  if (paramsToUse.length > 0){
							    return thatMethod.apply(that, paramsToUse)
							  }else {
							    return thatMethod.call(that)
							  }
							 }catch(e){
							  e.func = thatMethod;
							  e.params = _params.join(",");
							 };
							}
};
Lib.setTimeoutDelegate =		function(that, thatMethod){	
							var _params = [];
							for(var n = 2; n < arguments.length; n++) _params.push(arguments[n]);
							return function() {
							 try {
							  if (_params.length > 0){
							    return thatMethod.apply(that, _params)
							  }else {
							    return thatMethod.call(that)
							  }
							 }catch(e){
							  e.func = thatMethod;
							  e.params = _params.join(",");
							  
							 };
							}							
};

Lib.Browser = {};
Lib.Browser.query = 			function (avar, url){

							if (url){
							  var query = url.split("?")[1].split("#")[0];
							}else {
							  var query = window.location.search.split("#")[0];
							  query = query.substring(1);
							}
							 
							var vars = query.split("&");
							for (var i=0;i<vars.length;i++) {
							   var pair = vars[i].split("=");
							   if (pair[0] == avar) {
							    return pair[1];
							   }
							   
							}
							return false;
};

Lib.Browser._get = 			null;
Lib.Browser.get	=			function () {
						
							if (Lib.Browser._get != null){
							 return Lib.Browser._get;
							}

							var ua, s, i;

							var isMSIE = /*@cc_on!@*/false;
							isNS    = false;
							version = null;

							ua = navigator.userAgent;

							s = "Netscape6/";
							if ((i = ua.indexOf(s)) >= 0) {
							 isNS = true;
							 version = parseFloat(ua.substr(i + s.length));
							}

							s = "Gecko";
							if ((i = ua.indexOf(s)) >= 0) {
							 isNS = true;
							 version = 6.1;
							}
							return Lib.Browser._get = {isIE:isMSIE, isNS:isNS, version:version};
};
Lib.Browser.dim =					function (){
								var bd = {};

								if (window.innerHeight && window.scrollMaxY) {	
									bd.xfull = document.body.scrollWidth;
									bd.yfull = window.innerHeight + window.scrollMaxY;
								} else if (document.body.scrollHeight > document.body.offsetHeight){

									bd.xfull = document.body.scrollWidth;
									bd.yfull = document.body.scrollHeight;
								} else {
									bd.xfull = document.body.offsetWidth;
									bd.yfull = document.body.offsetHeight;
								}
								
								if (self.innerHeight) {	// all except Explorer
									bd.xview = self.innerWidth;
									bd.yview = self.innerHeight;
								} else if (document.documentElement && document.documentElement.clientHeight) {
									bd.xview = document.documentElement.clientWidth;
									bd.yview = document.documentElement.clientHeight;
								} else if (document.body) { // other Explorers
									bd.xview = document.body.clientWidth;
									bd.yview = document.body.clientHeight;
								}	
								

								if(bd.yfull < bd.yview){
									bd.yfull = bd.yview;
								}

								
								if (self.pageYOffset) {
									bd.yscroll = self.pageYOffset;
								} else if (document.documentElement && document.documentElement.scrollTop){
									bd.yscroll = document.documentElement.scrollTop;
								} else if (document.body) {
									bd.yscroll = document.body.scrollTop;
								}
								return bd;
};

// requires Lib.Browser;
Lib.Dom = {};
Lib.Dom.getEventSrc = 			function (e){
						
							if (typeof e == 'undefined') {
							 if (window.event){
							  var e = window.event;
							 }else {
							  return false;
							 }
							}
							if (e.cancelBubble != null){
								return (typeof e.target != 'undefined'?source = e.target:source = e.srcElement);
							}
							return false;
							
};
Lib.Dom.getElementsByClassName = 	function (elm, tag, myclass, exact){

 							tags = tag.split("|");
 							
 							var allelms = [];
 							for (var i=0; i<tags.length; i++){
 							 var tmp = (tags[i] == "*" && elm.all)? elm.all : elm.getElementsByTagName(tags[i]);
							 for (var a=0; a<tmp.length; a++){
							  allelms.push(tmp[a])
							 }
							}

							var returnelms = new Array();
							myclass = myclass.replace(/-/g, "\-");
							var regexp = new RegExp("(^|\s)" + myclass + "(\s|$)");
							var oElement;
							var classes;
							
							for(var i=0; i<allelms.length; i++){
								oElement = allelms[i];
								if (exact){
								 
								 if(regexp.test(oElement.className)){
								 
								  returnelms.push(oElement);
								 }
								}else {
								 classes = oElement.className.split(" ");
								 
								 var flag = false;
								 
								 for (var a=0; a<classes.length; a++){
								  if(regexp.test(classes[a])){
								   flag = true;	
								  }
								 }
								 if (flag){
								  returnelms.push(oElement);
								 }
								}
								
							}
							
							return returnelms;
};
/* events */

Lib.Dom.addEvent	= 		function( obj, type, fn ) { 
								  if ( obj.attachEvent ) { 
								    obj['e'+type+fn] = fn; 
								    obj[type+fn] = function(){obj['e'+type+fn]( window.event );} 
								    obj.attachEvent( 'on'+type, obj[type+fn] ); 
								  } else 
								    obj.addEventListener( type, fn, false ); 
} 
Lib.Dom.removeEvent = 		function ( obj, type, fn ) { 
								  if ( obj.detachEvent ) { 
								    obj.detachEvent( 'on'+type, obj[type+fn] ); 
								    obj[type+fn] = null; 
								  } else 
								    obj.removeEventListener( type, fn, false ); 
} 
Lib.Dom.preventDefaultIE  = function(){
						      window.event.cancelBubble = true;
						      window.event.returnValue = false;
}
Lib.Dom.preventDefaultBehaviour = function(e){
							 var browser = Lib.Browser.get();
						     if (browser.isIE && (window.event!=null)){
						        Lib.Dom.preventDefaultIE();
						     }
						     else
						           e.preventDefault();
}
Lib.Dom._domLoadedFunctionList	=	[];
Lib.Dom._domLoaded =			false;
Lib.Dom.callWhenDOMLoaded = 		function (func) {

							if (Lib.Dom._domLoaded) {
								try {func();}catch(e){}
							} else {
								Lib.Dom._domLoadedFunctionList.push(func);
							}
};
Lib.Dom._domLoadedEvent	=		function() {
							Lib.Dom._domLoaded=true;
							
							if (arguments.callee.done) return;
							
							arguments.callee.done = true;
							
							for (var i=0;i<Lib.Dom._domLoadedFunctionList.length;i++) {
							  try {Lib.Dom._domLoadedFunctionList[i]();}catch(e){}
							}
};





// shortcut to call when dom loaded
callWhenDOMLoaded = function(a){return Lib.Dom.callWhenDOMLoaded(a);};
if (document.addEventListener) {
  document.addEventListener("DOMContentLoaded", Lib.Dom._domLoadedEvent, null);
}
window.onload = Lib.Dom._domLoadedEvent;
/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
	document.write("<script id=__ie_onload defer src=\"//:\"><\/script>");
	var script = document.getElementById("__ie_onload");
	script.onreadystatechange = function() {
		if (this.readyState == "complete") {
			Lib.Dom._domLoadedEvent(); // call the onload handler
		}
	};
/*@end @*/







Lib.Dom.Elm = {};	
Lib.Dom.Elm.find = 			function(elm){
							if (typeof elm == "object"){
							 if (source = Lib.Dom.getEventSrc(elm)){
							  return source;
							 }else {
							  return elm;
							 }
							}else {
							  return document.getElementById(elm);
							}
};

// shortcut to Lib.Dom.Elm.find()
$ = 					function (e){
							return Lib.Dom.Elm.find(e);
};

Lib.Dom.Elm.first = 			function (elm, type){
							var first = false;
							if (first = elm.getElementsByTagName(type)[0]){
							 return first;
							}else {
							 return first;
							}
							
}
Lib.Dom.Elm.last = 			function (elm, type){
							var elms = elm.getElementsByTagName(type);
							return elms[elms.length-1];
}
Lib.Dom.Elm.create = 		function(type, styles){
	
							var elm = document.createElement(type);
							
							if (styles){
							  Lib.Dom.Elm.Style.add(elm, styles);
							}
							return elm;
};
Lib.Dom.Elm.findPos = 			function(obj) {
						var curleft = curtop = 0;
						if (obj.offsetParent) {
							curleft = obj.offsetLeft
							curtop = obj.offsetTop
							while (obj = obj.offsetParent) {
								curleft += obj.offsetLeft
								curtop += obj.offsetTop
							}
						}
						return [curleft,curtop];
};
Lib.Dom.Elm.isTag = 			function (elm, tag){
						if (elm.nodeName.toUpperCase() == tag.toUpperCase()){
							return true;
						}
						return false;
};

Lib.Dom.Elm.Style = {};
Lib.Dom.Elm.Style.add = 		function(elm, styles){
							elm = $(elm);
							for (sty in styles){
							  elm.style[sty] = styles[sty];
							}
};

Lib.Dom.Elm.Style.changeStyle =		function (element, newStyleSuffix){
							if(null != element){
							  if (element.originalClass==null || element.originalClass.length==0){
							    if (element.className.length>0){
							      element.originalClass=element.className;
							    }else {
							      element.originalClass=" ";
							    }
							  }
							  if(element.originalClass.length>0 && element.originalClass != " "){
							    element.className = element.originalClass+" "+element.originalClass+newStyleSuffix;
							  }else {
							    element.className = newStyleSuffix;
							  }
							}
};
Lib.Dom.Elm.Style.revertToOriginalStyle = function (element){
							if(element != null && null != element.originalClass && element.originalClass.length>0){
								element.className = (element.originalClass!=" "?element.originalClass:"");
							}
};
Lib.Dom.Elm.Style.addClass = 		function (element, newStyleSuffix){

							if(null != element)
							{
							  element.originalClass = element.className;
							  if(element.className == null){
							    element.className = newStyleSuffix;
							  }else{
							    element.className += ' ' + newStyleSuffix;
							  }
							}
};
Lib.Dom.Elm.Style.removeClass = 	function (element, newStyleSuffix){
							if(element != null && element.className!=null){
							  if(element.className.indexOf(newStyleSuffix) != -1){
							    var n = element.className.indexOf(newStyleSuffix);
							    element.className = (element.className.substr(0, n) + element.className.substr(n + newStyleSuffix.length)).replace(/^\s+|\s+$/g, '');
							  }
							}
};

Lib.Dom.Elm.Opacity = {};
Lib.Dom.Elm.Opacity._tid = {};
Lib.Dom.Elm.Opacity.opacity = 		function(id, opacStart, opacEnd, millisec) {
							var speed = Math.round(millisec / 100);
							var timer = 0;
							if (!opacStart){
							  opacStart = $(id).thisOpacity;
							}
							if (Lib.Dom.Elm.Opacity._tid[id] != null){
							 for (var a = 0; a<Lib.Dom.Elm.Opacity._tid[id].length; a++){
							   clearTimeout(Lib.Dom.Elm.Opacity._tid[id][a]);
							 }
							}
							Lib.Dom.Elm.Opacity._tid[id] = [];;
							if(opacStart > opacEnd) {
								for(i = opacStart; i >= opacEnd; i--) {
									Lib.Dom.Elm.Opacity._tid[id].push(setTimeout("Lib.Dom.Elm.Opacity.changeOpac(" + i + ",'" + id + "')",(timer * speed)));
									timer++;
								}
							} else if(opacStart < opacEnd) {
								for(i = opacStart; i <= opacEnd; i++)
									{
									Lib.Dom.Elm.Opacity._tid[id].push(setTimeout("Lib.Dom.Elm.Opacity.changeOpac(" + i + ",'" + id + "')",(timer * speed)));
									timer++;
								}
							}
};
Lib.Dom.Elm.Opacity.changeOpac = 	function(opacity, id) {
							var object = $(id); 

							Lib.Dom.Elm.Style.add (object, {
								opacity : (opacity / 100),
								MozOpacity : (opacity / 100),
								KhtmlOpacity : (opacity / 100),
								filter : "alpha(opacity=" + opacity + ")"
							});
							object.thisOpacity = opacity;
};
Lib.Dom.LinkPanels = {};
Lib.Dom.LinkPanels.getParentDiv = 	function (linkDivElement) {
							while ( (linkDivElement != null) && 
									(linkDivElement.clickhref==null)
								) { 
								linkDivElement=linkDivElement.parentNode;
							}
							return linkDivElement;
};
Lib.Dom.LinkPanels.click = 		function (e, eventObj) {

							var linkDivElement = $(eventObj);
							while ( (linkDivElement != null) 
								&& (linkDivElement.clickhref==null)
								&& (linkDivElement.tagName.toLowerCase() !='a')  ){
								linkDivElement=linkDivElement.parentNode;
							}
							if ( (linkDivElement != null) ) {
								window.location.href=linkDivElement.clickhref;
							}
};
Lib.Dom.LinkPanels.rollover = 		function (e, eventObj) {
							Lib.Dom.Elm.Style.addClass(Lib.Dom.LinkPanels.getParentDiv($(eventObj)),"Hover");
	
};
Lib.Dom.LinkPanels.rollout = 		function (e, eventObj) {
							Lib.Dom.Elm.Style.revertToOriginalStyle(Lib.Dom.LinkPanels.getParentDiv($(eventObj)));
};	

Lib.Dom.LinkPanels.initialise = 	function (container, tags) {
                            if (container == null){
                              container = document.body;
                            }
                            if (tags == null){
                              tags = 'div';
                            }
							var divList=Lib.Dom.getElementsByClassName($(container), tags, 'linkpanel');
							for (var i=0;i<divList.length;i++) {
								var divElement=divList[i];
									var atags=divElement.getElementsByTagName("a");
									if (atags.length>0) {
										divElement.clickhref=atags[0].getAttribute('href');
										Lib.Dom.Elm.Style.add(divElement, { 'cursor' : 'pointer'});
										Lib.Dom.addEvent(divElement, "click", Lib.delegate(this, Lib.Dom.LinkPanels.click, divElement));
										Lib.Dom.addEvent(divElement, "mouseover", Lib.delegate(this, Lib.Dom.LinkPanels.rollover, divElement));
										Lib.Dom.addEvent(divElement, "mouseout", Lib.delegate(this, Lib.Dom.LinkPanels.rollout, divElement));
									}
								
							}
};
