// Copyright 2005 Jim Radford <radford@blackbean.org> All rights reserved. -*- c -*- 
function foundation(div,game){generic_foundation.prototype.init.call(this,div,game);this.accept_stacks=true;this.old_accept=this.accept;this.accept=function(cards){return cards.length==13?this.old_accept(cards):0;}}
foundation.prototype=new generic_foundation();function tableau(div,game){pile.prototype.init.call(this,div,game);this.accept_stacks=true;this.accept=function(cards){return(this.pile.length==0?1:0)||(in_suit_order(cards[0],this.top())?3:0)||(in_numeric_order(cards[0],this.top())?2:0);};this.drag_order=game.game=="spider"?in_suit_order:game.game=="tarantula"?in_color_order:game.game=="black widdow"?in_numeric_order:undefined;this.can_drag=function(index){return in_order_by(this.drag_order,this.pile,index);};this.splice=this.splice_and_turn_over;this.xoffset=0;}
tableau.prototype=new pile();function stock(div,game){pile.prototype.init.call(this,div,game);this.accept=function(card){return false;};this.can_drag=function(index){return false;};this.xoffset=.3;this.yoffset=.3;this.maxstack=54;}
stock.prototype=new pile();function game(){pile_game.prototype.init.call(this,this.game);this.decks=2;this.stock=new stock("stock",this);this.foundation=[];for(var i=1;i<=8;i++)
this.foundation.push(new foundation("good"+i,this));this.tableau=[];for(var i=1;i<=10;i++)
this.tableau.push(new tableau("tableau"+i,this));this.deal=function(deck){this.stock.pile=deck;for(var c=0;c<54;c++)
this.tableau[c%this.tableau.length].push(this.stock.pop());for(var i in this.tableau)
this.tableau[i].top().face=up;};var me=this;this.stock.onclick=function(){if(!me.stock.pile.length)return;for(var i=0;i<me.tableau.length;i++)
if(me.tableau[i].pile.length==0)
return;me.push_state();for(var i=0;i<me.tableau.length;i++)
if(me.stock.pile.length){me.stock.top().face=up;me.stock.move_to_pile(me.stock.top_index(),1,me.tableau[i]);}};}
game.prototype=new pile_game();game.prototype.game="spider";game.prototype.is_complete=function(){for(var i in this.foundation)
if(this.foundation[i].pile.length!=13)
return NOT_COMPLETE;return WON;}
