SZN.Scrollbar = SZN.ClassMaker.makeClass({
	NAME: "Scrollbar",
	VERSION: "1.0",
	CLASS: "class"
});

SZN.Scrollbar.prototype.$constructor = function(parent,type) {
	this.parent = parent;
	if(!this.parent) return false;
	

	this.eventsCache = [];
	this.eventsWheelCash = false;
	this.eventsWheelCash2 = false;
	this.moveInterval = false;
	this.type = 'v';
	if(type) this.type = type;
	this.stepSize = 10;
	this.wheelMulti = 5;
	this.barMulti = 5;
	
	this.scroller = false;
	this.scrollerId = this.parent.wrapper.id+'-'+this.type+'Scroller';
	this.scrollerWeight = 15;
	this.scrollerDrag = false;
	this.scrollerExists = false;
	this.scrollerCssExists = false;
	
	this.scrollerUp = false;
	this.scrollerUpId = this.parent.wrapper.id+'-'+this.type+'ScrollerUp';
	this.scrollerUpWeight = 0;
	this.scrollerUpCssExists = false;
	this.scrollerDown = false;
	this.scrollerDownId = this.parent.wrapper.id+'-'+this.type+'ScrollerDown';
	this.scrollerDownWeight = 0;
	this.scrollerDownCssExists = false;
	this.scrollerBar = false;
	this.scrollerBarId = this.parent.wrapper.id+'-'+this.type+'ScrollerBar';
	this.scrollerBarCssExists = false;
	this.scrollerBarPos = 0;
	this.scrollerBarSpace = 0;
	this.scrollerBarWeight = 0;
	this.scrollerBarDragPos = 0;
	
	this.scroller = SZN.cEl('DIV',this.scrollerId,this.type+'Scroller');
	this.scrollerUp = SZN.cEl('DIV',this.scrollerUpId,this.type+'ScrollerUp');
	this.scrollerDown = SZN.cEl('DIV',this.scrollerDownId,this.type+'ScrollerDown');
	this.scrollerBar = SZN.cEl('DIV',this.scrollerBarId,this.type+'ScrollerBar');
	this.scroller.appendChild(this.scrollerDown);
	this.scroller.appendChild(this.scrollerUp);
	this.scroller.appendChild(this.scrollerBar);
	SZN.Dom.append(Array(this.parent.wrapper,this.scroller));
	
	this.eventsCache.push(SZN.Events.addListener(this.scrollerDown,"click",this,"scroll",false));
	this.eventsCache.push(SZN.Events.addListener(this.scrollerDown,"mouseup",this,"autoscrollStop",false));
	this.eventsCache.push(SZN.Events.addListener(this.scrollerDown,"mouseout",this,"autoscrollStop",false));
	this.eventsCache.push(SZN.Events.addListener(this.scrollerDown,"mousedown",this,"autoscroll",false));
	this.eventsCache.push(SZN.Events.addListener(this.scrollerDown,"mouseover",this,"hoverOver",false));
	this.eventsCache.push(SZN.Events.addListener(this.scrollerDown,"mouseout",this,"hoverOut",false));
	

	this.eventsCache.push(SZN.Events.addListener(this.scrollerUp,"click",this,"scroll",false));
	this.eventsCache.push(SZN.Events.addListener(this.scrollerUp,"mouseup",this,"autoscrollStop",false));
	this.eventsCache.push(SZN.Events.addListener(this.scrollerUp,"mouseout",this,"autoscrollStop",false));
	this.eventsCache.push(SZN.Events.addListener(this.scrollerUp,"mousedown",this,"autoscroll",false));
	this.eventsCache.push(SZN.Events.addListener(this.scrollerUp,"mouseover",this,"hoverOver",false));
	this.eventsCache.push(SZN.Events.addListener(this.scrollerUp,"mouseout",this,"hoverOut",false));
	
	this.eventsCache.push(SZN.Events.addListener(this.scroller,"click",this,"barJump",false));
	this.eventsCache.push(SZN.Events.addListener(this.scroller,"mouseup",this,"barDrop",false));
	this.eventsCache.push(SZN.Events.addListener(this.scroller,"mousedown",this,"barDrag",false));
	this.eventsCache.push(SZN.Events.addListener(this.scrollerBar,"click",this,"barDrop",false));
	this.eventsCache.push(SZN.Events.addListener(this.scrollerBar,"mouseover",this,"hoverOver",false));
	this.eventsCache.push(SZN.Events.addListener(this.scrollerBar,"mouseout",this,"hoverOut",false));
	this.eventsCache.push(SZN.Events.addListener(this.parent.wrapper,"mousemove",this,"barMove",false));
	this.eventsCache.push(SZN.Events.addListener(this.parent.wrapper,"mouseup",this,"barDrop",false));
	this.eventsCache.push(SZN.Events.addListener(document,"mouseup",this,"barDrop",false));	
	
	this.checkCss();
	
	//this.reset();
}
SZN.Scrollbar.prototype.checkCss = function() {
	
	this.scrollerCssExists = false;
	this.scrollerUpCssExists = false;
	this.scrollerDownCssExists = false;
	this.scrollerBarCssExists = false;
	var cssRules = false;
	//this.debug('pocet stylu: '+document.styleSheets.length);
	for(s=0;s<document.styleSheets.length;s++){
		//this.debug('styl: '+s+' typ: '+document.styleSheets[s].type);
		if(document.styleSheets[s].rules) cssRules = document.styleSheets[s].rules;
		else cssRules = document.styleSheets[s].cssRules;
		for(r=0;r<cssRules.length;r++){
			//this.debug(cssRules[r].selectorText);
			if(cssRules[r].selectorText=='#'+this.scrollerId) this.scrollerCssExists = true;
			if(cssRules[r].selectorText=='#'+this.scrollerUpId) this.scrollerUpCssExists = true;
			if(cssRules[r].selectorText=='#'+this.scrollerDownId) this.scrollerDownCssExists = true;
			if(cssRules[r].selectorText=='#'+this.scrollerBarId) this.scrollerBarCssExists = true;
		}
	}
}
SZN.Scrollbar.prototype.hoverOver = function(e,elm) {
	if(elm==this.scrollerUp && !this.scrollerUpCssExists) elm.style.backgroundColor = '#a9bdf1';
	if(elm==this.scrollerDown && !this.scrollerDownCssExists) elm.style.backgroundColor = '#a9bdf1';
	if(elm==this.scrollerBar && !this.scrollerBarCssExists) elm.style.backgroundColor = '#a9bdf1';
}
SZN.Scrollbar.prototype.hoverOut = function(e,elm) {
	if(elm==this.scrollerUp && !this.scrollerUpCssExists) elm.style.backgroundColor = '#d3daed';
	if(elm==this.scrollerDown && !this.scrollerDownCssExists) elm.style.backgroundColor = '#d3daed';
	if(elm==this.scrollerBar && !this.scrollerBarCssExists) elm.style.backgroundColor = '#d3daed';
}
SZN.Scrollbar.prototype.debug = function(message) {
	this.parent.debug(message);
}
SZN.Scrollbar.prototype.reset = function(padding) {
	
	
	if(this.scrollerCssExists){
		if(this.type=='h'){
			//dodelat zjisteni zadane sirky v CSS (computed vraci mimo IE vzdy hodnotu)
			if(!isNaN(parseInt(SZN.Dom.getStyle(this.scroller,"height")))) this.scrollerWeight = this.scroller.offsetHeight;
			if(!this.scrollerWeight) this.scrollerWeight = 15;
			if(!intval(SZN.Dom.getStyle(this.scroller,"height"))) this.scroller.style.height = this.scrollerWeight+'px';
			if(!intval(SZN.Dom.getStyle(this.scroller,"width"))){
				this.scroller.style.width = this.parent.wrapper.clientWidth+'px';
				if(this.parent.vScroll && this.parent.contentOverflowHeight>0) this.scroller.style.width = (this.parent.wrapper.clientWidth-this.parent.vScroll.scrollerWeight)+'px';
			}
			if(!intval(SZN.Dom.getStyle(this.scroller,"bottom"))) this.scroller.style.bottom = '0px';
			if(!intval(SZN.Dom.getStyle(this.scroller,"left"))) this.scroller.style.left = '0px';	
		}else{
			if(!isNaN(parseInt(SZN.Dom.getStyle(this.scroller,"width")))) this.scrollerWeight = this.scroller.offsetWidth;
			if(!this.scrollerWeight) this.scrollerWeight = 15;
			if(!intval(SZN.Dom.getStyle(this.scroller,"width"))) this.scroller.style.width = this.scrollerWeight+'px';
			if(!intval(SZN.Dom.getStyle(this.scroller,"height"))){
				this.scroller.style.height = this.parent.wrapper.clientHeight+'px';	
				if(this.parent.hScroll && this.parent.contentOverflowWidth>0) this.scroller.style.height = (this.parent.wrapper.clientHeight-this.parent.hScroll.scrollerWeight)+'px';
			}
			if(!intval(SZN.Dom.getStyle(this.scroller,"top"))) this.scroller.style.top = '0px';
			if(!intval(SZN.Dom.getStyle(this.scroller,"right"))) this.scroller.style.right = '0px';
		}
		this.scroller.style.position = 'absolute';
	}else{
		this.scrollerWeight = 15;
		if(this.type=='h'){
			this.scroller.style.height = this.scrollerWeight+'px';
			this.scroller.style.width = this.parent.wrapper.clientWidth+'px';	
			if(this.parent.vScroll && this.parent.contentOverflowHeight>0) this.scroller.style.width = (this.parent.wrapper.clientWidth-this.parent.vScroll.scrollerWeight)+'px';
			this.scroller.style.bottom = '0px';
			this.scroller.style.left = '0px';	
		}else{
			this.scroller.style.width = this.scrollerWeight+'px';
			this.scroller.style.height = this.parent.wrapper.clientHeight+'px';	
			if(this.parent.hScroll && this.parent.contentOverflowWidth>0) this.scroller.style.height = (this.parent.wrapper.clientHeight-this.parent.hScroll.scrollerWeight)+'px';
			this.scroller.style.top = '0px';
			this.scroller.style.right = '0px';
		}
		this.scroller.style.backgroundColor = '#EFEFEF';
		this.scroller.style.position = 'absolute';
	}
	
	//-- tlačítko posuvníku nahrou (na začátek)
	if(this.scrollerUpCssExists){
		this.scrollerUp.style.display = 'block';
		this.scrollerUp.style.position = 'absolute';
		this.scrollerUp.style.overflow = 'hidden';
		if(this.type=='h'){
			if(isFinite(parseInt(SZN.Dom.getStyle(this.scrollerUp,"width")))) this.scrollerUpWeight = this.scrollerUp.offsetWidth;
			if(!this.scrollerUpWeight) this.scrollerUpWeight = 15;
			if(!intval(SZN.Dom.getStyle(this.scrollerUp,"bottom"))) this.scrollerUp.style.bottom = '0px';
			if(!intval(SZN.Dom.getStyle(this.scrollerUp,"left"))) this.scrollerUp.style.left = '0px';
		}else{
			if(isFinite(parseInt(SZN.Dom.getStyle(this.scrollerUp,"height")))) this.scrollerUpWeight = this.scrollerUp.offsetHeight;
			if(!this.scrollerUpWeight) this.scrollerUpWeight = 15;
			this.scrollerUp.style.top = '0px';
			this.scrollerUp.style.right = '0px';
		}
	}else{
		this.scrollerUpWeight = this.scrollerWeight;
		this.scrollerUp.style.display = 'block';
		this.scrollerUp.style.position = 'absolute';
		if(this.type=='h'){
			this.scrollerUp.style.bottom = '0px';
			this.scrollerUp.style.left = '0px';
			this.scrollerUp.style.height = (this.scrollerWeight-2) +'px';
			this.scrollerUp.style.width = (this.scrollerUpWeight-2) +'px';
		}else{
			this.scrollerUp.style.top = '0px';
			this.scrollerUp.style.right = '0px';
			this.scrollerUp.style.width = (this.scrollerWeight-2) +'px';
			this.scrollerUp.style.height = (this.scrollerUpWeight-2) +'px';		
		}
		this.scrollerUp.style.borderRight = 'solid 1px #a1b1d9';
		this.scrollerUp.style.borderBottom = 'solid 1px #a1b1d9';
		this.scrollerUp.style.borderTop = 'solid 1px #e3e8f3';
		this.scrollerUp.style.borderLeft = 'solid 1px #e3e8f3';
		this.scrollerUp.style.backgroundColor = '#D3DAED';
		this.scrollerUp.style.overflow = 'hidden';		
	}
	
	//-- tlačítko posuvníku dolů (na konec)
	if(this.scrollerDownCssExists){
		this.scrollerDown.style.display = 'block';
		this.scrollerDown.style.position = 'absolute';
		this.scrollerDown.style.overflow = 'hidden';
		if(this.type=='h'){
			if(isFinite(parseInt(SZN.Dom.getStyle(this.scrollerDown,"width")))) this.scrollerDownWeight = this.scrollerDown.offsetWidth;
			if(!this.scrollerDownWeight) this.scrollerDownWeight = 15;
			if(!intval(SZN.Dom.getStyle(this.scrollerDown,"bottom"))) this.scrollerDown.style.bottom = '0px';
			if(!intval(SZN.Dom.getStyle(this.scrollerDown,"right"))) this.scrollerDown.style.right = '0px';
		}else{
			if(isFinite(parseInt(SZN.Dom.getStyle(this.scrollerDown,"height")))) this.scrollerDownWeight = this.scrollerDown.offsetHeight;
			if(!this.scrollerDownWeight) this.scrollerDownWeight = 15;	
			this.scrollerDown.style.bottom = '0px';
			this.scrollerDown.style.right = '0px';
		}
	}else{
		this.scrollerDownWeight = this.scrollerWeight;
		this.scrollerDown.style.display = 'block';
		this.scrollerDown.style.position = 'absolute';
		if(this.type=='h'){
			this.scrollerDown.style.height = (this.scrollerWeight-2) +'px';
			this.scrollerDown.style.width = (this.scrollerDownWeight-2) +'px';
			this.scrollerDown.style.bottom = '0px';
			this.scrollerDown.style.right = '0px';
		}else{
			this.scrollerDown.style.width = (this.scrollerWeight-2) +'px';
			this.scrollerDown.style.height = (this.scrollerDownWeight-2) +'px';		
			this.scrollerDown.style.bottom = '0px';
			this.scrollerDown.style.right = '0px';
		}
		this.scrollerDown.style.borderRight = 'solid 1px #a1b1d9';
		this.scrollerDown.style.borderBottom = 'solid 1px #a1b1d9';
		this.scrollerDown.style.borderTop = 'solid 1px #e3e8f3';
		this.scrollerDown.style.borderLeft = 'solid 1px #e3e8f3';
		this.scrollerDown.style.backgroundColor = '#D3DAED';
		this.scrollerDown.style.overflow = 'hidden';		
	}

	//-- úprava odsazení obsahu při existujícím posuvníku, výpočet prostoru posuvníku
	if(!this.eventsWheelCash) this.eventsWheelCash = SZN.Events.addListener(this.parent.wrapper,"mousewheel",this,"mouseWheel",false);
	if(!this.eventsWheelCash2) this.eventsWheelCash2 = SZN.Events.addListener(this.parent.wrapper,"DOMMouseScroll",this,"mouseWheel",false);
	if(this.type=='h'){
		if(this.parent.contentOverflowWidth > 0){
			if(padding) this.parent.content.style.paddingBottom = (intval(this.parent.content.style.paddingBottom)+this.scrollerWeight)+'px';	
			this.scroller.style.display = 'block';
			this.scrollerExists = true;
		}else{
			this.scroller.style.display = 'none';
			this.scrollerExists = false;
		}

		this.scrollerBarSpace = this.scroller.clientWidth-this.scrollerDownWeight-this.scrollerUpWeight;
		if(this.parent.vScroll && this.parent.contentOverflowHeight>0){
			SZN.Events.removeListener(this.eventsWheelCash);
			this.eventsWheelCash = false;
			SZN.Events.removeListener(this.eventsWheelCash2);
			this.eventsWheelCash2 = false;
		}
	}else{
		if(this.parent.contentOverflowHeight > 0){
			if(padding){
				if(this.parent.hScroll){
					this.parent.content.style.paddingRight = (intval(this.parent.content.style.paddingRight)+this.scrollerWeight)+'px';		
				}else{
					this.parent.content.style.width = (this.parent.getWidth(this.parent.wrapper)-this.scrollerWeight)+'px';
				}
			}
			this.scroller.style.display = 'block';
			this.scrollerExists = true;
		}else{		
			this.scroller.style.display = 'none';
			this.scrollerExists = false;
		}
		this.scrollerBarSpace = this.scroller.clientHeight-this.scrollerDownWeight-this.scrollerUpWeight;
	}
	
	//-- paramentry posuvnik
	
	if(this.scrollerBarCssExists){
		this.scrollerBar.style.position = 'absolute';
		if(this.type=='h'){
			if(isFinite(parseInt(SZN.Dom.getStyle(this.scrollerBar,"width")))) this.scrollerBarWeight = this.scrollerBar.offsetWidth;
			if(!this.scrollerBarWeight){
				this.scrollerBarWeight = intval(this.scrollerBarSpace*0.3);
				if(this.scrollerBarWeight<5) this.scrollerBarWeight = 5;
			}
			if(!intval(SZN.Dom.getStyle(this.scrollerBar,"bottom"))) this.scrollerBar.style.bottom = '0px';
			this.scrollerBar.style.left = this.scrollerUpWeight +'px';
			this.scrollerBar.style.width = this.scrollerBarWeight+'px';	
			if(!intval(SZN.Dom.getStyle(this.scrollerBar,"height"))) this.scrollerBar.style.height = this.scrollerWeight+'px';
			
		}else{
			if(isFinite(parseInt(SZN.Dom.getStyle(this.scrollerBar,"height")))) this.scrollerBarWeight = this.scrollerBar.offsetHeight;
			if(!this.scrollerBarWeight){
				this.scrollerBarWeight = intval(this.scrollerBarSpace*0.3);
				if(this.scrollerBarWeight<5) this.scrollerBarWeight = 5;
			}
			this.scrollerBar.style.top = this.scrollerUpWeight +'px';
			this.scrollerBar.style.right = '0px';
			this.scrollerBar.style.height = this.scrollerBarWeight+'px';
			if(!intval(SZN.Dom.getStyle(this.scrollerBar,"width"))) this.scrollerBar.style.width = this.scrollerWeight+'px';	
		}
	}else{
	
		this.scrollerBarWeight = intval(this.scrollerBarSpace*0.3);
		if(this.scrollerBarWeight<5) this.scrollerBarWeight = 5;
		this.scrollerBar.style.display = 'block';
		this.scrollerBar.style.position = 'absolute';
		if(this.type=='h'){
			this.scrollerBar.style.bottom = '0px';
			this.scrollerBar.style.left = this.scrollerUpWeight +'px';
			this.scrollerBar.style.width = (this.scrollerBarWeight-2) +'px';
			this.scrollerBar.style.height = (this.scrollerWeight-2) +'px';
		}else{
			this.scrollerBar.style.top = this.scrollerUpWeight +'px';
			this.scrollerBar.style.right = '0px';
			this.scrollerBar.style.width = (this.scrollerWeight-2) +'px';
			this.scrollerBar.style.height = (this.scrollerBarWeight-2) +'px';		
		}
		this.scrollerBar.style.borderRight = 'solid 1px #a1b1d9';
		this.scrollerBar.style.borderBottom = 'solid 1px #a1b1d9';
		this.scrollerBar.style.borderTop = 'solid 1px #e3e8f3';
		this.scrollerBar.style.borderLeft = 'solid 1px #e3e8f3';
		this.scrollerBar.style.backgroundColor = '#D3DAED';	
	}
	
	//document.styleSheets[0].disabled=true;
	//document.styleSheets[0].disabled=false;
	//SZN.Dom.removeClass(this.scrollerBar, "scrollerbar");
	//SZN.Dom.addClass(this.scrollerBar,"scrollerbar");
}

