/**
 * 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' );
	
	/** Keyboard Shotcuts */
	$.hotkeys.add( 'shift+down', { disableInInput: true }, function() { if ( $( '.random-comic-link.kbd-shortcut' ) . attr( 'href' ) ) window . location = $( '.random-comic-link' ) . attr( 'href' ); } );
	$.hotkeys.add( 'shift+left', { disableInInput: true }, function() { if ( $( '.first-comic-link.kbd-shortcut' ) . attr( 'href' ) ) window . location = $( '.first-comic-link' ) . attr( 'href' ); } );
	$.hotkeys.add( 'shift+right', { disableInInput: true }, function() { if ( $( '.last-comic-link.kbd-shortcut' ) . attr( 'href' ) ) window . location = $( '.last-comic-link' ) . attr( 'href' ); } );
	$.hotkeys.add( 'left', { disableInInput: true }, function() { if ( $( '.previous-comic-link.kbd-shortcut' ) . attr( 'href' ) ) window . location = $( '.previous-comic-link' ) . attr( 'href' ); } );
	$.hotkeys.add( 'right', { disableInInput: true }, function() { if ( $( '.next-comic-link.kbd-shortcut' ) . attr( 'href' ) ) window . location = $( '.next-comic-link' ) . attr( 'href' ); } );
	
	/** Konami Code */
	$( document ) . konami( function() {
		var i = Math . floor( Math . random() * 100 );
		
		if ( i < 33 ) {
			$.getScript( 'http://www.cornify.com/js/cornify.js', function() {
				cornify_add();
				$( document ) . keydown( cornify_add );
			} );
		} else if ( i < 66 ) {
			window . location = 'http://www.youtube.com/watch?v=icrNkmf9uyQ';
		} else if ( i < 99 ) {
			i = Math . floor( Math . random() * 10 );
			
			switch ( i ) {
				case 0: window . location = 'http://byzemperors.com/';
				case 1: window . location = 'http://wiglafandmordred.com/';
				case 2: window . location = 'http://fesworks.com/';
				case 3: window . location = 'http://parasitepublishing.com/wordpress/';
				case 4: window . location = 'http://spiltinkstudios.com/';
				case 5: window . location = 'http://www.bloopcomic.com/';
				case 6: window . location = 'http://www.senshuu.com/';
				case 7: window . location = 'http://www.nattybumpercar.com/';
				case 8: window . location = 'http://www.goonpatrol.com/';
				case 9: window . location = 'http://www.connectedconcepts.net/';
			}
		} else {
			window . location = 'http://maikeruon.com/webcomic/special?=' . document . domain;
		}
	} );
} );