<?xml version="1.0" encoding="UTF-8"?>
<Module>
<ModulePrefs title="Match Blox" 
title_url="http://sites.google.com/site/jimrgarrison/" 
screenshot="http://sites.google.com/site/jimrgarrison/gadgetfiles/matchblox_screenshot.png" thumbnail="http://sites.google.com/site/jimrgarrison/gadgetfiles/matchblox_thumbnail.png" height="250" width="250" directory_title="Match Blox" description="An addictive and fun game. Click on matching color blocks to clear the screen." author="Jim Garrison" author_email="jimrgarrison@gmail.com" author_affiliation="http://sites.google.com/site/jimrgarrison/" author_location="San Antonio, TX" category="funandgames" />
<Content type="html"><![CDATA[
<script language="javascript">
<!--
function begin() {
  off0 = new Image();
  off0.src = "http://hosting.gmodules.com/ig/gadgets/file/106137054980310914756/black.gif";
  off1 = new Image();
  off1.src = "http://hosting.gmodules.com/ig/gadgets/file/106137054980310914756/1off.gif";
  off2 = new Image();
  off2.src = "http://hosting.gmodules.com/ig/gadgets/file/106137054980310914756/2off.gif";
  off3 = new Image();
  off3.src = "http://hosting.gmodules.com/ig/gadgets/file/106137054980310914756/3off.gif";
  on0 = new Image();
  on0.src = "http://hosting.gmodules.com/ig/gadgets/file/106137054980310914756/black.gif";
  on1 = new Image();
  on1.src = "http://hosting.gmodules.com/ig/gadgets/file/106137054980310914756/1on.gif";
  on2 = new Image();
  on2.src = "http://hosting.gmodules.com/ig/gadgets/file/106137054980310914756/2on.gif";
  on3 = new Image();
  on3.src = "http://hosting.gmodules.com/ig/gadgets/file/106137054980310914756/3on.gif";
  total = 0;
  winner = 0;
  bottom = new Array();
  n = 0;
  for (i = 0; i < 15; i++) {
    bottom[i] = n;
    n += 10;
  }
  head = new Array();
  n = 9;
  for (i = 0; i < 15; i++) {
    head[i] = n;
    n += 10;
  }
  main = new Array();
  for (i = 0; i < 150; i++) {
    main[i] = random();
  }
       // writeAd();
  startUp();
}

function random() {
  ballCount = 3;
  randomNum = Math.floor((Math.random() * ballCount));
  randomNum++;
  return randomNum;
}

function onBall(numba) {
  if (main[numba] != 0) {
    crayon = main[numba];
    findAdjacent(numba);
    if (adj.length > 1) {
      for (n = 0; n < adj.length; n++) {
        document["img" + adj[n]].src = eval("on" + crayon + ".src");
           }
        }
   }
}

function offBall(numba) {
  if (main[numba] != 0) {
    crayon = main[numba];
    findAdjacent(numba);
    if (adj.length > 1) {
      for (n = 0; n < adj.length; n++) {
        document["img" + adj[n]].src = eval("off" + crayon + ".src");
           }
        }
   }
}

function clickBall(numba) {
  if (main[numba] != 0) {
    findAdjacent(numba);
    if (adj.length > 1) {
      for (n=0; n<adj.length; n++) {
        main[adj[n]] = 0;
      }
      slideBalls();
      startUp();
      total = (adj.length - 2) * (adj.length - 2) + total;
      document.scores.show.value = total;
      winTotal = total + 1000;
      if (checkWinner()) {
         document.scores.message.value = "          ** You Won! **" 
          document.scores.restart.disabled = false
        winner = 1;
      }
      q = 0;
      checkLoser();
      if (q == 60 && winner == 0) {
         document.scores.message.value = "    Game Over - Try Again"
         document.scores.restart.disabled = false
          }
    }
     }
}

function checkLoser() {
  if (q == 60) {
    return true
  }
  if (main[q] != 0) {
    if (smallAdjacent(q)) {
      return false;
       }
  }
  q++;
  checkLoser();
}

function checkWinner() {
  if (main[0] == 0) {
    return true;
   }
}


function smallAdjacent(numba) {
  isBottom = 0;
  isHead = 0;
  for (n = 0; n < 20; n++) {
    if (numba == head[n]) {
      isHead = 1;
       }
  }
  for (n = 0; n < 20; n++) {
    if (numba == bottom[n]) {
      isBottom = 1;
       }
  }
  if (main[numba + 1] == main[numba] && isHead != 1) {
    return true;
  }
  if (main[numba + 10] == main[numba]) {
    return true;
  }
  if (main[numba - 1] == main[numba] && isBottom != 1) {
    return true;
  }
  if (main[numba - 10] == main[numba]) {
    return true;
  }
  return false;
}

function slideBalls() {
  change = 0;
  for (i = 0; i < 15; i++) {
    blankCount = 0;
    column = new Array();
    newColumn = new Array();
    for (c = 0; c < 10; c++) {
      column[c] = main[c + change];
    }
    for (c = 0; c < 10; c++) {
      if (column[c] == 0) {
        blankCount++;
        newColumn[10-blankCount] = 0;
      } else {
        newColumn[c - blankCount] = column[c];
         }
    }
    for (c = 0; c < 10; c++) {
      main[c + change] = newColumn[c];
    }
    if (blankCount == 10) {
      for (c = change; c < 150; c++) {
        main[c] = main[c + 10];
      }
      for (c = 140; c < 150; c++) {
        main[c] = 0;
      }
      change -= 10;
    }
    change += 10;
     }
}

function startUp() {
    var responseText = '';
    
    responseText = responseText + '<table border=0 cellpadding=0 cellspacing=0 bgcolor=black align=center>';

    for (i = 9; i > -1; i--) {
  n = i;
  for (c = 0; c < 15; c++) {
    if (n < 10) {
      responseText = responseText + '<tr>';
    }
  responseText = responseText + '<td><a href=javascript:clickBall(' + n + ') onmouseover=onBall(' + n + ') onmouseout=offBall(' + n + ')><img src=http://hosting.gmodules.com/ig/gadgets/file/106137054980310914756/black.gif height=16 width=16 name=img' + n + ' border=0></a></td>';
  n=n+10;
  }
   }

   responseText = responseText + '</tr><tr><td colspan=15 align=center bgcolor=#FFFFFF><form name=scores>';
   responseText = responseText + '<input type=text name=message readonly size=25 /><br />Score:&nbsp;<input type=text name=show size=5 value=0 onFocus=blur() />';
   responseText = responseText + '&nbsp;&nbsp;<input name=restart type=button value=Start Game onclick=begin() />';
   responseText = responseText + '</form></td></tr><tr><td colspan=15 align=center bgcolor=#FFFFFF>';
   responseText = responseText + '</td></tr></table>';   
   _gel("mainContainer").innerHTML = responseText;
   document.scores.show.value = 0;
   for (i = 0; i < main.length; i++) {
  crayon = main[i];
  document["img" + i].src = eval("off" + crayon + ".src");
    }
    document.scores.restart.disabled = true;
    document.scores.message.value = "   Remove Matching Blocks"
   
}

function findAdjacent(numba) {
  adj = new Array();
  adj[0] = numba;
  i = 0;
  c = 0;
  findAdjacent2(adj[c]);
}

function findAdjacent2(numba) {
  isBottom = 0;
  isHead = 0;
  for (n = 0; n < 20; n++) {
    if (numba == head[n]) {
      isHead = 1;
       }
  }
  for (n = 0; n < 20; n++) {
    if (numba == bottom[n]) {
      isBottom = 1;
       }
  }
  if (main[numba+1] == main[numba] && isHead != 1 && isAdjacent(numba+1)) {
    i++;
    adj[i] = numba + 1;
  }
  if (main[numba+10] == main[numba] && isAdjacent(numba+10)) {
    i++;
    adj[i] = numba + 10;
  }
  if (main[numba-1] == main[numba] && isBottom != 1 && isAdjacent(numba-1)) {
    i++;
    adj[i] = numba - 1;
  }
  if (main[numba-10] == main[numba] && isAdjacent(numba-10)) {
    i++;
    adj[i] = numba - 10;
  }
  c++;
  if (c == adj.length) {
    blah = 500;
  } else {
    findAdjacent2(adj[c]);
   }
}

function isAdjacent(numba) {
  isAdj = 1
  for (n=0; n<adj.length; n++) {
    if (adj[n] == numba) {
      isAdj = 0
    }
  }
  if (isAdj == 1) {
    return true;
  } else {
    return false;
     }
}
function writeAd() {
var r_text = new Array ();
r_text[0] = '<a href=http://84f52hp8uhmm0f4sp-sqxt0q4z.hop.clickbank.net/?tid=GGADGET>The Diet Solution</a>';
r_text[1] = '<a href=http://84f52hp8uhmm0f4sp-sqxt0q4z.hop.clickbank.net/?tid=GGADGET>Burn Fat Fast</a>';
r_text[2] = '<a href=http://84f52hp8uhmm0f4sp-sqxt0q4z.hop.clickbank.net/?tid=GGADGET>Fast and Easy Fat Loss</a>';
var i = Math.round(2*Math.random());
_gel("adContent").innerHTML = "<font size=-1>" + r_text[i] + "</font>";
}
//-->
</script>
<script language="JavaScript">
<!--
  _IG_RegisterOnloadHandler(begin);
//-->
</script>
<div id="mainContainer"></div>
<div align="center" id="adContent"></div>
]]></Content>
</Module>