SZN.Scrollbar.prototype.setScrollerBar = function() {
	if(this.type=='h'){
		
		var min = this.scrollerUpWeight;
		var max = this.scrollerBarSpace+this.scrollerUpWeight-this.scrollerBarWeight;
		this.scrollerBarPos = min;
		if(this.parent.contentLeft!=0){
			this.scrollerBarPos = (Math.abs((this.parent.contentLeft/this.parent.contentOverflowWidth)*(this.scrollerBarSpace-this.scrollerBarWeight))+this.scrollerUpWeight);
			if(this.scrollerBarPos <min) this.scrollerBarPos = min;
			if(this.scrollerBarPos > max) this.scrollerBarPos = max;
		}
		this.scrollerBar.style.left = this.scrollerBarPos+'px';		
	}else{
		var min = this.scrollerUpWeight;
		var max = this.scrollerBarSpace+this.scrollerUpWeight-this.scrollerBarWeight;
		this.scrollerBarPos = min;
		if(this.parent.contentTop!=0){
			this.scrollerBarPos = (Math.abs((this.parent.contentTop/this.parent.contentOverflowHeight)*(this.scrollerBarSpace-this.scrollerBarWeight))+this.scrollerUpWeight);
			if(this.scrollerBarPos <min) this.scrollerBarPos = min;
			if(this.scrollerBarPos > max) this.scrollerBarPos = max;
		}
		this.scrollerBar.style.top = this.scrollerBarPos+'px';		
	}
}

