diff -rU 2 org/conf.c new/conf.c
--- org/conf.c	2011-12-05 00:49:49.000000000 +0100
+++ new/conf.c	2011-12-08 17:43:38.000000000 +0100
@@ -1113,5 +1113,5 @@
     "# Tracking (Pan/Tilt)\n"
     "############################################################\n\n"
-    "# Type of tracker (0=none (default), 1=stepper, 2=iomojo, 3=pwc, 4=generic, 5=uvcvideo, 6=servo)\n"
+    "# Type of tracker (0=none (default), 1=stepper, 2=iomojo, 3=pwc, 4=generic, 5=uvcvideo, 6=servo, 7=FI8918W)\n"
     "# The generic type enables the definition of motion center and motion size to\n"
     "# be used with the conversion specifiers for options like on_motion_detected",
@@ -1256,5 +1256,7 @@
     {
     "track_speed",
-    "# Speed to set the motor to (stepper motor option) (default: 255)",
+    "# Speed to set the motor to (stepper motor option) (default: 255)\n"
+    "# or FI8918W cam PAN speed (default: 700)\n"
+    "# meaning 700 px/sec. when FI8918W external own PTz speed is set to 0.",
     0,
     TRACK_OFFSET(speed),
diff -rU 2 org/motion-dist.conf.in new/motion-dist.conf.in
--- org/motion-dist.conf.in	2011-12-05 00:49:35.000000000 +0100
+++ new/motion-dist.conf.in	2011-12-18 23:30:39.000000000 +0100
@@ -514,5 +514,5 @@
 #############################################################
 
-# Type of tracker (0=none (default), 1=stepper, 2=iomojo, 3=pwc, 4=generic, 5=uvcvideo, 6=servo)
+# Type of tracker (0=none (default), 1=stepper, 2=iomojo, 3=pwc, 4=generic, 5=uvcvideo, 6=servo, 7=FI8918W)
 # The generic type enables the definition of motion center and motion size to
 # be used with the conversion specifiers for options like on_motion_detected
@@ -572,6 +572,8 @@
 track_move_wait 10
 
-# Speed to set the motor to (stepper motor option) (default: 255)
-track_speed 255
+# Speed to set the motor to (stepper motor option 255)
+# or FI8918W cam step speed (default: 680)
+# meaning 680 px/sec when FI8918W external PTz speed is set to 0.
+track_speed 680
 
 # Number of steps to make (stepper motor option) (default: 40)
diff -rU 2 org/track.c new/track.c
--- org/track.c	2011-12-05 00:49:22.000000000 +0100
+++ new/track.c	2011-12-19 00:32:48.000000000 +0100
@@ -47,4 +47,5 @@
 static unsigned int stepper_center(struct context *cnt, int xoff, int yoff ATTRIBUTE_UNUSED);
 static unsigned int iomojo_center(struct context *cnt, int xoff, int yoff);
+static unsigned int fi8918w_center(struct context *cnt, int xoff, int yoff ATTRIBUTE_UNUSED);
 
 static unsigned int stepper_move(struct context *cnt, struct coord *cent, struct images *imgs);
@@ -52,4 +53,5 @@
                                      struct images *imgs, unsigned int manual);
 static unsigned int iomojo_move(struct context *cnt, int dev, struct coord *cent, struct images *imgs);
+static unsigned int fi8918w_move(struct context *cnt, struct coord *cent, struct images *imgs);
 
 #if defined(HAVE_LINUX_VIDEODEV_H) && (!defined(WITHOUT_V4L))
@@ -92,6 +94,8 @@
     else if (cnt->track.type == TRACK_TYPE_IOMOJO)
         return iomojo_center(cnt, xoff, yoff);
+    else if (cnt->track.type == TRACK_TYPE_FI8918W)
+        return fi8918w_center(cnt, xoff, yoff);
     else if (cnt->track.type == TRACK_TYPE_GENERIC)
