Zadig = {
'ie': (navigator.userAgent.indexOf("MSIE")!= -1),	
'ie6': (navigator.userAgent.indexOf("MSIE 6")!= -1),
'bind': function(fn, obj){return function(){fn.apply(obj, arguments)};},
'inherit' : function(from, to)
{
	var z= function(){}
	z.prototype = from.prototype;
	for(var i in z.prototype)
	{
		if(to.prototype[i]==null)to.prototype[i] = z.prototype[i];
	}
	to.prototype.superClass = from;
	to.superClass = from;
},
/*{
	var z= function(){}
	z.prototype = from.prototype;
	to.prototype = new z();
	to.prototype.constructor = to;
	to.superClass = from;
},*/
'addListener':function(type, target, listener)
{
	target.addEventListener ? target.addEventListener(type, listener, false) : target.attachEvent('on' + type, listener);
},
'removeListener':function(type, target, listener)
{
	target.addEventListener ? target.removeEventListener(type, listener, false) : target.detachEvent('on' + type, listener);
},
'stopEvent' : function(e)
{
	e.stopPropagation ?	e.stopPropagation() : e.cancelBubble = true;
  e.preventDefault ? e.preventDefault() : e.returnValue = false;
},
'getTarget' :  function(e)
{
	return e.srcElement ? e.srcElement : e.target;	
},
'pageRect': function()
{
	return {'x':document.documentElement.offsetWidth, 'y': Math.max(document.documentElement.scrollHeight, document.documentElement.offsetHeight - document.documentElement.scrollTop)};
},
'viewPort' : function()
{
	var x =  self.pageXOffset ? self.pageXOffset : document.documentElement.scrollLeft;	
	var width = self.innerWidth ? self.innerWidth : document.documentElement.clientWidth;
	var y = self.pageYOffset ? self.pageYOffset : document.documentElement.scrollTop;
	var height = self.innerHeight ? self.innerHeight : document.documentElement.clientHeight;
	return {'x':x, 'y':y, 'width':width, 'height':height};
},
'getRect' : function(e)
{
	var width = e.offsetWidth;
	var height = e.offsetHeight;
	
	var left = 0;
	var top = 0;
	
	if (e.offsetParent)
	{
		left = e.offsetLeft
		top = e.offsetTop
		
		while (e = e.offsetParent) 
		{
			left += e.offsetLeft
			top += e.offsetTop
		}
	}
	return {"x": left, "y": top, 'width':width, 'height':height}
},
'posAt' : function(obj) 
{
  var pos = arguments[1] ? arguments[1] : 'cm';
	var rect = arguments[2] ? this.getRect(arguments[2]) : Zadig.viewPort();
	var off = arguments[3] ? arguments[3] : {x:0,y:0};
	var orect = Zadig.getRect(obj);
	
	obj.style.position = 'absolute';
	var x = rect.x;
	var y = rect.y;
  //calc x
  if(pos.match(/c/)){x += Math.round((rect.width - orect.width) /2);}
  else if(pos.match(/r/)) {x += rect.width-2;}
  //calc y
  if(pos.match(/m/)){y += Math.round((rect.height - orect.height) /2);}
  else if(pos.match(/b/)) {y += rect.height;} 
  else if(pos.match(/t/)) {y -= rect.height;} 
	obj.style.top = y+off.y + "px";
	obj.style.left = x+off.x + "px";
},
'mousePos' : function(e)
{
	var x = 0;
	var y = 0;
	if (e.pageX || e.pageY)
	{
		x = e.pageX;
		y = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
		x = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		y = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	}
	if(arguments[1])
	{
		var r = Zadig.getRect(arguments[1]);
		x -= r.x;
		y -= r.y;
	}
	return {'x':x, 'y': y};
},

'setOpacity' : function (element, opacity) 
{
	if(Zadig.ie)
	{
		element.style.filter = "alpha(opacity:"+opacity+");"; 
		return;
	}
	if(element.style.opacity != undefined){element.style.opacity = opacity/100; return;}
	if(element.style.KHTMLopacity) {element.style.KHTMLopacity = opacity/100; return;} 
	if(element.style.Mozopacity) {element.style.Mozopacity = opacity/100; return;}
	
},
'getStyle' : function (element, prop)
{
	if (element.currentStyle)
		return element.currentStyle[prop];
	if (window.getComputedStyle)
		return document.defaultView.getComputedStyle(x,null).getPropertyValue(prop);
	return '';
},

'bindComponents' : function(e)
{
	var elements = arguments[1]==null ? document.getElementsByTagName("*") : arguments[1];
	var i;
	for(i in elements)
	{
		try{
		if(elements[i].attributes.flow == null)continue;
		var element = elements[i];	
		eval('var args =' + elements[i].attributes.flow.nodeValue.replace(/&apos;/g,'\'')+';');
		var comp;
		var ex;
		for(comp in args){
			new args[comp].code(elements[i], args[comp]);}
		}catch(ex){}
	}
}
}
Zadig.addListener('load',window,Zadig.bindComponents);

Zadig.Hover = function(element, args) 
{
	this.element = element;
	this.classOver = args.classOver;
	this.removeRegex = new RegExp("(^| )"+args.classOver+"(|$)");
	Zadig.addListener('mouseover',element,Zadig.bind(this.over, this));
	Zadig.addListener('mouseout',element,Zadig.bind(this.out, this)); 
}
Zadig.Hover.prototype.over = function (e){this.element.className += " "+this.classOver;}
Zadig.Hover.prototype.out = function (e){this.element.className = this.element.className.replace(this.removeRegex,'');}
/*
A = function(s)
{
	this.s = s;
	alert(this.constructor);
	
}
A.prototype = {
'bar': function (){alert(this.s + " a");},
'j': function (){alert(this.s + 'j');}
}
B = function(s)
{
	this.superClass(s);
}
B.prototype = {'bar' : function (){alert(this.s);}}
Zadig.inherit(A, B);

new B('ff');*/