SZN.Scrollbar.prototype.mouseWheel = function(e,elm) {
	SZN.Events.cancelDef(e);
	delta=false;
	if (!e){ e = window.event; }
	if (e.wheelDelta){
		delta = e.wheelDelta/120;
		//if (window.opera) { delta = -delta; }
	}else if (e.detail) { delta = -e.detail/3; }

	if(delta!=false) this.scrollstep(delta*this.wheelMulti);
	SZN.Events.stopEvent(e);
}
SZN.Scrollbar.prototype.scrollUp = function(e,elm) {
	SZN.Events.cancelDef(e);
	this.scrollstep(1);
	SZN.Events.stopEvent(e);
}
SZN.Scrollbar.prototype.scrollDown = function(e,elm) {
	
	SZN.Events.cancelDef(e);
	this.scrollstep(-1);
	SZN.Events.stopEvent(e);
}
SZN.Scrollbar.prototype.scroll = function(e,elm) {
	
	if(elm.id == this.scrollerUp.id) this.scrollUp(e,elm);
	else this.scrollDown(e,elm);
}
SZN.Scrollbar.prototype.autoscroll = function(e,elm) {
	SZN.Events.cancelDef(e);
	var direction = (-1);
	if(elm.id == this.scrollerUp.id) direction = 1;
	
	if(!this.moveInterval){ 
		//var scrollstep = SZN.bind(this,this.scrollstep);
		var mThis = this;
		this.moveInterval = setTimeout(function(){ mThis.moveInterval = setInterval(function(){ mThis.scrollstep(direction);},50) },500);
	}
	SZN.Events.stopEvent(e);
}
SZN.Scrollbar.prototype.autoscrollStop = function(e,elm) {
	//SZN.Events.cancelDef(e);
	if(this.moveInterval) clearInterval(this.moveInterval);
	this.moveInterval = false;
}
SZN.Scrollbar.prototype.scrollstep = function(direction) {
	if(this.type=='h') this.parent.setLeft(this.parent.contentLeft+(this.stepSize*direction));
	else this.parent.setTop(this.parent.contentTop+(this.stepSize*direction));
	this.setScrollerBar();
}

