/*  

Theme Name: ABViews
Theme URI: http://hellocarbon.ca
Description: New look for albertaviews.ab.ca
Version: 1.0

*/
jQuery( document ).ready( function(){

	/* Form posts via <a> as well as <input> */
	var form_button = jQuery( "form .button" );
  if ( form_button.length ){
    jQuery( "form .button" ).click( function(){
      jQuery( this ).next( "input" ).trigger( "click" );
    } );
  }

	/* Get that 1st photo in it's right place */
	var posts = jQuery( '#index .post' );
	if ( posts.length ){
		posts.each( function( idx ) {
			var post = jQuery( this );
			
			/* Pull the 1st image from the article content */
			var image_box = post.find( '.image-box' );
			
			// Does the image exist within a link?
			//var image     = post.find( ".doubled-up a[rel~='attachment']" );
			var image     = post.find( ".doubled-up img:first" );
			image_box.prepend( image );
			
			image_box.remove( "p" );
		
			// If it's orphaned
			//var image     = post.find( ".doubled-up a:first" );
			//image_box.prepend( image );
			//return false;
		} );
  }

	/* Latest Issue/Magazine Edition Control */
	var mec = jQuery( '#latest-edition ul.magazineditionspicturebook li:first' );
	mec.show();
    
	/* Pufferfish */
  jQuery( '#site-credits a, .pufferfish' ).append( '<span class="hover"></span>' );
 	jQuery( '#site-credits a, .pufferfish' ).hover( function() {
 		jQuery( 'span.hover', this ).stop().animate( {
 			'opacity': 1
 		}, 700, 'easeOutSine' )
 	}, function(){
 		jQuery( 'span.hover', this ).stop().animate( {
       'opacity': 0
 		}, 2000, 'easeOutExpo' )
 	})

} );