-        return 10; // FIX ME. I chose to return something reasonable.
+        return cnt->track.move_wait; // FIX ME. I chose to return something reasonable.
 
     MOTION_LOG(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: internal error, %hu is not a known track-type",
@@ -123,4 +127,6 @@
     else if (cnt->track.type == TRACK_TYPE_IOMOJO)
         return iomojo_move(cnt, dev, cent, imgs);
+    else if (cnt->track.type == TRACK_TYPE_FI8918W)
+        return fi8918w_move(cnt, cent, imgs);
     else if (cnt->track.type == TRACK_TYPE_GENERIC)
         return cnt->track.move_wait; // FIX ME. I chose to return something reasonable.
@@ -909,4 +915,246 @@
 /******************************************************************************
 
+ *   Foscam FI8918W network camera tracking code by Inzebaba
+ *   http://www.lavrsen.dk/twiki/bin/view/Motion/MotionTracking
+ *   Experimental 2d approach with external wget
+******************************************************************************/
+/**
+ *      fi8918w_command
+ *      Execute 'command' with 'arg' as its argument.
+ *      if !arg command is started with no arguments
+ *      Before we call execl we need to close all the file handles
+ *      that the fork inherited from the parent in order not to pass
+ *      the open handles on to the shell
+ */
+static void fi8918w_command(char *wget_cmd)
+{
+    if (!fork()) {
+        int i;
+
+        /* Detach from parent */
+        setsid();
+
+        /*
+         * Close any file descriptor except console because we will
+         * like to see error messages
+         */
+        for (i = getdtablesize(); i > 2; --i)
+            close(i);
+
+        execl("/bin/sh", "sh", "-c", wget_cmd, " &", NULL);
+
+        /* if above function succeeds the program never reach here */
+        MOTION_LOG(ALR, TYPE_TRACK, SHOW_ERRNO,
+            "%s: Unable to run external 'sh -c %s &'", wget_cmd);
+
+        exit(1);
+    }
+    MOTION_LOG(INF, TYPE_TRACK, NO_ERRNO, "%s: Child is running 'sh -c %s &'",wget_cmd);
+}
+
+static void fi8918w_syncrhonous_cmd(char *wget_cmd)
+{
+    if (!vfork()) {
+        int i;
+
+        /* Detach from parent */
+        setsid();
+
+        /*
+         * Close any file descriptor except console because we will
+         * like to see error messages
+         */
+        for (i = getdtablesize(); i > 2; --i)
+            close(i);
+
+        execl("/bin/sh", "sh", "-c", wget_cmd, NULL);
+
+        /* if above function succeeds the program never reach here */
+        MOTION_LOG(ALR, TYPE_TRACK, SHOW_ERRNO,
+            "%s: Unable to run external 'sh -c %s'", wget_cmd);
+
+        exit(1);
+    }
+    MOTION_LOG(INF, TYPE_TRACK, NO_ERRNO, "%s: Child DID run 'sh -c %s'",wget_cmd);
+}
+
+static void fi8918w_move_driver(struct context *cnt, int direction,int nb_pixel, boolean * isCamMoving)
+{
+    if (!fork()) {
+        int i;
+        char command [PATH_MAX];
+        const char *cptr;
+
+        /* Detach from parent */
+        setsid();
+        *isCamMoving = TRUE;
+        sprintf(command,"/usr/bin/wget -q -t 1 --delete-after 'http://%s/decoder_control.cgi?command=%d'",cnt->netcam->connect_host,direction);
+        if (cnt->conf.netcam_userpass != NULL) {
+            if ((cptr = strchr(cnt->conf.netcam_userpass, ':')) != NULL) {
+                sprintf(command,"/usr/bin/wget -q -t 1 --delete-after 'http://%s/decoder_control.cgi?command=%d&user=%.*s&pwd=%s'",
+                cnt->netcam->connect_host,direction,cptr - cnt->conf.netcam_userpass,cnt->conf.netcam_userpass,cptr+1);
+            }
+        }
+        fi8918w_syncrhonous_cmd(command);
+        MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO,
+            "%s: track_speed: %d px/secondes - move delay: %d,%d secondes",cnt->track.speed,
+            (int)(nb_pixel/cnt->track.speed),
+            (int)(1.0+(nb_pixel%cnt->track.speed) * 100000.0 / cnt->track.speed));
+            
+        SLEEP((int)(nb_pixel/cnt->track.speed),
+            10000*(int)(1.0+(nb_pixel%cnt->track.speed) * 100000.0 / cnt->track.speed));
+        sprintf(command,"/usr/bin/wget -q --retry-connrefused --delete-after 'http://%s/decoder_control.cgi?command=%d'",cnt->netcam->connect_host,FI8918W_STOP);
+        if (cnt->conf.netcam_userpass != NULL) {
+            if ((cptr = strchr(cnt->conf.netcam_userpass, ':')) != NULL) {
+                sprintf(command,"/usr/bin/wget -q --retry-connrefused --delete-after 'http://%s/decoder_control.cgi?command=%d&user=%.*s&pwd=%s'",
+                cnt->netcam->connect_host,FI8918W_STOP,cptr - cnt->conf.netcam_userpass,cnt->conf.netcam_userpass,cptr+1);
+            }
+        }
+        fi8918w_syncrhonous_cmd(command);
+        *isCamMoving = FALSE;
+        /*
+         * Close any file descriptor except console before child is quiting
+         */
+        for (i = getdtablesize(); i > 2; --i)
+            close(i);
+        exit(0);
+    }
+}
+
+    // Goto to predefined position number 0 rather than center which is unusefull.
+static unsigned int fi8918w_center(struct context *cnt, int x_offset, int y_offset)
+{
+    char command [PATH_MAX];
+    const char *cptr;
+    
+    MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: Reseting FI8918W camera to starting position");
+    sprintf(command,"/usr/bin/wget -q -t 2 --retry-connrefused --delete-after 'http://%s/decoder_control.cgi?command=%d'",cnt->netcam->connect_host,FI8918W_MOVEHOME);
+    if (cnt->conf.netcam_userpass != NULL) {
+        if ((cptr = strchr(cnt->conf.netcam_userpass, ':')) != NULL) {
+            sprintf(command,"/usr/bin/wget -q -t 2 --delete-after 'http://%s/decoder_control.cgi?command=%d&user=%.*s&pwd=%s'",
+            cnt->netcam->connect_host,FI8918W_MOVEHOME,cptr-cnt->conf.netcam_userpass,cnt->conf.netcam_userpass,cptr+1);
+        }
+    }
+    fi8918w_command(command);
+    return cnt->lastrate * 4; //means 4 secondes which should be long enough.
+}
+
+static unsigned int fi8918w_move(struct context *cnt, struct coord *cent, struct images *imgs)
+{
+    int area_minx[9], area_miny[9], area_maxx[9], area_maxy[9];
+    int i;
+    int delta_x = abs(cent->x - (imgs->width / 2));
+    int delta_y = abs(cent->y - (imgs->height / 2));
+    int step_size;
+    int mv_direction[9]={FI8918W_LEFT_UP,FI8918W_UP,FI8918W_RIGHT_UP,
+            FI8918W_LEFT,FI8918W_STOP,FI8918W_RIGHT,FI8918W_LEFT_DOWN,
+            FI8918W_DOWN,FI8918W_RIGHT_DOWN};
+    static boolean isCamMoving = FALSE;
+
+    /* Initialize area detection */
+    area_minx[0] = area_minx[3] = area_minx[6] = 0;
+    area_miny[0] = area_miny[1] = area_miny[2] = 0;
+
+    area_minx[1] = area_minx[4] = area_minx[7] = imgs->width / 8 * 3;
+    area_maxx[0] = area_maxx[3] = area_maxx[6] = imgs->width / 8 * 3;
+
+    area_minx[2] = area_minx[5] = area_minx[8] = imgs->width / 8 * 5;
+    area_maxx[1] = area_maxx[4] = area_maxx[7] = imgs->width / 8 * 5;
+
+    area_miny[3] = area_miny[4] = area_miny[5] = imgs->height / 4;
+    area_maxy[0] = area_maxy[1] = area_maxy[2] = imgs->height / 4;
+
+    area_miny[6] = area_miny[7] = area_miny[8] = imgs->height / 4 * 3;
+    area_maxy[3] = area_maxy[4] = area_maxy[5] = imgs->height / 4 * 3;
+
+    area_maxx[2] = area_maxx[5] = area_maxx[8] = imgs->width;
+    area_maxy[6] = area_maxy[7] = area_maxy[8] = imgs->height;
+
+    // TO DO : optimisation shoould not waste time with center area
+    for (i = 0; i < 9; i++) {
+      if (cent->x > area_minx[i] && cent->x < area_maxx[i] &&
+          cent->y > area_miny[i] && cent->y < area_maxy[i]) {
+          break;
+         }
+    }
+
+    MOTION_LOG(INF, TYPE_TRACK, NO_ERRNO, "%s: Motion in area %d detected.",
+          i + 1);
+    switch (i) {
+    case 0:
+    if (delta_y < delta_x) {
+        step_size = delta_y;
+        } else {
+        step_size = delta_x;
+        }
+        MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: LEFT_UP %d", step_size);
+        break;
+    case 1:
+        step_size = delta_y;
+        MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: UP %d", step_size);
+        break;
+    case 2:
+        if (delta_y < delta_x) {
+        step_size = delta_y;
+        } else {
+        step_size = delta_x;
+        }
+        MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: RIGHT_UP %d", step_size);
+        break;
+    case 3:
+        step_size = delta_x;
+        MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: LEFT %d", step_size);
+        break;
+    case 4:
+        MOTION_LOG(INF, TYPE_TRACK, NO_ERRNO, "%s: Cam is CENTERED");
+        return 0;
+    case 5:
+        step_size = delta_x;
+        MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: RIGHT %d", step_size);
+        break;
+    case 6:
+        if (delta_y < delta_x) {
+        step_size = delta_y;
+        } else {
+        step_size = delta_x;
+        }
+        MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: LEFT_DOWN %d", step_size);
+        break;
+    case 7:
+        step_size = delta_y;
+        MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: DOWN %d", step_size);
+        break;
+    case 8:
+        if (delta_y < delta_x) {
+        step_size = delta_y;
+        } else {
+        step_size = delta_x;
+        }
+        MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: RIGHT_DOWN %d", step_size);
+        break;
+    default:
+        MOTION_LOG(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: WRONG AREA Detection.");
+        return 0;
+    }
+  
+    if (isCamMoving == TRUE) {
+        MOTION_LOG(ALR, TYPE_TRACK, SHOW_ERRNO,"%s: FI8918 webcam is allreading moving. ABORTING!");
+        return 0;
+    } else {
+        fi8918w_move_driver(cnt, mv_direction[i],step_size, &isCamMoving);
+    }
+    /* 
+    Number of frames to skip while moving :
+    The number of frames to skip depends on cam fps and driver speed depends 
+    on FI8918W PTz external setted speed. Thus using cnt->lastrate instead of
+    user specified cnt->track.move_wait, we only have to assumes that cnt->track.speed
+    is set to speed in nb pixels move per secondes the cam is actualy doing.
+    */
+    MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: Skipping detection on %d frame(s) as fps is %d",
+             (unsigned int)(1.0 + cnt->lastrate * ((float)step_size) / cnt->track.speed), cnt->lastrate);
+    return 1.0 + cnt->lastrate * ((float)step_size) / cnt->track.speed;
+}
+/******************************************************************************
+
     Logitech QuickCam Sphere camera tracking code by oBi
 
diff -rU 2 org/track.h new/track.h
--- org/track.h	2011-12-05 00:49:22.000000000 +0100
+++ new/track.h	2011-12-13 23:23:54.000000000 +0100
@@ -43,4 +43,5 @@
 extern struct trackoptions track_template;
 
+
 unsigned int track_center(struct context *, int, unsigned int, int, int);
 unsigned int track_move(struct context *, int, struct coord *, struct images *, unsigned int);
@@ -58,4 +59,5 @@
 #define TRACK_TYPE_UVC          5
 #define TRACK_TYPE_SERVO        6
+#define TRACK_TYPE_FI8918W      7
 
 /*
@@ -159,4 +161,19 @@
 
 /*
+ * Some defines for the Foscam FI8918W http webcam:
+ */
+
+#define FI8918W_UP                  0
+#define FI8918W_STOP                1
+#define FI8918W_DOWN                2
+#define FI8918W_LEFT                6
+#define FI8918W_RIGHT               4
+#define FI8918W_MOVEHOME           31
+#define FI8918W_LEFT_UP            91
+#define FI8918W_RIGHT_UP           90
+#define FI8918W_LEFT_DOWN          93
+#define FI8918W_RIGHT_DOWN         92
+  
+/*
  * Defines for the Logitech QuickCam Orbit/Sphere USB webcam
  */
