<?php

function mar_mark_as_read_js() {
	global $mar_base_dir;
	global $mar_options;
	
	if($mar_options['alert_read'] == '') {
		$read_text = 'Post marked as read';
	} else {
		$read_text = $mar_options['alert_read'];
	}
	if($mar_options['alert_unread'] == '') {
		$unread_text = 'Mark Post as Unread?';
	} else {
		$unread_text = $mar_options['alert_unread'];
	}
	
	wp_enqueue_script( "mark-as-read", $mar_base_dir . 'includes/mark-as-read.js', array( 'jquery' ) );
	wp_localize_script( 'mark-as-read', 'mark_as_read_js', 
		array( 
			'ajaxurl' => admin_url( 'admin-ajax.php' ),
			'read_message' => $read_text,
			'unread_message' => $unread_text,
			'show_alerts' => $mar_options['alerts']
		) 
	);	
}
add_action('wp_print_scripts', 'mar_mark_as_read_js');

function mar_load_auto_scripts() {
	global $mar_base_dir, $post, $mar_options;
	wp_enqueue_script( "mark-as-read-auto", $mar_base_dir . 'includes/mark-as-read-auto.js', array( 'jquery' ) );
	wp_localize_script( 'mark-as-read-auto', 'mark_as_read_auto_js', 
		array( 
			'ajaxurl' => admin_url( 'admin-ajax.php' ),
			'post_id' => $post->ID,
			'time' => $mar_options['auto_time']
		) 
	);
}

function mar_custom_css() {
	global $mar_options;
	
	if($mar_options['mar_css']) {
		echo '<style type="text/css">' . PHP_EOL;
		echo $mar_options['mar_css'] . PHP_EOL;
		echo '</style>' . PHP_EOL;
	}
}
add_action('wp_head', 'mar_custom_css');