SZN.Scrollbar.prototype.barJump = function(e,elm) {
	SZN.Events.cancelDef(e);
	var direction = (-1);
	var pos = SZN.Dom.getFullBoxPosition(this.scrollerBar);
	if(this.type=='h'){
		if(pos.left > e.clientX) var direction = 1;
	}else{
		if(pos.top > e.clientY) var direction = 1;
	}
	this.scrollstep(direction*this.barMulti);
	SZN.Events.stopEvent(e);
}
SZN.Scrollbar.prototype.barDrop = function(e,elm) {
	SZN.Events.cancelDef(e);
	this.scrollerDrag = false;
	SZN.Events.stopEvent(e);
}
SZN.Scrollbar.prototype.barDrag = function(e,elm) {
	SZN.Events.cancelDef(e);
	this.scrollerDrag = true;
	var pos = SZN.Dom.getFullBoxPosition(this.scrollerBar);
	if(this.type=='h') this.scrollerBarDragPos =  intval(e.clientX-pos.left);
	else this.scrollerBarDragPos = intval(e.clientY-pos.top);
	if(this.scrollerBarDragPos<0 || this.scrollerBarDragPos>this.scrollerBarWeight) this.scrollerBarDragPos=intval(this.scrollerBarWeight/2);
	SZN.Events.stopEvent(e);
}
SZN.Scrollbar.prototype.barMove = function(e,elm) {
	//SZN.Events.cancelDef(e);
	if(this.scrollerDrag){
		var pos = SZN.Dom.getFullBoxPosition(this.scroller);
		if(this.type=='h'){
			var left = intval(((e.clientX-pos.left-this.scrollerUpWeight-this.scrollerBarDragPos))/(this.scrollerBarSpace-this.scrollerBarWeight)*this.parent.contentOverflowWidth)*(-1);
			this.parent.setLeft(left);
		}else{
			var top = intval(((e.clientY-pos.top-this.scrollerUpWeight-this.scrollerBarDragPos))/(this.scrollerBarSpace-this.scrollerBarWeight)*this.parent.contentOverflowHeight)*(-1);
			this.parent.setTop(top);			
		}
		this.setScrollerBar();
	}
	SZN.Events.stopEvent(e);
}


