
    var offset=0;

    var stopUp = 1;
    var stopDown = 1;

    function shiftup()
    {
	viewPortHeight = $('#scroller').height(); 

	if( stopUp ) return;

	h = $('#copyDynamicNode').height();

	if( offset >= h - viewPortHeight ) return;

	offset += 2; 
	$('#copyDynamicNode').css({top: '-' + offset + 'px'});
    }

    function shiftdown()
    {
	if( stopDown ) return;

	if( offset <= 0 ) return;

	offset -= 2; 
	$('#copyDynamicNode').css({top: '-' + offset + 'px'});
    }


    function regExpSrcUpdate( o, to ) 
    {
	src = o.src;
	src = src.replace( /-[^\/]*$/, to );  
	o.src = src; 
    }

    function condRegExpSrcUpdate( c, o, a, b ) 
    {
	(c == o) ? regExpSrcUpdate( o, a ) : regExpSrcUpdate( o, b );
    }
 
function hideAllShowOne( all, one )
{
    $(all).css('display', 'none');
    $(one).css('display', 'block');
}

var onElement;
function groupStyleToggle( all, one, attr, on, off )
{
    onElement = one;

    $(all).css(attr, off);
    $(one).css(attr, on);
}

jQuery.fn.log = 

//( console ) ?
//    function (msg) {	
//	console.log("%s: %o", msg, this);
//	return this;
//    } :
    function () {	
	return this;
    };



var makeOnClick = function(t_, bb_) {

    return (function() {
	$('.lb').click( function() {return false} );
	$('.lb').removeClass('lightbox');

	$().log( ">>" + t_ );
		    
	$(t_).addClass('lightbox');

	$('.lightbox' + bb_).addClass('lightbox');
	$('.lightbox').lightBox();

	$(this).click();
    })
};


function installLightboxes() {

    var aaa = [1,2,3];
    var bbb = [1,2,3];

    for(a in aaa) {	
	for(b in bbb) {	
	
	    var ax = aaa[a];
	    var bx = bbb[b];

	    var target = ['.lb',ax,'-',bx].join('');	

	    $().log( ">" + target );
	  
	    $(target).click( makeOnClick( target, bx ) ); 
	}
    }
}





