function scroll( _id, _dir ){
	var e = ge( _id );
	var offset = 5;
	if( e ) {
		var t = parseInt( e.style.top, 10 );
		if( isNaN( t ) ) t = 0;
		var ep = e.parentNode;
		if( ep.clientHeight < e.clientHeight ) {
			if( _dir == 'up' ) {
				var nt = e.parentNode.clientHeight - t;
				if( ( nt + offset ) > ( e.scrollHeight - ep.scrollTop ) ) offset = ( e.scrollHeight - ep.scrollTop ) - nt;			
				e.style.top = ( t - offset ) + 'px';
			}
			if( _dir == 'down' ) {
				var nt = 0 - t;
				if( ( nt - offset ) < ( -ep.scrollTop ) ) offset = 0;	
				e.style.top = ( t + offset ) + 'px';
			}		
			timers[ _id ] = setTimeout( "scroll( '" + _id + "', '" + _dir + "' )", 100 );
		}
	}
}

function resetScroll( _id ) {
	var l = ge( _id );
	l.style.top = '0px';
}

function moveUp( _id, _to ) {
	var l = ge( _id );
	var t = parseInt( l.style.top, 10 );
	if( isNaN( t ) ) t = 0;
	t -= 2;
	if( t > _to ) {
		l.style.top = t + 'px';
		setTimeout( "moveUp( '" + _id + "', '" + _to + "' )", 100 );
	}
}

var timers = [];
function startScroll( _id, _dir ) {
	scroll( _id, _dir );
}

function stopScroll( _id ) {
	clearTimeout( timers[ _id ] );
}

function scrollTo( _id, _dir ) {
	var e = ge( _id );
	if( e ) {
		if( _dir == 'up' ) {
			e.style.top = e.parentNode.scrollTop + 'px';			
		}
		if( _dir == 'down' ) {
			var nt = e.parentNode.clientHeight - e.clientHeight + e.parentNode.scrollTop;
			e.style.top = nt + 'px';
		}
	}
}

function makeScrollable( _id, _cid, _b )  {

	var el = ge( _id );	
	if( el ) {
		el.style.overflow = 'hidden';
		var code = '<div id="t_' + _cid + '" class="scrolltop" onmouseover="startScroll( \'' + _cid + '\', \'down\' )" onclick="scrollTo( \'' + _cid + '\', \'up\' ); return false;" onmouseout="stopScroll( \'' + _cid + '\' )"></div>';
		code += '<div id="b_' + _cid + '" class="scrollbottom" onmouseover="startScroll( \'' + _cid + '\', \'up\' )" onclick="scrollTo( \'' + _cid + '\', \'down\' ); return false;" onmouseout="stopScroll( \'' + _cid + '\' )"></div>';
		code += '<div id="ns_' + _cid + '" class="scrollbody" ><div id="' + _cid + '" class="scrollpanel">';
		code += el.innerHTML;
		code += '</div>';
		code += '</div>';
		
		var ise6 = ( typeof document.body.style.maxHeight == 'undefined' );
		if( !ise6 ){
			if( _b ) {
				code += '<img class="shadetop" alt="" src="images/scrollovertop.png" width="100%" height="5" />';
				code += '<img class="shadebottom" alt="" src="images/scrolloverbottom.png" width="100%" height="5" />';
			} else {
				code += '<img class="shadetop" alt="" src="images/scrollovertopw.png" width="100%" height="5" />';
				code += '<img class="shadebottom" alt="" src="images/scrolloverbottomw.png" width="100%" height="5" />';
			}
		}
		re( el, code );
		monitorScroll( _cid );
	}

	var int = self.setInterval( "monitorScroll( '" + _cid + "' )", 50 );
}

function monitorScroll( _id ) {
	var e1 = ge( 'ns_' + _id );
	var e2 = ge( _id );
	if( e1 && e2 ) {
		var s = ( e2.clientHeight > e1.clientHeight );
		show( 't_' + _id, s );
		show( 'b_' + _id, s );
		if( !s ) resetScroll( _id );
	}	
}

var h1 = { 'mendoza': 0, 'brandies': -24, 'wines': -48, 'tablewines': -168, 'vinegars': -72, 'bohorquez': -192 }
var h2 = { 'mendoza': 0, 'brandies': -96, 'wines': -120, 'tablewines': -168, 'vinegars': -144, 'bohorquez': -192 }

function convertItem( _id, _top ) {
	var el = ge( _id + 'item' );
	if( !el ) return;
	var h = h1;
	if( _top ) h = h2;
	el.onmouseover = function() { 
		var el = ge( _id + 'menu' ); 
		if( el ) {
			for( i = 0; i < el.childNodes.length; i++ ) el.childNodes[ i ].style.display = 'block';
			el.style.display = 'block'; 
		}
		this.className += ' over'; 
		el = ge( _id + 'bottle' );
		if( el ) el.style.backgroundPositionY = '0px'; 
		el = ge( _id + 'caption' );
		if( el ) el.style.backgroundPosition = '-75px ' + h[ _id ] + 'px'; 
	}
	el.onmouseout = function() { 
		var el = ge( _id + 'menu' );
		if( el ) {
			for( i = 0; i < el.childNodes.length; i++ ) el.childNodes[ i ].style.display = 'none';
			el.style.display = 'none';
		}
		this.className = this.className.replace( ' over', '' ); 
		el = ge( _id + 'bottle' );
		if( el ) el.style.backgroundPositionY = '-210px'; 
		el = ge( _id + 'caption' ); 
		if( el ) el.style.backgroundPosition = '0px ' + h[ _id ] + 'px'; 
	}	
}