SZN.Scroll = SZN.ClassMaker.makeClass({
	NAME: "Scroll",
	VERSION: "1.0",
	CLASS: "class"
});

SZN.Scroll.prototype.$constructor = function(id,hScroll,vScroll) {
	this.debug("SZN.Scroll: Založen pro element ID "+id);
	this.eventsCache = [];
	this.moveInterval = false;
	this.isWake = true;
	
	this.content = false;
	this.contentTop = 0;
	this.contentLeft = 0;
	this.contentOverflowHeight = 0;
	this.contentOverflowWidth = 0;
	
	this.wrapper = false;
	this.vScroll = false;
	this.hScroll = false;
	
	this.element = SZN.gEl(id);
	if(!this.element){
		this.debug("SZN.Scroll: Nepodařilo se získat dom pro element ID "+id);
		return false;
	}
	this.wrapper = this.element.cloneNode(true);
	this.wrapper.style.display = 'block';
	this.wrapper.style.overflow = 'hidden';
	if(!this.wrapper.style.position || this.wrapper.style.position=='static') this.wrapper.style.position = 'relative';
	this.content = SZN.cEl('DIV',this.wrapper.id+'Content','');
	this.content.innerHTML = this.wrapper.innerHTML;
	SZN.Dom.clear(this.wrapper);
	SZN.Dom.append(Array(this.wrapper,this.content));
	this.element.parentNode.replaceChild(this.wrapper, this.element);
	
	//this.wrapper.innerHTML = SZN.bind(this,"innerHTML");
	//this.debug(this.wrapper.offsetHeight+' vs '+this.wrapper.clientHeight);
	
	if(vScroll!=false) this.vScroll = new SZN.Scrollbar(this,'v');
	if(hScroll){
		this.hScroll = new SZN.Scrollbar(this,'h');
		//this.debug("h");
	}
	
	this.eventsCache.push(SZN.Events.addListener(window,"unload",this,"$destructor",false));
	this.eventsCache.push(SZN.Events.addListener(window,"resize",this,"resize",false));
	this.eventsCache.push(SZN.Events.addListener(this.wrapper,"resize",this,"resize",false));
	
	this.reset();
}
SZN.Scroll.prototype.innerHTML = function(html) {
	this.content.innerHTML = html;
	this.reset();
}
SZN.Scroll.prototype.$destructor = function() {
	for (var i=0;i<this.eventsCache.length;i++) {
		SZN.Events.removeListener(this.eventsCache[i]);
	}
	for (var p in this) { this[p] = null; }
}
SZN.Scroll.prototype.wake = function() {
	if(!this.isWake){
		this.element.parentNode.replaceChild(this.wrapper, this.element);
		this.isWake = true;
		this.reset();
	}
}
SZN.Scroll.prototype.sleep = function() {
	if(this.isWake) {
		this.wrapper.parentNode.replaceChild(this.element,this.wrapper);
		this.isWake = false;
	}
}
SZN.Scroll.prototype.end = function() {
	if(this.isWake) this.wrapper.parentNode.replaceChild(this.element,this.wrapper);
	this.$destructor();
}
SZN.Scroll.prototype.resize = function(e,elm) {
	this.reset();
}
SZN.Scroll.prototype.getWidth = function(elm) {
	if(elm){
		var width = elm.clientWidth;
		if(elm.style.paddingLeft) width -= intval(elm.style.paddingLeft);
		if(elm.style.paddingRight) width -= intval(elm.style.paddingRight);
		//this.debug(elm.style.paddingLeft);
		//this.debug(elm.style.paddingRight);
		//this.debug(width+' versus '+elm.clientWidth+' ofset'+elm.offsetWidth);
		return width;
	}else return 0;
}
SZN.Scroll.prototype.getHeight = function(elm) {
	if(elm){
		var height = elm.clientHeight;
		if(elm.style.paddingTop) height -= intval(elm.style.paddingTop);
		if(elm.style.paddingBottom) height -= intval(elm.style.paddingBottom);
		return height;
	}else return 0;
}
SZN.Scroll.prototype.reset = function() {
	
	if(this.hScroll){
		this.content.style.whiteSpace = 'nowrap';
		this.wrapper.style.height = this.getHeight(this.wrapper)+'px';
	}else{
		this.content.style.whiteSpace = '';
		this.content.style.width = this.getWidth(this.wrapper)+'px';
		this.wrapper.style.height = this.getHeight(this.wrapper)+'px';
	}
	this.content.style.paddingLeft = this.wrapper.style.paddingLeft;
	this.content.style.paddingRight = this.wrapper.style.paddingRight;
	this.content.style.paddingTop = this.wrapper.style.paddingTop;
	this.content.style.paddingBottom = this.wrapper.style.paddingBottom;
	this.content.style.position = 'absolute';
	this.setTop(0);
	this.setLeft(0);
	
	this.countOverflow();	
	
	//-- tohle by chtelo vyresit lepe
	if(this.hScroll){
		
		this.hScroll.reset(true);
		this.countOverflow();
		if(this.vScroll) {
			this.vScroll.reset(true);
			this.countOverflow();
		}
		this.hScroll.reset();
		this.countOverflow();
		
	}else if(this.vScroll) {
		this.vScroll.reset(true);
		this.countOverflow();	
	}

	
}
SZN.Scroll.prototype.countOverflow = function() {
	this.contentOverflowHeight = (this.content.offsetHeight-this.wrapper.clientHeight);
	this.contentOverflowWidth = (this.content.offsetWidth-this.wrapper.clientWidth);
	//this.debug('overflow h: '+this.contentOverflowHeight+', content.offsetHeight: '+this.content.offsetHeight+', wrapper.offsetHeight: '+this.wrapper.offsetHeight);
	//this.debug('overflow w: '+this.contentOverflowWidth+', content.offfsetWidth: '+this.content.offsetWidth+', wrapper.offfsetWidth: '+this.wrapper.offsetWidth);
}
SZN.Scroll.prototype.setTop = function(top) {
	this.contentTop = intval(top);
	if(this.contentTop < (-this.contentOverflowHeight)){
		this.contentTop = (-this.contentOverflowHeight);
	}
	if(this.contentTop > 0) this.contentTop = 0;
	this.content.style.top = this.contentTop+'px';
}
SZN.Scroll.prototype.setLeft = function(left) {
	this.contentLeft = intval(left);
	if(this.contentLeft < (-this.contentOverflowWidth)){
		this.contentLeft = (-this.contentOverflowWidth);
	}
	if(this.contentLeft > 0) this.contentLeft = 0;
	this.content.style.left = this.contentLeft+'px';
}


SZN.Scroll.prototype.debug = function(message) {
	/*
	if(SZN.Browser.client!='ie'){
		if(console) console.log(message);
	}
	*/
}
function intval(number,base){
	number = parseInt(number,base);
	if(isFinite(number)) return number;
	else return 0;
}
SZN.getComputedStyle = function(elm){
	if(elm.currentStyle) return elm.currentStyle;
	else return window.getComputedStyle(elm,null);
}


