// Javascript

$(document).ready(function() {
	
	// Pull images and YouTube videos from page and append to sidebar
	$('#main .wp-caption').appendTo('#slideshow');
	$('#main object').appendTo('#youtube');
	
	
	// Find thumbnail images in single posts
	$('#main img').each(function(index){
		if ($(this).attr('width') == 260) {
			$(this).parent().addClass('slideshow-img');
			$(this).parent().addClass('thumb-img');
		}
	});
	
	$('#main h2 + p').after('<div id="post-slideshow" style="margin:0 0 20px 20px; padding:0; width:260px; overflow:hidden;"></div>');
	$('.slideshow-img').appendTo('#post-slideshow');
	
	// If thumbnail doesn't exist, then remove slideshow wrapper
	if ( $('.size-thumbnail').length == 0 ) {
		$('#slideshow-wrapper').hide();
		$('#post-slideshow').hide();
	}
	
	
	// Image slideshow
	$(function() {
	   $('#slideshow, #post-slideshow').cycle({
			timeout: 4500,
			speed: 2000,
			pause: true,
			random: true
		});
	});
	
	
	// Hide toggle items
	$('.toggle').hide();
	
	// Toggle list items
	$('#toggle-list h3').click(function () {
		$(this).siblings('.toggle').slideToggle();
		$(this).parent().toggleClass('active');
	});
	
	// Post List item linkage
	$('.link').click(function () {
		window.location=$(this).find("a").attr("href");
		return false;
	});
	
	
	 
	
	autoFill($("input.wp-email-capture-name"), "Full Name");
	autoFill($("input.wp-email-capture-email"), "Email Address");
	
	//auto fill search field
	function autoFill(id, v){
		
		$(id).attr({
		value: v
	
	}).focus(function(){
	
		if($(this).val()==v){
			
			$(this).val("").css({
		
		});
	}
	
	}).blur(function(){
		
		if($(this).val()==""){
			$(this).val(v);
		}
		
	});
 
}
	
	
	
});
