// TAB MODULE
function TabModule (ObjectName,DivID,RequestURL,ScrollSetting) {	

	// PRIVATE VERIABLES
	var TabObject = document.getElementById(DivID);	
	var MaxWidth = TabObject.offsetWidth;
	var URL = RequestURL;
	var NavObject = (TabObject.childNodes[0].nodeName != '#text') ? TabObject.childNodes[0].childNodes : TabObject.childNodes[1].childNodes;	
	for(a = 0; a < TabObject.childNodes.length; a++) {
		if (TabObject.childNodes[a].className == 'tabloader') {
			var Loader = TabObject.childNodes[a];	
		}		
		if (TabObject.childNodes[a].className == 'tabcontentholder') {
			var ContentHolder = TabObject.childNodes[a];	
			for(b = 0; b < ContentHolder.childNodes.length; b++) {
				if (ContentHolder.childNodes[b].className == 'tabcontent') {
					var Content = ContentHolder.childNodes[b];					
				}	
			}
		}
		if (TabObject.childNodes[a].className == 'tabcontent') {
			var Content = TabObject.childNodes[a];	
		}
		if (TabObject.childNodes[a].className == 'tabscroller') {
			TabObject.childNodes[a].style.display = "none";
		}
	}
	var Name = ObjectName;
	var TabSection = new Array();
	var ShowAllTabs = false;	
	var TotalWidth = 0;
	
	// SCROLL
	var Scroll = false;
	var ScrollHeight = 0;
	if (ScrollSetting != 0 && ScrollSetting != 'auto') {		
		var Scroll = true;	
		var ScrollHeight = parseInt(ScrollSetting);	
		ContentHolder.style.height = ScrollHeight+"px";
		ContentHolder.style.overflow = "hidden";
		Content.style.position = "absolute";
		for(a = 0; a < TabObject.childNodes.length; a++) {
			if (TabObject.childNodes[a].className == 'tabscroller') {
				var Scroller = TabObject.childNodes[a];	
				Scroller.style.height = ScrollHeight+"px";
				Scroller.style.display = "block";
				Scroller.style.visibility = "hidden";
				for(b = 0; b < Scroller.childNodes.length; b++) {
					if (Scroller.childNodes[b].className == 'tabslider') {
						var ScrollerSlider = Scroller.childNodes[b];	
					}	
				}
			}
		}	
	}
	
	// PUBLIC	
	this.Active = 0;
	this.ActiveSection = 0;	
	this.ButtonActive = null;
	this.ButtonActiveSection = null;	
	this.MinWidth = 0;
	this.FirstElement = 1;	
	this.LastElement = 1;
	this.InAnimation = false;
	
	// SCAN NAV
	var CountLI = 0;
	var CountSection = 0;
	var SectionClassID = '';
	for(i=0; i < NavObject.length; i++) {
		if (NavObject[i].nodeName == 'DIV') {
			
			if (SectionClassID == '') {
				SectionClassID = NavObject[i].className.split(' ')[0];
				TabSection[CountSection] = new Array();
			} else if (SectionClassID != NavObject[i].className.split(' ')[0]) {
				SectionClassID = NavObject[i].className.split(' ')[0];				
				CountSection++;
				TabSection[CountSection] = new Array();
				CountLI = 0;
			} else {
				CountLI++;
			}	
			
			if (NavObject[i].className.match(/active/)) {
				this.Active = CountLI;
				this.ActiveSection = CountSection;
				this.ButtonActive = CountLI;
				this.ButtonActiveSection = CountSection;	
				TabSection[CountSection][CountLI] = new Array (i,NavObject[i].offsetWidth+1);	
				NavObject[i].onclick = new Function ("document."+Name+".LoadTab("+CountSection+","+CountLI+")");
				NavObject[i].setAttribute('id',Name+'_'+CountSection+'_'+CountLI);	
				TotalWidth += NavObject[i].offsetWidth+17;
			}	
			
			else if (NavObject[i].className.match(/sub/)) {
				TabSection[CountSection][CountLI] = new Array (i,NavObject[i].offsetWidth+18);		
				NavObject[i].onclick = new Function ("document."+Name+".Previous("+CountSection+")");	
				NavObject[i].setAttribute('id',Name+'_'+CountSection+'_'+CountLI);
				NavObject[i].style.display = "none";	
			}				
			
			else if (NavObject[i].className.match(/add/)) {
				TabSection[CountSection][CountLI] = new Array (i,NavObject[i].offsetWidth+18);				
				NavObject[i].onclick = new Function ("document."+Name+".Next("+CountSection+")");	
				NavObject[i].setAttribute('id',Name+'_'+CountSection+'_'+CountLI);	
				NavObject[i].style.display = "none";
			}	
			
			else {
				TabSection[CountSection][CountLI] = new Array (i,NavObject[i].offsetWidth+17);
				NavObject[i].onclick = new Function ("document."+Name+".LoadTab("+CountSection+","+CountLI+")");
				NavObject[i].setAttribute('id',Name+'_'+CountSection+'_'+CountLI);
				TotalWidth += NavObject[i].offsetWidth+17;
			}	
			
	
		}
	}
	
	// CHECK SHOW TABS	
	if (MaxWidth > TotalWidth) {
		ShowAllTabs = true;
	}
	
	// DEC 14 HACK
	ShowAllTabs = false;
	
	// SET GROUPS/SET VISIBLE
	for (a = 0; a < TabSection.length; a++) {
		
		var SliderHolder = document.createElement('div');
			SliderHolder.setAttribute('id',Name+'_Holder_'+a);
			SliderHolder.style.overflow = "hidden";
			SliderHolder.style.width = "0px";
			SliderHolder.style.display = "block";
		
		var Slider = document.createElement('div');
			Slider.setAttribute('id',Name+'_Silder_'+a);			
	
		var SectionWidth = 0;	
		for (b = 1; b < TabSection[a].length-1; b++) {
			Slider.appendChild(document.getElementById(Name+'_'+a+'_'+b));	
			SectionWidth += TabSection[a][b][1]+4;
		}
		
		Slider.style.width = SectionWidth+"px";
		SliderHolder.appendChild(Slider);		
		
		document.getElementById(Name+'_0_0').parentNode.insertBefore(SliderHolder,document.getElementById(Name+'_'+a+'_'+(TabSection[a].length-1))); 		
		
		if (this.ActiveSection == a) {
			if(TabSection[a].length > 3 && !ShowAllTabs) {	
				document.getElementById(Name+'_'+a+'_'+(TabSection[a].length-1)).style.display = "block";
				this.MinWidth += TabSection[a][(TabSection[a].length-1)][1];	
			}		
		} else {		
			if(TabSection[a].length > 3 && !ShowAllTabs) {	
				document.getElementById(Name+'_'+a+'_'+(TabSection[a].length-1)).style.display = "block";
				this.MinWidth += TabSection[a][(TabSection[a].length-1)][1];
			}			
			if (ShowAllTabs) {
				var SectionWidth = 0;
				for (b = 1; b < TabSection[a].length-1; b++) {
				SectionWidth += TabSection[a][b][1];	
				}
				document.getElementById(Name+'_Holder_'+a).style.width = SectionWidth+"px";
			} else {			
				document.getElementById(Name+'_Holder_'+a).style.width = TabSection[a][1][1]+"px";
				this.MinWidth += TabSection[a][1][1];			
			}
		}		
	}		
		
	// DISPLAY ACTIVE GROUP	
	var ActiveWidth = 0;
	this.FirstElement = 1;
	for (a = 1; a < TabSection[this.ActiveSection].length-1; a++) {	
		if ((this.MinWidth+ActiveWidth+TabSection[this.ActiveSection][a][1]) < MaxWidth) {
			ActiveWidth += TabSection[this.ActiveSection][a][1];	
			this.LastElement = a+1;
		} else {
		 break;
		}
	}	
	document.getElementById(Name+'_Holder_'+this.ActiveSection).style.width	= ActiveWidth+"px"; 
	
	if (this.LastElement == TabSection[this.ActiveSection].length-1) {				
		document.getElementById(Name+'_'+this.ActiveSection+'_'+(TabSection[this.ActiveSection].length-1)).style.display = "none";		
		this.MinWidth -= TabSection[this.ActiveSection][TabSection[this.ActiveSection].length-1][1];			
	}	
	TabObject.style.visibility = "visible";		
	
	// LOAD 
	this.LoadTab = function (Selection,ID) { 
	
		// OPEN TAB SECTION
		if (Selection != this.ActiveSection && !ShowAllTabs) {
			this.Next(Selection);		
		}
		
		// SET BUTTONS
		if (this.ButtonActive != null) {
			document.getElementById(Name+'_'+this.ButtonActiveSection+'_'+this.ButtonActive).className = document.getElementById(Name+'_'+this.ButtonActiveSection+'_'+this.ButtonActive).className.split(' ')[0];
		}
		document.getElementById(Name+'_'+Selection+'_'+ID).className = document.getElementById(Name+'_'+Selection+'_'+ID).className+' active';
		this.ButtonActive = ID;
		this.ButtonActiveSection = Selection
			
		// PRE LOADER
		Content.style.visibility = "hidden";
		Loader.style.left = ((Content.offsetWidth-16)/2)+"px";
		Loader.style.top = ((Content.offsetHeight-16)/2)+50+"px";
		Loader.innerHTML = '<img src="/images/tabs-loader.gif" width="16" height="16" />';	
		
		// CONTENT
		var ContentPost = new HTTPRequest ();
		ContentPost.URL = URL;
		ContentPost.Parameters = "section="+Selection+"&id="+ID;	
		ContentPost.Completed = function(Response) {
				
				Loader.innerHTML = '';
				Loader.style.left = "0px";
				Loader.style.top = "0px";				
				Content.innerHTML = Response;	
				Content.style.visibility = "visible";
				
				var x = Content.getElementsByTagName("script");   
				for(var i=0;i<x.length;i++)  { 
					eval(x[i].text);  
				}
				
				document[Name].ScrollBarSet();
			};	
		ContentPost.Error = function (Response) {
				Loader.innerHTML = '';
				Loader.style.left = "0px";
				Loader.style.top = "0px";				
				Content.innerHTML = '';
			};	
		ContentPost.POST();				
			
	}
	
	this.LoadTab(this.ActiveSection,this.Active);
	
	// NEXT
	this.Next = function (Selection) {
		if (!this.InAnimation) {		
			if (this.ActiveSection != Selection) {
			
				// CURRENT SELECTION
				this.Animation(this.ActiveSection,TabSection[this.ActiveSection][1][1],0);
				
				// PREVIOUS
				if (document.getElementById(Name+'_'+this.ActiveSection+'_'+0).offsetWidth != 0) {
					this.AnimationWidth(document.getElementById(Name+'_'+this.ActiveSection+'_'+0),0);
					this.MinWidth -= TabSection[this.ActiveSection][0][1];	
				}
				
				// NEXT
				if(TabSection[this.ActiveSection].length > 3 && document.getElementById(Name+'_'+this.ActiveSection+'_'+(TabSection[this.ActiveSection].length-1)).offsetWidth == 0) {	
					this.AnimationWidth(document.getElementById(Name+'_'+this.ActiveSection+'_'+(TabSection[this.ActiveSection].length-1)),26);
					this.MinWidth += TabSection[this.ActiveSection][(TabSection[this.ActiveSection].length-1)][1];
				}	

				// ADD FIRST ITEM
				this.MinWidth += TabSection[this.ActiveSection][1][1];	
				
								this.ActiveSection = Selection;
				
								// NEW SELECTION				
								this.MinWidth -= TabSection[this.ActiveSection][1][1];		
								
								var ActiveWidth = 0;
								this.FirstElement = 1;
				for (a = 1; a < TabSection[Selection].length-1; a++) {	
					if ((this.MinWidth+ActiveWidth+TabSection[Selection][a][1]) <= MaxWidth) {
						ActiveWidth += TabSection[Selection][a][1];	
						this.LastElement = a+1;
					} else {
					 break;
					}
				}

				
				if (this.LastElement == TabSection[Selection].length-1 && TabSection[Selection].length > 3) {
					this.AnimationWidth(document.getElementById(Name+'_'+Selection+'_'+(TabSection[Selection].length-1)),0);				
					this.MinWidth -= TabSection[Selection][TabSection[Selection].length-1][1];			
				}
				
				this.InAnimation = true;
				this.Animation(Selection,ActiveWidth,0);
				
			
			} else {			
				if (document.getElementById(Name+'_'+Selection+'_'+0).style.display == "none" || document.getElementById(Name+'_'+Selection+'_'+0).offsetWidth == 0) {
					document.getElementById(Name+'_'+Selection+'_'+0).style.width = "0px";	
					document.getElementById(Name+'_'+Selection+'_'+0).style.display = "block";	
					this.AnimationWidth(document.getElementById(Name+'_'+Selection+'_'+0),26);
					this.MinWidth += TabSection[Selection][0][1];			
				}
				
				var SlideX = document.getElementById(Name+'_'+Selection+'_'+this.LastElement).offsetLeft;
				
				var ActiveWidth = 0;
				this.FirstElement = this.LastElement;
				
				for (a = this.LastElement; a < TabSection[Selection].length-1; a++) {	
					if ((this.MinWidth+ActiveWidth+TabSection[Selection][a][1]) <= MaxWidth) {
						ActiveWidth += TabSection[Selection][a][1];	
						this.LastElement = a+1;
					} else {
					 break;
					}
				}

				if (this.LastElement == TabSection[Selection].length-1) {
					this.AnimationWidth(document.getElementById(Name+'_'+Selection+'_'+(TabSection[Selection].length-1)),0);				
					this.MinWidth -= TabSection[Selection][TabSection[Selection].length-1][1];			
				}	

				this.InAnimation = true;
				this.Animation(Selection,ActiveWidth,(SlideX*-1));
			} 	
		}
	}
	
	// PREVIOUS
	this.Previous = function (Selection) {
		if (!this.InAnimation) {
		
				if (document.getElementById(Name+'_'+Selection+'_'+(TabSection[Selection].length-1)).offsetWidth == 0) {
					this.AnimationWidth(document.getElementById(Name+'_'+Selection+'_'+(TabSection[Selection].length-1)),26);
					this.MinWidth += TabSection[Selection][(TabSection[Selection].length-1)][1];			
				}
		
				var ActiveWidth = 0;
				this.LastElement = this.FirstElement;
				for (a = this.FirstElement-1; a > 0; a--) {
					if ((this.MinWidth+ActiveWidth+TabSection[Selection][a][1]) < MaxWidth) {
						ActiveWidth += TabSection[Selection][a][1];
						this.FirstElement = a;
					} else {				
						break;
					}
				}	
					
				if (this.FirstElement == 1) {
					this.AnimationWidth(document.getElementById(Name+'_'+Selection+'_'+0),0);
					this.MinWidth -= TabSection[Selection][0][1];			
				}		
			
			var SlideX = document.getElementById(Name+'_'+Selection+'_'+this.FirstElement).offsetLeft;		
			this.InAnimation = true;
			this.Animation(Selection,ActiveWidth,(SlideX*-1));
			
		}		 	
	}
	
	// ANIMATION
	this.AnimationWidth = function (Obj,Width) {	
		
		var IE = /*@cc_on!@*/false;
		Obj.style.display = "block";
		
		function EaseInOut(Start,End,Current) {			
			if (Start < End) {
				var nEnd = Math.abs(Math.abs(End)-Math.abs(Start));
				var nCurrent = Math.abs(nEnd - Math.abs(Math.abs(End)-Math.abs(Current)));		
			} else if (Start > End) {
				var nEnd = Math.abs(Math.abs(Start)-Math.abs(End));
				var nCurrent = Math.abs(nEnd - Math.abs(Math.abs(Current)-Math.abs(End)));	
			}	
			var Percentage = Math.abs(Math.round((nCurrent/nEnd)*100))+1;
			if (Percentage < 50) {
				return Math.ceil(Math.pow(nEnd*(Percentage/100),.65));				
			} else {
				return (100-Percentage <= 0) ? (IE) ? 2:1 : Math.ceil(Math.pow(nEnd*((100-Percentage)/100),.65));
			}	 
		} 
		
		function ObjDiv(Obj,Start,Increment) {		
			if (Start < Width && Width > Obj.offsetWidth) {			
				Obj.style.width = (Obj.offsetWidth+Increment)+"px";
				ObjDelay = function () { ObjDiv(Obj,Start,EaseInOut(Start,Width,Obj.offsetWidth)); } 
				setTimeout(ObjDelay,40);	
			} else if (Start > Width && Width < Obj.offsetWidth) {			
				Obj.style.width = (Obj.offsetWidth-Increment)+"px";
				ObjDelay = function () { ObjDiv(Obj,Start,EaseInOut(Start,Width,Obj.offsetWidth)); } 
				setTimeout(ObjDelay,40);	
			} else if (Start != Width) {
				Obj.style.width = Width+"px";
				if (Obj.offsetWidth == 0) {
					Obj.style.display = "none";
				} 		
			}  else if (Start == Width) {
				Obj.style.width = Width+"px";
				if (Obj.offsetWidth == 0) {
					Obj.style.display = "none";
				} 	
			} 		
		}				
		
		var ObjDelay = function () { ObjDiv(Obj,Obj.offsetWidth,EaseInOut(Obj.offsetWidth,Width,Obj.offsetWidth)); } 
		setTimeout(ObjDelay,40);	
	}
	
	
	// ANIMATION
	this.Animation = function (Selection,Width,Position) {	
		
		var IE = /*@cc_on!@*/false;
		
		function EaseInOut(Start,End,Current) {			
			if (Start < End) {
				var nEnd = Math.abs(Math.abs(End)-Math.abs(Start));
				var nCurrent = Math.abs(nEnd - Math.abs(Math.abs(End)-Math.abs(Current)));		
			} else if (Start > End) {
				var nEnd = Math.abs(Math.abs(Start)-Math.abs(End));
				var nCurrent = Math.abs(nEnd - Math.abs(Math.abs(Current)-Math.abs(End)));	
			}	
			var Percentage = Math.abs(Math.round((nCurrent/nEnd)*100))+1;
			if (Percentage < 50) {
				return Math.ceil(Math.pow(nEnd*(Percentage/100),.65));				
			} else {
				return (100-Percentage <= 0) ? (IE) ? 2:1 : Math.ceil(Math.pow(nEnd*((100-Percentage)/100),.65));
			}	 
		} 
		
		function HolderDiv(Start,Increment) {		
			if (Start < Width && Width > document.getElementById(Name+'_Holder_'+Selection).offsetWidth) {			
				document.getElementById(Name+'_Holder_'+Selection).style.width = (document.getElementById(Name+'_Holder_'+Selection).offsetWidth+Increment)+"px";
				HolderDelay = function () { HolderDiv(Start,EaseInOut(Start,Width,document.getElementById(Name+'_Holder_'+Selection).offsetWidth)); } 
				setTimeout(HolderDelay,40);	
			} else if (Start > Width && Width < document.getElementById(Name+'_Holder_'+Selection).offsetWidth) {			
				document.getElementById(Name+'_Holder_'+Selection).style.width = (document.getElementById(Name+'_Holder_'+Selection).offsetWidth-Increment)+"px";
				HolderDelay = function () { HolderDiv(Start,EaseInOut(Start,Width,document.getElementById(Name+'_Holder_'+Selection).offsetWidth)); } 
				setTimeout(HolderDelay,40);	
			} else if (Start != Width) {
				document.getElementById(Name+'_Holder_'+Selection).style.width = Width+"px";	
			}  else if (Start == Width) {
				document.getElementById(Name+'_Holder_'+Selection).style.width = Width+"px";	
			}		
		}
		var HolderDelay = function () { HolderDiv(document.getElementById(Name+'_Holder_'+Selection).offsetWidth,EaseInOut(document.getElementById(Name+'_Holder_'+Selection).offsetWidth,Width,document.getElementById(Name+'_Holder_'+Selection).offsetWidth)); } 
		setTimeout(HolderDelay,40);		
		
		function SlideDiv(Start,Increment) {			
			if (Start < Position && Position > document.getElementById(Name+'_Silder_'+Selection).offsetLeft) {			
				document.getElementById(Name+'_Silder_'+Selection).style.left = (document.getElementById(Name+'_Silder_'+Selection).offsetLeft+Increment)+"px";			
				SliderDelay = function () {  SlideDiv(Start,EaseInOut(Start,Position,document.getElementById(Name+'_Silder_'+Selection).offsetLeft));  }
				setTimeout(SliderDelay,40);
			} else if (Start > Position && Position < document.getElementById(Name+'_Silder_'+Selection).offsetLeft) {			
				document.getElementById(Name+'_Silder_'+Selection).style.left = (document.getElementById(Name+'_Silder_'+Selection).offsetLeft-Increment)+"px";	
				SliderDelay = function () {  SlideDiv(Start,EaseInOut(Start,Position,document.getElementById(Name+'_Silder_'+Selection).offsetLeft));  }
				setTimeout(SliderDelay,40);
			} else if (document.getElementById(Name+'_Silder_'+Selection).offsetLeft != Position && IE) {
				document.getElementById(Name+'_Silder_'+Selection).style.left = (Position-1)+"px";	
				document[Name].InAnimation = false;
			} else if (document.getElementById(Name+'_Silder_'+Selection).offsetLeft == Position) {	
				document[Name].InAnimation = false;		
			}			
		}	
		var SliderDelay = function () {  SlideDiv(document.getElementById(Name+'_Silder_'+Selection).offsetLeft,EaseInOut(document.getElementById(Name+'_Silder_'+Selection).offsetLeft,Position,document.getElementById(Name+'_Silder_'+Selection).offsetLeft));  }
		setTimeout(SliderDelay,40);		
	}
	
	// SCROLL BAR
		
		// SCROLL SET
		this.ScrollBarSet = function () {				  
			if (Scroll) {
				// RESET
				Content.style.top = "0px";
				ScrollerSlider.style.top = "0px";
				
				if (ContentHolder.offsetHeight < Content.offsetHeight) {
					
					// SET SLIDER
					var SliderHeight  = (ContentHolder.offsetHeight * Scroller.offsetHeight) / Content.offsetHeight;
					if(SliderHeight  < 15) SliderHeight = 15;							
					ScrollerSlider.style.height = Math.round(SliderHeight) + "px";			
					
					// SCROLL DISTANCE
					var ScrollDistance = Math.round(Scroller.offsetHeight-SliderHeight);			
					
					// SET POSITION
					if (ContentHolder.offsetTop != 0) {
					var SliderY	= ((Content.offsetTop*-1)/(Content.offsetHeight - ContentHolder.offsetHeight))*ScrollDistance;	
						if (SliderY > ScrollDistance) {
						ScrollerSlider.style.top = ScrollDistance+"px";
						var docY = 0 - (ScrollDistance * (Content.offsetHeight - ContentHolder.offsetHeight) / ScrollDistance);
						Content.style.top = docY + "px";
						} else {
						ScrollerSlider.style.top = SliderY+"px";	
						}
					}	
					
					// SHOW
					Scroller.style.visibility = "visible";
					
					// SET DRAG
					Drag.init(ScrollerSlider,null,0,0,0,ScrollDistance);	
					ScrollerSlider.onDrag = function (x,y) {
					  var scrollY = parseInt(ScrollerSlider.style.top);
					  var docY = 0 - (scrollY * (Content.offsetHeight - ContentHolder.offsetHeight) / ScrollDistance);
					  Content.style.top = docY + "px";
					}
				} else {
					Scroller.style.visibility = "hidden";	
				}
			}			
		}	
		
		// SCROLL FUNCTION		
		var Drag = {
			obj : null,
			init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
			{
				o.onmousedown	= Drag.start;
				o.hmode			= bSwapHorzRef ? false : true ;
				o.vmode			= bSwapVertRef ? false : true ;
				o.root = oRoot && oRoot != null ? oRoot : o ;
		
				if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
				if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
				if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
				if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";
		
				o.minX	= typeof minX != 'undefined' ? minX : null;
				o.minY	= typeof minY != 'undefined' ? minY : null;
				o.maxX	= typeof maxX != 'undefined' ? maxX : null;
				o.maxY	= typeof maxY != 'undefined' ? maxY : null;
		
				o.xMapper = fXMapper ? fXMapper : null;
				o.yMapper = fYMapper ? fYMapper : null;
		
				o.root.onDragStart	= new Function();
				o.root.onDragEnd	= new Function();
				o.root.onDrag		= new Function();
			},
		
			start : function(e)
			{
				var o = Drag.obj = this;
				e = Drag.fixE(e);
				var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
				var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
				o.root.onDragStart(x, y);
				o.lastMouseX	= e.clientX;
				o.lastMouseY	= e.clientY;
				if (o.hmode) {
					if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
					if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
				} else {
					if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
					if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
				}
				if (o.vmode) {
					if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
					if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
				} else {
					if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
					if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
				}
		
				document.onmousemove	= Drag.drag;
				document.onmouseup		= Drag.end;
				return false;
			},
		
			drag : function(e)
			{
				e = Drag.fixE(e);
				var o = Drag.obj;
				var ey	= e.clientY;
				var ex	= e.clientX;
				var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
				var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
				var nx, ny;
		
				if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
				if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
				if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
				if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);
		
				nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
				ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));
				
				if (o.xMapper)		nx = o.xMapper(y)
				else if (o.yMapper)	ny = o.yMapper(x)
		
				Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
				Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
				Drag.obj.lastMouseX	= ex;
				Drag.obj.lastMouseY	= ey;
		
				Drag.obj.root.onDrag(nx, ny);
				return false;
			},
		
			end : function()
			{
				document.onmousemove = null;
				document.onmouseup   = null;
				Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
											parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
				Drag.obj = null;
			},
		
			fixE : function(e)
			{
				if (typeof e == 'undefined') e = window.event;
				if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
				if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
				return e;
			}
		};				
}
