// Copyright Enzon, 2009
// design by Enzon.cz [http://www.enzon.cz]
var sTimer=false;

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.scrollerId+' '+this.type+'Scroller');
	this.scrollerUp = SZN.cEl('DIV',this.scrollerUpId,this.scrollerUpId+' '+this.type+'ScrollerUp');
	this.scrollerDown = SZN.cEl('DIV',this.scrollerDownId,this.scrollerDownId+' '+this.type+'ScrollerDown');
	this.scrollerBar = SZN.cEl('DIV',this.scrollerBarId,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));
	
	if(SZN.Browser.client=='ie'){
		document.styleSheets[0].addRule('div.'+this.scrollerId,' ',0);
		this.scrollerCss = document.styleSheets[0].rules[0].style;
		
		document.styleSheets[0].addRule('div.'+this.scrollerUpId,' ',0);
		this.scrollerUpCss = document.styleSheets[0].rules[0].style;	
		document.styleSheets[0].addRule('div.'+this.scrollerUpId+':hover','background: #a9bdf1;',0);
		
		document.styleSheets[0].addRule('div.'+this.scrollerDownId,' ',0);
		this.scrollerDownCss = document.styleSheets[0].rules[0].style;
		document.styleSheets[0].addRule('div.'+this.scrollerDownId+':hover','background: #a9bdf1;',0);
		
		document.styleSheets[0].addRule('div.'+this.scrollerBarId,' ',0);
		this.scrollerBarCss = document.styleSheets[0].rules[0].style;
		document.styleSheets[0].addRule('div.'+this.scrollerBarId+':hover','background: #a9bdf1;',0);
		
	}else{

		document.styleSheets[0].insertRule('div.'+this.scrollerId+'{  }',0);
		this.scrollerCss = document.styleSheets[0].cssRules[0].style;

		document.styleSheets[0].insertRule('div.'+this.scrollerUpId+'{  }',0);
		this.scrollerUpCss = document.styleSheets[0].cssRules[0].style;	
		document.styleSheets[0].insertRule('div.'+this.scrollerUpId+':hover{ background: #a9bdf1; }',0);
		
		document.styleSheets[0].insertRule('div.'+this.scrollerDownId+'{  }',0);
		this.scrollerDownCss = document.styleSheets[0].cssRules[0].style;
		document.styleSheets[0].insertRule('div.'+this.scrollerDownId+':hover{ background: #a9bdf1; }',0);

		document.styleSheets[0].insertRule('div.'+this.scrollerBarId+'{  }',0);
		this.scrollerBarCss = document.styleSheets[0].cssRules[0].style;
		document.styleSheets[0].insertRule('div.'+this.scrollerBarId+':hover{ background: #a9bdf1; }',0);		
	}
	
	
	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));	

}

