
var h, d;

// returns array of sheet object, rule object, and rule index
function findCssRule(selectorText) {
  var rules, sheets = document.styleSheets;
  var r, rlen, s, slen = sheets.length;
  for(s=0; s<slen; ++s) {
    rules = (sheets[s].rules) ? sheets[s].rules : sheets[s].cssRules;
    rlen = rules.length;
    for(r=0; r<rlen; ++r) {
      if(rules[r].selectorText == selectorText) {
        return [sheets[s], rules[r], r];
      }
    }
  }
  return null;
}

jQuery.noConflict();
duration = 6000;

jQuery(document).ready(function(){

//	number of children
	n = document.getElementById("customfield").getElementsByTagName('li').length;
//	visible height
	d = 200;
//	margin between children
	m = 2;
//	height of each child
	h = 20 + m;
//	the height of the entire object
	nh = (n*h*-1) + d - h + m;

	
//	rest point when scrolling down
//	this doesn't work as some items are two line heights
//	stop_bottom = nh-2.5*h
	stop_bottom = parseInt(document.getElementById('customfield').clientHeight) * -1 + d - h + m;
	stop_top = h;
//	alert(stop_bottom + " " + stop_bottom_new);
//	if ( jQuery.browser.msie )
//		nh -= 2;
	
	jQuery("#customfield_down").hover(
		function(){
		//	onmouseover
			t = parseInt(document.getElementById('customfield').style.top);
			if ( isNaN(t) )
				t = 0;
				
			if ( t <= stop_bottom ) {
				jQuery("#customfield").stop();
				document.getElementById('customfield').style.top = stop_bottom + "px";
				return;
			}
		
//	where are we in the animation ? we are at t
//	how far do we need to go ? we need to go to stop_bottom
//				top: "-=1000px"
//	our duration needs to be equivalent to `duration' over 1000px
			
			custom_duration = parseInt((-stop_bottom + t)/1000 * duration);

			jQuery("#customfield").animate({ 
				top: stop_bottom + "px"
			}, custom_duration, "linear" )
		},
		function(){
		//	onmouseout
			jQuery("#customfield").stop()

			t = document.parseInt(getElementById('customfield').style.top);
			if ( parseInt(t) < stop_bottom ) {
				document.getElementById('customfield').style.top = stop_bottom + "px";
				return;
			}
		}
	);

	jQuery("#customfield_up").hover(
		function(){
		//	onmouseover
			t = parseInt(document.getElementById('customfield').style.top);
			if ( isNaN(t) )
				t = 0;

			if ( t >= stop_top ) {
				jQuery("#customfield").stop();
				return;
			}
			
			custom_duration = parseInt(-t/1000 * duration);

			jQuery("#customfield").animate({ 
				top: stop_top + "px"
			}, custom_duration, "linear" )
		},
		function(){
		//	onmouseout
			jQuery("#customfield").stop();
			
			t = document.getElementById('customfield').style.top;
			if ( t > stop_top ) {
				document.getElementById('customfield').style.top = stop_top + "px";
			}
		}
	);
});


function show_active_in_sidebar(id, style) {
//	alert(style);
	h = 22;
	d = 200;
	m = 2;
	
	stop_bottom = parseInt(document.getElementById(id).clientHeight) * -1 + d - h + m;

	nodes = document.getElementById(id).getElementsByTagName('li');
	for ( i = 0; i < nodes.length; i++ ) {
		if ( nodes[i].className == style ) {
			new_t = -h*i + d/2;
			if ( new_t < stop_bottom )
				new_t = stop_bottom;
			else if ( new_t > h )
				new_t = h;

			document.getElementById(id).style.top = new_t + 'px';
			break;
		}
	}
}