$().ready(function(){
	
	// Home Page slide show
	// Append controls and initialize Cycle plugin
	$("#home-slider")
		.after('<div class="slide-nav" />')
		.after('<a class="slide-prev" />')
		.after('<a class="slide-next" />')
		.cycle({ 
			timeout: 8000,
			pager: '.slide-nav', 
			next: '.slide-next', 
			prev: '.slide-prev'
		});		
		
	// Stop when a slide is clicked	
	$('.slide-nav a, .slide-next, .slide-prev').click(function(){
		$("#home-slider").cycle('stop');
	});
		
	// Redirects for select "jump" lists
	$("select.jumplist").change(function(){
		if($(this).val() != '') {
			window.location = $(this).val();
		}
	});
	
	// Video overlays
	$(".video-link").fancybox();
	
	$(".video-slider").cycle({
		fx:'scrollHorz', 
		timeout:0,
		next: '.video-next',
		prev: '.video-prev',
		before: function(currSlideElement, nextSlideElement) {
			$("#video-description").hide();
			$("#video-description").html( $(nextSlideElement).find(".description").html() ).fadeIn('fast');
		}
	});
	
	// Vertical align banners
	$('.sidebar-banner > div > a, .home-banner > div > a').each(function(i){
		var ah = $(this).height();
		var ph = $(this).parent().height();
		var mh = (ph - ah) / 2;
		$(this).css('padding-top', mh);
	});
	
	// Open external links in a new window
	$("a[href^=http]").each(function() {
		if(this.href.indexOf(location.hostname.replace(/www./gi, "")) == -1) {
			$(this).click(function() { window.open(this.href, "_blank"); return false; });
		}
	});
	
	// Form field titles as prompts
	// Display prompts as values using Labelify plugin 
	$('input[type="text"]').labelify();
	
});
