// calculating height set of elements, parent - jquery obj, elm - class or tag
function calc_height(parent, elm)
{
	var h = 0;
	$(elm, parent).each(function()
		{
			var mt = 0, pt = 0, mb = 0, pb = 0, bt = 0, bb = 0;
			mt = (isNaN(parseInt($(this).css("marginTop")))) ? 0 : parseInt($(this).css("marginTop"));
			pt = (isNaN(parseInt($(this).css("paddingTop")))) ? 0 : parseInt($(this).css("paddingTop"));
			mb = (isNaN(parseInt($(this).css("marginBottom")))) ? 0 : parseInt($(this).css("marginBottom"));
			pb = (isNaN(parseInt($(this).css("paddingBottom")))) ? 0 : parseInt($(this).css("paddingBottom"));
			bt = (isNaN(parseInt($(this).css("borderTopWidth")))) ? 0 : parseInt($(this).css("borderTopWidth"));
			bb = (isNaN(parseInt($(this).css("borderBottomWidth")))) ? 0 : parseInt($(this).css("borderBottomWidth"));
			h += $(this).height() + mt + mb + pt + pb + bt + bb;
		}
	);
	return h;
}
// artificial vertical scroll init, all jquery objects, except a_cont
function init_art_vscroll(a_list, a_elm, a_scroll, a_bar, a_cont)
{
	a_list.scrollTop(0);
	a_list.css({overflowY: "hidden"});
	if (a_elm.length > 0)
	{
		var b_h = a_list.height();
		var tli_h = calc_height(a_list, ".li");
		if (b_h < tli_h)
		{
			a_scroll.show();
			a_bar.draggable({axis: 'y', containment: a_cont});
			a_bar.bind("drag", {list_height: tli_h, b_h: b_h}, function(e, ui)
				{
					var cont_height = e.data.b_h;
					var list_height = e.data.list_height;
					var cus_scroll = a_scroll.height() - a_bar.height();
					//var scroll_coef1 = (list_height - cont_height) / cus_scroll + ((list_height - cont_height) * .035 / cus_scroll);
					var scroll_coef1 = (list_height - cont_height) / cus_scroll;
					a_list.scrollTop(ui.position.top * scroll_coef1);
				}
			);
			// hover scroll
			a_list.hover(
				function()
				{
					var p = $(this);
					$(window).everyTime(40, "navd", function()
						{
							var cursc = p.scrollTop();
							p.scrollTop(cursc + 1);
							var cus_scroll = a_scroll.height() - a_bar.height();
							//var scroll_coef = (tli_h - b_h) / cus_scroll + ((tli_h - b_h) * .035 / cus_scroll);
							var scroll_coef = (tli_h - b_h) / cus_scroll;
							a_bar.css({top: (cursc + 1)/scroll_coef});
						}
					);
				},
				function()
				{
					$(window).stopTime("navd");
				}
			);
		}
	}
	return;
}
// main definitions
$(document).ready(function(){
	// init
	// news at left artificial scroll init
	init_art_vscroll($(".blck_twitter .list"), $(".blck_twitter .list .li"), $(".blck_twitter .scroll"), $(".blck_twitter .bar"), ".blck_twitter .scroll");
	// definitions
	// common events
});