SZN.Scrollbar.prototype.hoverOver = function(e,elm) {

}
SZN.Scrollbar.prototype.hoverOut = function(e,elm) {

}
SZN.Scrollbar.prototype.debug = function(message) {
	this.parent.debug(message);
}
SZN.Scrollbar.prototype.reset = function(padding) {
	
	//-- plocha posuvníku
	if(this.type=='h'){
		this.scrollerCss.height = '15px';
		this.scrollerCss.width = this.parent.wrapper.clientWidth+'px';
		if(this.parent.vScroll && this.parent.contentOverflowHeight>0){
			this.scrollerCss.width = (this.parent.wrapper.clientWidth-this.parent.vScroll.scrollerWeight)+'px';
		}
		this.scrollerCss.bottom = '0px';
		this.scrollerCss.left = '0px';
		
		if(!isNaN(parseInt(SZN.Dom.getStyle(this.scroller,"height")))) this.scrollerWeight = this.scroller.offsetHeight;
		if(!this.scrollerWeight) this.scrollerWeight = 15;

	}else{
		this.scrollerCss.width = '15px';
		this.scrollerCss.height = this.parent.wrapper.clientHeight+'px';	
		if(this.parent.hScroll && this.parent.contentOverflowWidth>0) this.scrollerCss.height = (this.parent.wrapper.clientHeight-this.parent.hScroll.scrollerWeight)+'px';
		this.scrollerCss.top = '0px';
		this.scrollerCss.right = '0px';
		
		if(!isNaN(parseInt(SZN.Dom.getStyle(this.scroller,"width")))) this.scrollerWeight = this.scroller.offsetWidth;
		if(!this.scrollerWeight) this.scrollerWeight = 15;
	}
	this.scrollerCss.backgroundColor = '#EFEFEF';
	this.scrollerCss.position = 'absolute';


	
	//-- tlačítko posuvníku nahrou (na začátek)
	this.scrollerUpCss.display = 'block';
	this.scrollerUpCss.position = 'absolute';
	this.scrollerUpCss.borderRight = 'solid 1px #a1b1d9';
	this.scrollerUpCss.borderBottom = 'solid 1px #a1b1d9';
	this.scrollerUpCss.borderTop = 'solid 1px #e3e8f3';
	this.scrollerUpCss.borderLeft = 'solid 1px #e3e8f3';
	this.scrollerUpCss.backgroundColor = '#D3DAED';
	this.scrollerUpCss.overflow = 'hidden';
	if(this.type=='h'){
		this.scrollerUpCss.bottom = '0px';
		this.scrollerUpCss.left = '0px';
		this.scrollerUpCss.height = (this.scrollerWeight-2) +'px';
		this.scrollerUpCss.width = (this.scrollerWeight-2) +'px';
		if(!isNaN(parseInt(SZN.Dom.getStyle(this.scrollerUp,"width")))) this.scrollerUpWeight = this.scrollerUp.offsetWidth;
		if(!this.scrollerUpWeight) this.scrollerUpWeight = 15;
	}else{
		this.scrollerUpCss.top = '0px';
		this.scrollerUpCss.right = '0px';
		this.scrollerUpCss.width = (this.scrollerWeight-2) +'px';
		this.scrollerUpCss.height = (this.scrollerWeight-2) +'px';
		if(!isNaN(parseInt(SZN.Dom.getStyle(this.scrollerUp,"height")))) this.scrollerUpWeight = this.scrollerUp.offsetHeight;
		if(!this.scrollerUpWeight) this.scrollerUpWeight = 15;		
	}


	
	
	//-- tlačítko posuvníku dolů (na konec)
	this.scrollerDownWeight = this.scrollerWeight;
	this.scrollerDownCss.display = 'block';
	this.scrollerDownCss.position = 'absolute';
	this.scrollerDownCss.borderRight = 'solid 1px #a1b1d9';
	this.scrollerDownCss.borderBottom = 'solid 1px #a1b1d9';
	this.scrollerDownCss.borderTop = 'solid 1px #e3e8f3';
	this.scrollerDownCss.borderLeft = 'solid 1px #e3e8f3';
	this.scrollerDownCss.backgroundColor = '#D3DAED';
	this.scrollerDownCss.overflow = 'hidden';
	if(this.type=='h'){
		this.scrollerDownCss.height = (this.scrollerWeight-2) +'px';
		this.scrollerDownCss.width = (this.scrollerWeight-2) +'px';
		this.scrollerDownCss.bottom = '0px';
		this.scrollerDownCss.right = '0px';
		if(!isNaN(parseInt(SZN.Dom.getStyle(this.scrollerDown,"width")))) this.scrollerDownWeight = this.scrollerDown.offsetWidth;
		if(!this.scrollerDownWeight) this.scrollerDownWeight = 15;
	}else{
		this.scrollerDownCss.width = (this.scrollerWeight-2) +'px';
		this.scrollerDownCss.height = (this.scrollerWeight-2) +'px';
		this.scrollerDownCss.bottom = '0px';
		this.scrollerDownCss.right = '0px';
		if(!isNaN(parseInt(SZN.Dom.getStyle(this.scrollerDown,"height")))) this.scrollerDownWeight = this.scrollerDown.offsetHeight;
		if(!this.scrollerDownWeight) this.scrollerDownWeight = 15;
	}

	

	//-- ú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;
	}
	
	//-- plovák :)
	this.scrollerBarWeight = intval(this.scrollerBarSpace*0.3);
	if(this.scrollerBarWeight<5) this.scrollerBarWeight = 5;
	this.scrollerBarCss.display = 'block';
	this.scrollerBarCss.position = 'absolute';
	this.scrollerBarCss.borderRight = 'solid 1px #a1b1d9';
	this.scrollerBarCss.borderBottom = 'solid 1px #a1b1d9';
	this.scrollerBarCss.borderTop = 'solid 1px #e3e8f3';
	this.scrollerBarCss.borderLeft = 'solid 1px #e3e8f3';
	this.scrollerBarCss.backgroundColor = '#D3DAED';
	if(this.type=='h'){
		this.scrollerBarCss.bottom = '0px';
		this.scrollerBarCss.left = this.scrollerUpWeight +'px';
		this.scrollerBarCss.width = (this.scrollerBarWeight-2) +'px';
		this.scrollerBarCss.height = (this.scrollerWeight-2) +'px';
	}else{
		this.scrollerBarCss.top = this.scrollerUpWeight +'px';
		this.scrollerBarCss.right = '0px';
		this.scrollerBarCss.width = (this.scrollerWeight-2) +'px';
		this.scrollerBarCss.height = (this.scrollerBarWeight-2) +'px';		
	}

}

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(intval(SZN.Dom.getStyle(elm,"paddingLeft"))) width -= intval(SZN.Dom.getStyle(elm,"paddingLeft"));
		if(intval(SZN.Dom.getStyle(elm,"paddingRight"))) width -= intval(SZN.Dom.getStyle(elm,"paddingRight"));
		return width;
	}else return 0;
}
SZN.Scroll.prototype.getHeight = function(elm) {
	if(elm){
		var height = elm.clientHeight;
		if(intval(SZN.Dom.getStyle(elm,"paddingTop"))) height -= intval(SZN.Dom.getStyle(elm,"paddingTop"));
		if(intval(SZN.Dom.getStyle(elm,"paddingBottom"))) height -= intval(SZN.Dom.getStyle(elm,"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'; //pokud neni urcena vyska prvku nutno povolit.
	}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 = SZN.Dom.getStyle(this.wrapper,"paddingLeft");
	this.content.style.paddingRight = SZN.Dom.getStyle(this.wrapper,"paddingRight");
	this.content.style.paddingTop = SZN.Dom.getStyle(this.wrapper,"paddingTop");
	this.content.style.paddingBottom = SZN.Dom.getStyle(this.wrapper,"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.hide = function() {
	
	if(this.hScroll) this.hScroll.scroller.style.display='none';
	if(this.vScroll) this.vScroll.scroller.style.display='none';
	
}

SZN.Scroll.prototype.debug = function(message) {
	
	if(typeof console != "undefined") console.log(message);
	
}
function intval(number,base){
	number = parseInt(number,base);
	if(isFinite(number)) return number;
	else return 0;
}

