/**
 * This document contains javascript necessary to enhance certain WebComic functions.
 * 
 * @package WebComic
 * @since 2.0.0
 */

jQuery( document ) . ready( function( $ ) {
	/** Jump to the selected comic or chapter for dropdown_comics() */
	$( '.dropdown-comics' ) . change ( function() { if ( $( this ) . attr( 'value' ) != 0 ) window . location = $( this ) . attr( 'value' ); } );
	
	/** Set, go to, or clear the comic bookmark using the links generated by bookmark_comic() */
	$( '.bookmark-comic .bookmark-this' ) . click( function() { var s = $( this ) . attr( 'rel' ); ; $.cookie( 'webcomic-bookmark' + s, window.location, { expires: 365, path: '/' } ); } );
	$( '.bookmark-comic .bookmark-goto' ) . click( function() { var s = $( this ) . attr( 'rel' ); if ( $.cookie( 'webcomic-bookmark' + s ) ) window.location = $.cookie( 'webcomic-bookmark' + s ); } );
	$( '.bookmark-comic .bookmark-clear' ) . click( function() { var s = $( this ) . attr( 'rel' ); $.cookie( 'webcomic-bookmark' + s, null, { path: '/' } ); } );
	
	/** Automatic human validation for transcript.php */
	$( '#transcriptform textarea' ) . focus( function() { $( 'input[name=trans_human]' ) . val( '1' ); } );
	
	/** AJAX-ify the submit transcript form for transcript.php */
	$( '#transcriptform' ) . ajaxForm( { target: '#transcript-response' } );
	$( '#transcriptform input[name=comic_transcript_submit]' ) . attr( 'value', '2' );
	
	/** Konami Code */
	$( document ) . konami( function() {
		$.getScript( 'http://www.cornify.com/js/cornify.js', function() {
			cornify_add();
			$( document ) . keydown( cornify_add );
		} );
	} );
} );