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.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, eventName, dlg){	
							if ( obj.detachEvent ) { 
							  obj.detachEvent( 'on'+type, obj[type+fn] ); 
							  obj[type+fn] = null; 
							} else 
							  obj.removeEventListener( type, fn, false ); 
};
Lib.Dom.addEventQuick = 		function (item, type, func){
							Lib.Dom.addEvent(item, type, Lib.delegate(this, func, item));
}
Lib.Dom._domLoadedFunctionList	=	[];
Lib.Dom._domLoaded =			false;
Lib.Dom.callWhenDOMLoaded = 		function (func) {

							if (Lib.Dom._domLoaded) {
								try {func();}catch(e){Lib.Error.throwError(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){Lib.Error.throwError(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.Images = {};
Lib.Dom.Images.fixPNGs =		function (){
							if(Lib.Browser.get().isIE){
							  var allpngs = Lib.Dom.getElementsByClassName(document, "img", "likeimg");

							  for(var a=0; a<allpngs.length; a++)
							  {

							    var img = allpngs[a]

							    var imgName = img.src.toUpperCase()

							    if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
							    {
							       var imgID = (img.id) ? "id='" + img.id + "' " : ""
							       var imgClass = (img.className) ? "class='" + img.className + "' " : ""
							       var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
							       var imgStyle = "display:inline-block;" + img.style.cssText
							       if (img.align == "left") imgStyle = "float:left;" + imgStyle
							       if (img.align == "right") imgStyle = "float:right;" + imgStyle

							       var strNewHTML = "<span " + imgID + imgClass + imgTitle
							       + " style=\"" + "width:7px; height:14px;" + imgStyle + ";"
							       + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
							       + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
							       img.outerHTML = strNewHTML

							    }
							  }
							}
 
}

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

// requires Lib.Dom.Elm;
Lib.Dom.Images.SimpleRoll = {

	setup : 			function (){
	
							var allRollovers = Lib.Dom.getElementsByClassName(document, "img", "rollover");
							var preLoadedImgs = [];
							for (i=0; i<allRollovers.length; i++){
							 if (allRollovers[i].nodeName.toLowerCase() == "img"){
							  var fullImgPath = allRollovers[i].src;
							  var extPos = fullImgPath.lastIndexOf(".");
							  var imgPath = fullImgPath.substring(0, extPos);
							  var imgExt = fullImgPath.substring(extPos, fullImgPath.length);

							  var overImg = imgPath + "_over" + imgExt;


							  var tmp = new Image();
							  tmp.src = overImg;
							  allRollovers[i].overimg = overImg;
							  allRollovers[i].outimg = fullImgPath;
							  preLoadedImgs.push(tmp);
							  parentTag = allRollovers[i].parentNode;
							  Lib.Dom.addEvent(parentTag, 'mouseover', Lib.Dom.Images.SimpleRoll.rollover);
							  Lib.Dom.addEvent(parentTag, 'mouseout', Lib.Dom.Images.SimpleRoll.rollout);

							 }
							}
	
	},
	rollover : 			function (e){
							var elm = $(e);
							if (elm.nodeName.toLowerCase() != "a"){
							  elm = elm.parentNode;
							}
							var imag = elm.getElementsByTagName("img")[0];
							imag.src = imag.overimg;
	},
	rollout : 			function (e){
							var elm = $(e);
							if (elm.nodeName.toLowerCase() != "a"){
							  elm = elm.parentNode;
							}
							var imag = elm.getElementsByTagName("img")[0];
							imag.src = imag.outimg;
	}

};

Lib.Ajax = {}; 

Lib.Functions = {};

Lib.Functions.FunctionList = Base.extend({
	constructor : 		function (items){
							this.clearItems();
							this.clearFunctions();
							if (items){
							 this.items = items;
							}
	},
	addItems : 		function (items){
							for (var i=0;i<items.length; i++){
							  this.items.push(items[i]);
							}
	},
	addItem : 		function (item){
							this.items.push(item);
	},
	clearItems : 		function (){
							this.items = [];;
	},
	addFunction : 		function (functionname){
							this.functions.push(functionname);
	},
	clearFunctions : 	function (){
							this.functions = [];
	},
	run : 			function (){
							for (var i=0; i<this.items.length; i++){
								for (var a=0; a<this.functions.length; a++){
									this.functions[a](this.items[i]);
								}
							}
	}
 });
 

Lib.Dom.Links = {};
Lib.Dom.Links.replaceHref = function (elm, target){
						    	elm = $(elm);
						    	target = (target?target:"javascript:void(0);");
						    	if (Lib.Dom.Elm.isTag(elm, "a")){
							 if (elm.oldhref == undefined || elm.oldhref == null){
							   elm.oldhref = elm.href;
							   elm.href = target;
							 }
							}
};
Lib.Dom.Links.revertHref = function (elm){
							elm = $(elm);
							if (Lib.Dom.Elm.isTag(elm, "a")){
							 if (elm.oldhref != undefined && elm.oldhref != null){
							   elm.href = elm.oldhref;
							   elm.oldhref = null;
							 }
							}
}
Lib.Dom.Links.getHref = function (elm){
							//console.log(elm);
							elm = $(elm);
							//console.log(elm);
							if (Lib.Dom.Elm.isTag(elm, "a")){
							 if (elm.oldhref != undefined && elm.oldhref != null){
								return elm.oldhref;
							 }else {
								return elm.href;
							 }
							}
}
Lib.Dom.Links.replaceTarget = function (elm, target){
						    	elm = $(elm);
						    	target = (target?target:"_self");
						    	if (Lib.Dom.Elm.isTag(elm, "a")){
							 if (elm.oldtarget == undefined || elm.oldtarget == null){
							   elm.oldtarget = elm.href;
							   elm.target = target;
							 }
							}
}
Lib.Dom.Links.revertTarget = function (elm){
							elm = $(elm);
							if (Lib.Dom.Elm.isTag(elm, "a")){
							 if (elm.oldtarget != undefined && elm.oldtarget != null){
							   elm.target = elm.oldtarget;
							   elm.oldtarget = null;
							 }
							}
}
Lib.Dom.Links.getHash = function (elm){
							elm = $(elm);
							if (Lib.Dom.Elm.isTag(elm, "a")){
								var href = Lib.Dom.Links.getHref(elm);
								var hashPosition = href.indexOf('#');
								if (hashPosition > -1){
										return href.substring(hashPosition+1, href.length);
								}
							}
							return false;
}
Lib.Dom.Links.replaceBlanks = function (){
							var blanks = Lib.Dom.getElementsByClassName(document, 'a', 'blank');
							for (var i=0; i<blanks.length; i++){
								Lib.Dom.Links.replaceTarget(blanks[i], "_blank");
							}
}



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


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.Dom.Transitions = function (speed){
	document.write('<meta http-equiv="Page-Exit" content="blendTrans(Duration='+speed+')">');
}


// requires Lib.Delegates
Lib.Ajax.HttpXML = Base.extend({
	constructor :			function (sendpage){
							this.httpxml_prefix = false;
							this.httpxml = false;
							this.create();
							this.data = null;
							this.method = "get";
							this.sendpage = sendpage;
	},
	create	:			function (){
							if (this.httpxml){
							  return this.httpxml;
							}
							try {
							  if (window.XMLHttpRequest) {
							    var req = new XMLHttpRequest();
							    // some older versions of Moz did not support the readyState property
							    // and the onreadystate event so we patch it!
							    if (req.readyState == null) {
							        req.readyState = 1;
							        req.addEventListener("load", function () {
							          req.readyState = 4;
							          if (typeof req.onreadystatechange == "function")
							             req.onreadystatechange();
							        }, false);
							    }
							    this.httpxml = req;
							  }
							  if (window.ActiveXObject) {
							    this.httpxml = new ActiveXObject(this.getControlPrefix() + ".XmlHttp");
							  }
							  
							  return this.httpxml;
							}catch (ex) {}
	},
	getControlPrefix:		function(){
	
							if (this.httpxml_prefix){
								 return this.httpxml_prefix;
							}
							
							var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];
							var o, o2;
							for (var i = 0; i < prefixes.length; i++) {
							  try {
								o = new ActiveXObject(prefixes[i] + ".XmlHttp");
								o2 = new ActiveXObject(prefixes[i] + ".XmlDom");
								return  this.httpxml_prefix = prefixes[i];
							  } catch (ex) {};
							}
							
	},
	send : 				function (data, method){
						  if (this.locked)return false;
							if (data) this.data = data;
							if (method) {
							 this.method = method;
							}else if (this.data){
							 this.method = "post";
							}
							
							
							if (this.sendpage){
							
							 this.httpxml.onreadystatechange = Lib.delegate(this, this.recieve);
							 
							 this.httpxml.open(this.method, this.sendpage);
							 this.httpxml.send(this.data);
							 
							 return true;
							}else {
							  throw "No sendpage specified";
							  return false;
							}
	},
	recieve : 			function (){
							if(this.httpxml.readyState == 4){
							 if (this.httpxml.status!=200){
							   this.onerror(this.httpxml.status);
							 }else {
							   data = this.httpxml.responseXML;
						  	   this.onrecieve(data);
						  	 }
							 this.httpxml.onreadystatechange = null; 
							}
	},
	onrecieve : 			function (data){
	},
	onerror : 			function (data){
	}
});

// requires Lib.Ajax.HttpXML
Lib.Ajax.HttpText = Lib.Ajax.HttpXML.extend({
	recieve : 			function (){
							if(this.httpxml.readyState == 4){
							 if (this.httpxml.status!=200){
							   this.onerror(this.httpxml.status);
							 }else {
							   data = this.httpxml.responseText;
						  	   this.onrecieve(data);
							 }
							 this.httpxml.onreadystatechange = null;
							}
	}
});

// requires Lib.Ajax.HttpText;
// requires Lib.Dom.Elm.Style;
// requires Lib.Delegates;
// requires Lib.Dom.Links;
  Lib.Ajax.AjaxRequester = Base.extend({
  	constructor : 	function (replacement_class, content_div, url_append){
  				callWhenDOMLoaded(Lib.delegate(this, this.setup));
  				this.idcounter = 0;
  				this.idtable = {};
  				this.replacement_class = replacement_class;
  				this.content_div = content_div;
  				this.url_append = url_append;
  				this.previouselement = false;
  	},
  	setup : 	function (){
				var previouslyselectedlist = Lib.Dom.getElementsByClassName(document, 'a', this.replacement_class+'selected');
  				if (previouslyselectedlist.length > 0){
  					this.previouselement = previouslyselectedlist[0];
  				}
  				this.links = Lib.Dom.getElementsByClassName(document, 'a', this.replacement_class);
  				var fList = new Lib.Functions.FunctionList(this.links);
  				fList.addFunction(Lib.delegate(this, Lib.Dom.addEventQuick, "click", Lib.delegate(this, this.clicked)));
  				fList.addFunction(Lib.delegate(this, this.replaceHrefs));
  				fList.run();
  				var hashPosition = location.href.indexOf('#');
  				if (hashPosition > -1){
  					var currentPage = location.href.substring(hashPosition+1, location.href.length);
					if (this.idtable[currentPage]!=null){
						for (var i=0; i<this.links.length; i++){
						 if (this.links[i].replaceid == currentPage){
						  this.clicked(false, this.links[i]);
						 }
						}
					}
  				}
  	

  	},
  	replaceHrefs : 	function (item){
  				var tolocation = Lib.Dom.Links.getHref(item);
  				if (item.id == null || item.id == ""){
  					item.replaceid = "section_link"+this.idcounter;
  					this.idcounter++;
  				}else {
  					item.replaceid = 'section_'+item.id;
  				}
  				
  				this.idtable[item.replaceid] = tolocation;
  				var currentPage = location.href.split("#")[0];
  				Lib.Dom.Links.replaceHref(item, currentPage + '#'+item.replaceid);
  	},
  	clicked : 	function (e,a){
  				Lib.Dom.Elm.Style.addClass(a, this.replacement_class+'selected');
  				if (this.previouselement) Lib.Dom.Elm.Style.removeClass(this.previouselement, this.replacement_class+'selected');
  				this.previouselement = a;
  				var ajax = new Lib.Ajax.HttpText(this.idtable[a.replaceid]+'?'+this.url_append);
  				ajax.onrecieve = Lib.delegate(this, this.onrecieve);
  				ajax.send();
  	},
  	onrecieve : 	function (data){
  				$(this.content_div).innerHTML = data;
  	}
  });

