$(document).ready(function(){
	// Toggle Form Values automagically
	$("#searchform input[type='text']").toggleVal();

	// Home page carousel
	$(function() {
		$('#carousel-items').cycle({
			fx:     'fade',
			timeout: 5000,
			before: onBefore,
			pause: 1,
			next:   '#cnext',
			prev:   '#cprev',
			delay: 15000
		});
	});

	function onBefore() {
		if( $('#output1').is(':visible') ) {
			$('#output1').fadeOut(800);
			$('#output2').html(this.title);
			$('#output2').append(' <a href="'+this.href+'">Read More...</a>');
			$('#output2').fadeIn(800);
		} else {
			$('#output2').fadeOut(800);
			$('#output1').html(this.title);
			$('#output1').append(' <a href="'+this.href+'">Read More...</a>');
			$('#output1').fadeIn(800);
		}
	}
});
/* colorbox - move in to prior function. */
$(document).ready(function(){
	var $grid,
	$gallery = $('#gallery'),
	gwidth = $gallery.width(),
	gheight = $gallery.height();
	
	$().bind('cbox_load cbox_complete', function(){
		$gallery.hide();
	});
	
	$grid = $('<a href="#" id="cboxGrid"></a>')
		.hide()
		.appendTo('#cboxContent')
		.click(function(){
			if($gallery.is(':hidden')){
				$('.cboxSlideshow_on #cboxSlideshow').click();
				$("<div/>").appendTo($("#cboxLoadedContent").empty()).css({width:gwidth, height:gheight});
				$("#cboxTitle").hide();
				$("#cboxLoadingGraphic, #cboxLoadingOverlay").show();
				$.fn.colorbox.resize(false, function(){
					$("#cboxLoadedContent").remove();
					$gallery.show();
					$("#cboxLoadingGraphic, #cboxLoadingOverlay").hide();
				});
			} else {
				$.fn.colorbox.element().click();
			}
			return false;
		});	
	
	$gallery
		.before(
			//$("<a href='#'>Launch Slide Show</a>").click(function(){
			//	$('#gallery a:first').click();
			//	return false;
			//})
			$('#gallery-launch').click(function(){
				$('#gallery a:first').click();
				return false;
			})

		)
		.appendTo('#cboxContent')
		.find('a')
		.colorbox({
			innerWidth:'500px',
			rel:'gal1',
			slideshow:true,
			slideshowSpeed:3000,
			slideshowAuto:false,
			scrolling:false,
			current:"{current} / {total}",
			title:function(){ return "<div>"+$(this).attr('title')+"</div>"; }
			}, function () {
				$grid.show();
			}
		);
});

