function imageChange(condition, current)
{
   if (condition != "none")
   {
      var max = imgList.length - 1;
      if (condition == "next")
      {
         if (current == max)
            current = 0;
         else
            ++current;
      }
      else if (condition == "prev")
      {
         if (current == 0)
            current = max;
         else
            --current;
      }
   }

   target = imgList[current];

   if (target[1] == "image")
   {
      gifStr   = target[0].replace(/.jpg/, ".gif");
      imageStr = "<!--[if IE]>\n" +
                 "<div id=\"targetAsset\" class=\"" + current + "\">\n" +
                 "  <img src=\"upload/gif/"+ gifStr +"\" width=\"100%\" alt=\"\"  style=\"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='upload/images/" + target[0] + "', sizingMethod='scale')\" /><div id=\"boxL\"></div><div id=\"boxR\"></div></div>\n" +
                 "<![endif]-->\n" +

                 "<!--[if !IE]>-->\n" +
                 "<div id=\"targetAsset\" class=\"" + current + "\"><img src=\"upload/images/"+ target[0] +"\" alt=\"\" width=\"100%\" /><div id=\"boxL\"></div><div id=\"boxR\"></div></div>\n" +
                 "<!--<![endif]-->\n" ;
   }
   else
   {
      flashStr = "<div id=\"targetAsset\" class=\"" + current + "\">\n" +
                 "    <div class=\"center\" style=\"width:"+ target[3] +";\">\n" +
                 "       <object type=\"application/x-shockwave-flash\" data=\"upload/flash/"+ target[0] +"\" width=\""+ target[3] +"\" height=\""+ target[4] +"\">\n" +
                 "          <param name=\"movie\" value=\"upload/flash/"+ target[0] +"\" />\n" +
                 "          <param name=\"quality\" value=\"high\" />\n" +
                 "          <param name=\"wmode\" value=\"transparent\" />\n" +
                 "          <param name=\"menu\" value=\"false\" />\n" +
                 "       </object><div id=\"box\"></div>" +
                 "    </div>\n" +
                 " </div>";
   }

   yearflh     = "<object type=\"application/x-shockwave-flash\" data=\"images/title_year.swf?texta="+ target[2] +"\" width=\"170\" height=\"40\">\n" +
                 "<param name=\"movie\" value=\"images/title_year.swf?texta="+ target[2] +"\" />\n" +
                 "<param name=\"quality\" value=\"high\" />\n" +
                 "<param name=\"wmode\" value=\"transparent\" />\n" +
                 "<param name=\"menu\" value=\"false\" />\n" +
                 "</object>";

   if (target[1] == "image")
   {
      $("#targetAsset").remove();
      $("#replace").append(imageStr);
   }
   else if (target[1] == "flash")
      $("#replace").html(flashStr);

   $("#yearReplace").html(yearflh);
}

function mouseMove()
{
   var p         = $("#content");
   var position  = p.position();
   var tPart     = position.top;
   var theight   = tPart - 20;
   var top       = 0;
   var left      = 0;
   var totalImg  = imgList.length;

   if (totalImg > 1)
   {
      $("#replace").bind("mousemove", function(e) {
         var maxHeight = Math.floor($("#proj-details").position().top + theight);
         var maxWidth  = Math.floor($(window).width() - 50);
         var halfPage  = Math.floor($(window).width() / 2);
         if (e.pageX > 40 && e.pageX < maxWidth && e.pageY < maxHeight && e.pageY > tPart)
         {
            if (e.pageX < halfPage)
            {
               top  = e.pageY - tPart + "px";
               left = e.pageX - 40 + "px";
               $("#replace .icon:eq(0)").removeClass('displaynone');
               $("#replace .icon:eq(1)").addClass('displaynone');
               $("#replace .icon:eq(0)").css({'top' : top, 'left' : left});
            }
            else
            {
               top = e.pageY - tPart + "px";
               left = e.pageX + "px";
               $("#replace .icon:eq(0)").addClass('displaynone');
               $("#replace .icon:eq(1)").removeClass('displaynone');
               $("#replace .icon:eq(1)").css({'top' : top, 'left' : left});
            }
         }
         else
            $("#replace .icon").addClass('displaynone');
      });

      $("#replace").bind("click", function(e){
         var maxHeight = Math.floor($("#proj-details").position().top + theight);
         var maxWidth  = Math.floor($(window).width() - 50);
         var halfPage  = Math.floor($(window).width() / 2);
         if (e.pageX > 40 && e.pageX < maxWidth && e.pageY < maxHeight && e.pageY > tPart)
         {
            if (e.pageX < halfPage)
               imageChange("prev", $("#targetAsset").attr("class"));
            else
               imageChange("next", $("#targetAsset").attr("class"));
         }
      });

      $("#replace").bind("mouseleave", function() {
         $("#replace .icon").addClass('displaynone');
      });
   }
}