$(document).ready( function() 
{ 
    // for some reason safari needs this
    // to position the menu images correctly.
    if ($.browser.safari) {
	$('.sf-menu img' ).css( {
		'position' : 'relative',
		'left'     : '-0px'
	    } );
    }




	$('.lightbox').lightBox();

    if( $('.lb').is('*') ) {
        $('.lb').click( function() {return false} );
	installLightboxes();	
    }

    $('.mo').each(
        function() {
           $(this).mouseover( function() { 
                 id = $(this).attr('id'); id = '#' + id + 't'; 
		 hideAllShowOne( '.descriptiontitle', id );
           })
        }   
    );


       $('img.ro').each( 

           function() 
	   { 
	   $( this ).mouseover( 

		   function() 
		   { 
		       regExpSrcUpdate( this, "-rollover.gif" ); 
		   } );
	
	   $( this ).mouseout(  

		   function() 
		   { 
		       regExpSrcUpdate( this, "-button.gif" ); 
		   } );

           });
      

       $('img.h').each( 

           function() 
	   { 
	
	   $( this ).mousedown(
    
                   function() 
                   { 
		       regExpSrcUpdate( this, "-hitstate.gif" ); 
		       return false; 
		   } );	

	   $( this ).mouseup(
    
                   function() 
                   { 
		       regExpSrcUpdate( this, "-rollover.gif" ); 
		       return false; 
		   } );	

           });
    
    if( $('#scroller').is('*') )
    {
	$('#scroller').css( { overflow: "hidden" } );
	$('#scroller').wrapInner('<div id="copyDynamicNode"></div>'); 

	$('#copyDynamicNode').css( { position: "absolute", top: "0px" } );

	$(this).everyTime(2, 'controlled-up', shiftup );
	$(this).everyTime(2, 'controlled-down', shiftdown );

	$('#downarrow' ).mousedown(function() {stopUp = 0; shiftdown() });
	$('#downarrow').mouseup( function() { stopUp = 1; });
	$('#uparrow' ).mousedown(function() { stopDown = 0; shiftup() });
	$('#uparrow').mouseup( function() { stopDown = 1; });
	$('#downarrow').click(function() { return false; }); 
	$('#uparrow').click(function() { return false; }); 

	$('#downarrow').wrap('<a id="dahref" href="#"></a>');
	$('#uparrow').wrap('<a id="uahref" href="#"></a>');

	$('#dahref').click(function() { return false; }); 
	$('#uahref').click(function() { return false; }); 
	$('#dahref').mouseup(function() { return false; }); 
	$('#uahref').mouseup(function() { return false; }); 


    }



if( $('#carousel').is('*') )
{
    function initCallback(carousel) {

	jQuery('#rightarrow').bind('click', function() {
	    carousel.next();
	    return false;
	});

	jQuery('#leftarrow').bind('click', function() {
	    carousel.prev();
	    return false;
	});
    }

    jQuery('#carousel').jcarousel({
        scroll: carouselSize,
        wrap: 'both',
        initCallback: initCallback,
        buttonNextHTML: null,
        buttonPrevHTML: null
    });
}


    if( $('#slides').is('*') )
    {
	leaveSelected = $('#nav img')[0];

	$('#nav img').each( 

           function() 
	   { 
	       var preload = new Image();
	       preload.src = this.src;
	       regExpSrcUpdate( preload, "-rollover.gif" ) ;
	   });


	$('#slides img').addClass('next'); 

	$('#nav img').each( 

           function() 
	   { 

	   $( this ).wrap('<a href="#"></a>'); 


	   $( this ).mouseover( 

		   function() 
		   { 
		       regExpSrcUpdate( this, "-rollover.gif" ); 
		   } );
	
	   $( this ).click(
     
                   function() 
                   { 
		       $('#nav img').each( function() {  regExpSrcUpdate( this, "-button.gif" ) } );	
		       regExpSrcUpdate( this, "-hitstate.gif" ); 
		       leaveSelected = this; 
		       return false; 
		   } );	

	   $( this ).mouseout(  

		   function() 
		   { 
		       condRegExpSrcUpdate( leaveSelected, this, "-hitstate.gif", "-button.gif" );
		   } );

           });

       $('.next').wrap('<a href="#" class="dynamicNodeA" ></a>');
       $('.prev').wrap('<a href="#" class="dynamicNodeA" ></a>'); 



       $( '.dynamicNodeA' ).mouseup(   function() { $(this).blur() } );	




       $('div#slides').cycle( {
	       fx: 'fade',
	       timeout: 0,
		
	       next: '.next',   
	       prev: '.prev',
	
	       after: function() { 

if( $('#caption').is('*') && $.browser.msie )
{
    $('#slides > div > div').css('display', 'none' );

      html = this.lastChild.innerHTML;
      $( '#caption' ).html( html );
}  
else if( $('#caption').is('*') )
{
    $('#slides > div > div').css('display', 'none' );

    caption =  $(this).find( 'div' ).clone();
    caption.css('display', 'block');

    $( '#caption' ).html( caption );
}  
               },
	
	       pager: '#nav',
	       pagerAnchorBuilder: function(idx, slide) 
	       { 
			return '#nav div:eq(' + idx + ')  img'; 
	       },
		
	       prevNextClick: function( isNext, idx, slide ) 
               {
		   e = $('#nav div:eq(' + idx + ') img'); 
		   e = e[0];

		   leaveSelected = e;
		   $('#nav img').each( 
                        function() 
			{
			    condRegExpSrcUpdate( leaveSelected, this, "-hitstate.gif", "-button.gif" );
                        } );	
	       }
	       
       });

   }


});

