$( document ).ready( function(){


	// Show a sponsor box randomly
	rd = Math.floor(Math.random()*2+1);
	$( '#tabs .btns a.'+rd+'-tab' ).addClass('active');
	$( '.tabs-content #'+rd+'-tab' ).show();

	$( '#tabs .btns a' ).click( function(){
		var id = '#' + $(this).attr( 'title' ).replace(/ /gi, '-').toLowerCase() + '-tab';
		$( '#tabs .btns a' ).removeClass('active')
		$( '.tabs-content .container' ).hide();
		
		$( this ).addClass( 'active' );
		$( id ).show();
		
		return false;
	});
	
	
	var li = $( this ).parent();
	$( '.more-archives' ).click( function(){
		var ul = $( this ).parent().parent();
		var orig_height = ul.height();

		if ( ul.css('display') == 'none' ) {
			ul.show();
			$( this ).html( 'less' );
		}else {
			ul.hide();
			$( this ).html( 'more' );
		}
		return false;
	})
	
	$( '.blink' )
		.focus( function(){
			if ( $( this ).attr( 'value' ) == $( this ).attr( 'title' ) )
				$( this ).attr({ 'value' : '' });
		})
		.blur ( function(){
			if ( $( this ).attr( 'value' ) == '' )
				$( this ).attr({ 'value' : $( this ).attr( 'title' ) });
		});

	if ( $( '#shopping-carousel' ).length > 0 ) {
		$( '#shopping-carousel' ).jcarousel({
			auto: 4,
			scroll: 1,
			animation: 'dev',
			wrap: 'last',
			initCallback: mycarousel_initCallback
		});
	}


	var list = $('ul#catList');
	var original_height = list.height();
	var new_height = $('#catList li').height()*8;
	list.css({height:new_height});

	$('#list-toggle').click(function() {
		if ( list.height() == new_height ) {
 			list.animate({height:original_height})
			$( this ).html( 'less' );
		}else {
 			list.animate({height:new_height})
			$( this ).html( 'more' );
		}
		return false;
	});

	var list2 = $('ul#archList');
	var original_height2 = list2.height();
	var new_height2 = $('#archList li').height()*8;
	list2.css({height:new_height2});

	$('#list-toggle2').click(function() {
		if ( list2.height() == new_height2 ) {
			list2.animate({height:original_height2})
			$( this ).html( 'less' );
		}else {
			list2.animate({height:new_height2})
			$( this ).html( 'more' );
		}
		return false;
	});

		
});

function mycarousel_initCallback(carousel) {
// Disable autoscrolling if the user clicks the prev or next button.
	carousel.buttonNext.bind('click', function() {
		carousel.startAuto(0);
	});

	carousel.buttonPrev.bind('click', function() {
		carousel.startAuto(0);
	});

	// Pause autoscrolling if the user moves with the cursor over the clip.
	carousel.clip.hover(function() {
		carousel.stopAuto();
		}, function() {
		carousel.startAuto();
	});
};