<?xml version="1.0"?>
<bindings xmlns="http://www.mozilla.org/xbl" 
          xmlns:xbl="http://www.mozilla.org/xbl" 
          xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

<binding id="target_box">
  <implementation>
    <field name="initialisedCard">0</field>

    <method name="checkWin">
      <body><![CDATA[
        // template is always in "start_place"
	if (document.getElementById("start_place").childNodes.length == 1){
	   win = true;
           // template is at i=0
	   for (i=1; i<this.childNodes.length; i++){
             if (!this.childNodes[i].check()){
	        win = false;
		break;
		}
	   }
	   if (win){
		smile = document.getElementById("smile");
		smile.smile(true);
	   }
	}
      ]]></body>
    </method>
  </implementation>
</binding>

<binding id="target_stack">
  <implementation>
    <constructor><![CDATA[
	this.setpos();
    ]]></constructor>

    <method name="check">
      <body><![CDATA[
	if (this.childNodes.length ==2)
	   return (this.childNodes[1].id == this.id);
	else
	   return false;
      ]]></body>
    </method>

    <method name="setpos">
      <body>
        <![CDATA[

       card = this.parentNode.initialisedCard;

       n_col = card % columns;
       n_line = (card - n_col) / columns;

       this.parentNode.initialisedCard++;

       this.setAttribute("left", n_col*150 + 120);
       this.setAttribute("top", n_line*150 + 120);

        ]]>
      </body>
    </method>

    <method name="dragReceive">
    <parameter name="element"/>
    <body>
        dest = document.getElementById("start_place");

	if (this.childNodes.length == 2){
	   dest.appendChild(this.removeChild(this.childNodes[1]));
	}

	element.parentNode.removeChild(element);
	this.appendChild(element);

	this.parentNode.checkWin()

        return true;
    </body>
  </method>
  </implementation>
</binding>

</bindings>
