var last = 0;
var where = 0;
var timer;
var by;
var sheight = document.documentElement.scrollHeight;
var kolik=230;
var vyska=600;

function posun() {

	if ((sheight-kolik-vyska)>=where) {

		sb.style.top = 	last+"px";
		if (last>where) {
			minus = -1;
		} else {
			minus = 1;
		}
		if ((last<where) || (last>where && minus==-1)) {
			last = last + 5*minus;
			if ((where-last)*minus>40) last = last + 15*minus;
			if ((where-last)*minus>160) last = last + 40*minus;
		}

	}

}

function stickyBar() {

	sheight = document.documentElement.scrollHeight;
	kolik=230;
	vyska=600;
	var top = document.body.scrollTop;
	if (top == 0) {
		if (window.pageYOffset) {
			top = window.pageYOffset;
		} else {
			top = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
		}
	}
	wherelast=where;
	if (top>kolik) {
		where = (top-kolik);		
		while (where%5!=0) {
				where++;
		}						
	} else {
		where = 0;						
	}						
	
}

$(document).ready(function(){

	if ($("#stickyBar").length!=0) {
				
		var sb = document.getElementById("sticky_bar");
		SBtimer=setInterval('posun()',10);
		
	}
	
});


