

// 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 + 2;

	
//	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 slide_list(id, show, direction) {

//	this has been pretty much replaced by
//	jQuery("#customfield_down").hover(

	return;
	node = document.getElementById(id);
	elements = node.getElementsByTagName('li');
	count = 0;
	show = parseInt(show) - 1;
//	alert(id);
	
	if ( ! node.offset ) 
		node.offset = 0;
	node.offset -= show * direction;

	if ( node.offset > elements.length - show )
		node.offset =  elements.length - show - 1;
	else if ( node.offset < 0 ) node.offset = 0;
	
	last = (parseInt(node.offset) + parseInt(show))
//	alert(0)
	for ( i = 0; i < elements.length; i++ ) {
//		alert("0." + i)
//		alert(elements[i].style.display)
//		if ( ! elements[i].style.display ) 
	//		next;
			
		if ( i < node.offset || i > last )
			elements[i].style.display = 'none';
		else
			elements[i].style.display = '';
//	internet explorer doesnt understand inherit
//			elements[i].style.display = 'inherit';
	}
//	alert(10)
	up = document.getElementById(id + "_up");
	down = document.getElementById(id + "_down");
	
	if ( node.offset == 0 )
		up.setAttribute('class', id + '_off');
	else
		up.setAttribute('class', id + '_on');
	
	if ( last >= elements.length - 1 )
		down.setAttribute('class', id + '_off');
	else
		down.setAttribute('class', id + '_on');	
}


function slide_list_OLD(id, direction) {
	node = document.getElementById(id);
	height = parseInt(node.style.height);
	if ( ! height ) {
		rule = findCssRule("ul." + id);
	//height = rule.style.height;
		height = parseInt(rule[1].style.height);
		if ( height )
			node.style.height = height;
	}
	
	if ( height ) alert(height);
	node.style.height = 'auto';
//	if ( node.style.clip ) {
		alert('clipped');
//	} else {
		if ( node.top )	node.top += height;
		else node.top = height;
		
		node.height = parseInt(node.top) + parseInt(height);
		
		alert(node.height)
		
		node.style.clip = "rect(" + node.top + "px auto auto auto)";
	
	alert(node.style.clip)
}


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;
		}
	}
}
