diff --git a/wysiwyg_template.admin.inc b/wysiwyg_template.admin.inc
index f6b7cb0..1f9e86c 100644
--- a/wysiwyg_template.admin.inc
+++ b/wysiwyg_template.admin.inc
@@ -60,14 +60,13 @@ function wysiwyg_template_template_form($something, $form_state) {
       t('Cancel')
     );
   }
-
   if(isset($form_state['build_info']['args'][0])){
     // add the current values as defaults to the form, if editing an existing item
     $form_state['values'] = $form_state['build_info']['args'][0];
   }
   
   $form = array();
-  
+  $form['#attributes']['enctype'] = 'multipart/form-data';
   $form['title'] = array(
     '#type' => 'textfield',
     '#title' => t('Template Name'),
@@ -82,6 +81,20 @@ function wysiwyg_template_template_form($something, $form_state) {
     '#default_value' => isset($form_state['values']['description']) ? $form_state['values']['description'] : '',
     '#description' => t('A description to be shown with the template.')
   );
+  $form['template_image'] = array(
+      '#type' => 'file',
+      '#title' => t('Choose a file'),
+      '#size' => 22,
+      '#description' => t('A image to be shown with the template.')
+  );
+  $form['template_image_fid'] = array(
+      '#type' => 'hidden',
+      '#default_value' =>  isset($form_state['values']['fid']) ? $form_state['values']['fid'] : '',
+  );
+  $form['template_image_delete'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Delete the Template image.')
+  );  
   $form['body'] = array(
     '#type' => 'textarea',
     '#title'  => t('HTML Template'),
@@ -137,7 +150,23 @@ function wysiwyg_template_template_form_submit($form, &$form_state) {
       return;
     }
   }
-
+	
+	$filepath = 'public://wysiwyg_template_images/';
+	file_prepare_directory($filepath, FILE_CREATE_DIRECTORY);
+	
+	// save the image, validate it against file_validate_extensions
+	$file = file_save_upload('template_image', array('file_validate_extensions' => array('jpg png gif jpeg')), $filepath);
+	
+	if ($file) {
+		// set status to permanent
+		$file->status = FILE_STATUS_PERMANENT;
+		$file = file_save($file);
+	
+		if ($file) {
+			$form_state['values']['template_image'] = $file->fid;
+		}
+	}
+	
   // save the template
   if(wysiwyg_template_save_template($form_state['values'])){
     drupal_set_message(t('The template has been saved.'));
diff --git a/wysiwyg_template.install b/wysiwyg_template.install
index e93a8c8..c5fc209 100644
--- a/wysiwyg_template.install
+++ b/wysiwyg_template.install
@@ -16,11 +16,17 @@ function wysiwyg_template_schema() {
         'type' => 'varchar',
         'length' => 255,
         'not null' => TRUE),
-      'description' => array(
+			'description' => array(
         'description' => 'The description of the Wysiwyg template',
         'type' => 'varchar',
         'length' => 255,
         'not null' => TRUE),
+			'fid' => array(
+         'description' => 'The {file_managed}.fid of the image.',
+         'type' => 'int',
+         'unsigned' => TRUE,
+         'not null' => TRUE,
+         'default' => 0),
       'body' => array(
         'description' => 'The Wysiwyg template HTML',
         'type' => 'text'),
diff --git a/wysiwyg_template.module b/wysiwyg_template.module
index d3a405f..b163a51 100644
--- a/wysiwyg_template.module
+++ b/wysiwyg_template.module
@@ -140,6 +140,8 @@ function wysiwyg_template_wysiwyg_plugin($editorName, $version) {
  * Generate javascript for template loading
  */
 function wysiwyg_template_list_js($editorName){
+	global $base_url;
+	
   //don't cache templates
   drupal_add_http_header('CacheControl', 'no-cache');
   drupal_add_http_header('Expires', '-1');
@@ -158,19 +160,20 @@ function wysiwyg_template_list_js($editorName){
       }
       print json_encode($outArray) . ";";
     break;
-    case 'ckeditor':
-      print "CKEDITOR.addTemplates( 'default', { templates:";
-      //todo: include an image with templates...
-      //imagesPath : CKEDITOR.getUrl( CKEDITOR.plugins.getPath( 'templates' ) + 'templates/images/' ),
-      // load the templates into the json array structure
-      foreach($templates as $template){
-	$template['html'] = $template['body'];
-	unset($template['body']);
-	unset($template['tid']);
-      }
-      print json_encode($templates);
-      print "});";
+    
+    case 'ckeditor':			
+			print "CKEDITOR.addTemplates( 'default', { imagesPath:'". $base_url ."', templates: ";
+			
+			// load the templates into the json array structure
+			foreach($templates as &$template){
+				$template['html'] = $template['body'];
+				unset($template['body']);
+				unset($template['tid']);
+			}
+			print json_encode($templates);
+			print "});";
     break;
+    
     case 'fckeditor':
       print '<?xml version="1.0" encoding="utf-8" ?>';
       print '<Templates imagesBasePath="">';
@@ -223,6 +226,7 @@ function wysiwyg_template_load_template($tid){
       'title' => $template->title,
       'description' => $template->description,
       'body' => $template->body,
+      'fid' => $template->fid,
       'tid' => $tid,
     );
   }
@@ -234,12 +238,23 @@ function wysiwyg_template_load_template($tid){
  * Wysiwyg load all templates from the database
  */
 function wysiwyg_template_load_all(){
+	global $base_url;
+	
   $templateResults = db_query("SELECT * FROM {wysiwyg_templates}");
   $templates = array();
   foreach ($templateResults as $dbTemplate) {
+  	//get the image
+  	$image = file_load($dbTemplate->fid)->uri;
+  	if ($image) {
+			$image = str_replace($base_url, "", image_style_url('wysiwyg_template_thumbnail', $image));
+		} else {
+			$image = "";
+		}
+  	
     $template = array(
       'title' => $dbTemplate->title,
       'description' => $dbTemplate->description,
+      'image' => $image,
       'body' => token_replace($dbTemplate->body),
       'tid' => $dbTemplate->tid,
     );
@@ -255,15 +270,27 @@ function wysiwyg_template_save_template($template){
   $tItem = array(
     'title' => $template['title'],
     'description' => $template['description'],
+    'fid' => $template['template_image'],
     'body' => $template['body'],
   );
-  
+    
   //if it's an existing item we're updating
   $key = array();
   if(isset($template['tid'])){
     $key = 'tid';
     $tItem['tid'] = $template['tid'];
+    
+    //delete the file
+    if ($template['template_image_delete']) {
+    	file_delete(file_load($template['template_image_fid']));
+			$tItem['fid'] = 0;
+		
+		// get old fid
+		} else {
+			$tItem['fid'] = $template['template_image_fid'];
+		}
   }
+  
   //save to database
   return drupal_write_record('wysiwyg_templates', $tItem, $key);
 }
@@ -274,3 +301,26 @@ function wysiwyg_template_save_template($template){
 function wysiwyg_template_delete_template($tid){
   db_query("DELETE FROM {wysiwyg_templates} WHERE tid = :tid", array(':tid' => $tid));
 }
+
+
+/**
+ * Wysiwyg template image style "wysiwyg_template_thumbnail"
+ */
+function wysiwyg_template_image_default_styles() {
+	$styles = array();
+	
+	$styles['wysiwyg_template_thumbnail'] = array(
+		'effects' => array(
+			array(
+				'name' => 'image_scale',
+				'data' => array(
+					'width' => 100,
+					'upscale' => 1,
+				),
+				'weight' => 0,
+			),
+		),
+	);
+	
+	return $styles;
+}
