
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);
}

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'});
}

$(document).ready( function() 
{ 
    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; }); 


    }

    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 );
    }


    if( $('#nav').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="#"></a>');
       $('.prev').wrap('<a href="#"></a>'); 

       $('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" );
                        } );	
	       }
	       
       });

   }

});
