//Card Deck
// deck.js
// copyright Chris Johnson chriso@people.net.au
// JavaScript


var Cards= new Array();
function Deck()
{
     var C="Clubs";
     Cards[0]=  new Card("Cards/cla.png",13,C);
     Cards[1]=  new Card("Cards/cl2.png",1,C);
     Cards[2]=  new Card("Cards/cl3.png",2,C);
     Cards[3]=  new Card("Cards/cl4.png",3,C);
     Cards[4]=  new Card("Cards/cl5.png",4,C);
     Cards[5]=  new Card("Cards/cl6.png",5,C);
     Cards[6]=  new Card("Cards/cl7.png",6,C);
     Cards[7]=  new Card("Cards/cl8.png",7,C);
     Cards[8]=  new Card("Cards/cl9.png",8,C);
     Cards[9]=  new Card("Cards/cl10.png",9,C);
     Cards[10]=  new Card("Cards/clj.png",10,C);
     Cards[11]=  new Card("Cards/clq.png",11,C);
     Cards[12]=  new Card("Cards/clk.png",12,C);
    //Diamonds
    var D = "Diamonds";
     Cards[13]=  new Card("Cards/dia.png",13,D);
     Cards[14]=  new Card("Cards/di2.png",1,D);
     Cards[15]=  new Card("Cards/di3.png",2,D);
     Cards[16]=  new Card("Cards/di4.png",3,D);
     Cards[17]=  new Card("Cards/di5.png",4,D);
     Cards[18]=  new Card("Cards/di6.png",5,D);
     Cards[19]=  new Card("Cards/di7.png",6,D);
     Cards[20]=  new Card("Cards/di8.png",7,D);
     Cards[21]=  new Card("Cards/di9.png",8,D);
     Cards[22]=  new Card("Cards/di10.png",9,D);
     Cards[23]=  new Card("Cards/dij.png",10,D);
     Cards[24]=  new Card("Cards/diq.png",11,D);
     Cards[25]=  new Card("Cards/dik.png",12,D);
    //Hearts
    var H="Hearts";
     Cards[26]=  new Card("Cards/hea.png",13,H);
     Cards[27]=  new Card("Cards/he2.png",1,H);
     Cards[28]=  new Card("Cards/he3.png",2,H);
     Cards[29]=  new Card("Cards/he4.png",3,H);
     Cards[30]=  new Card("Cards/he5.png",4,H);
     Cards[31]=  new Card("Cards/he6.png",5,H);
     Cards[32]=  new Card("Cards/he7.png",6,H);
     Cards[33]=  new Card("Cards/he8.png",7,H);
     Cards[34]=  new Card("Cards/he9.png",8,H);
     Cards[35]=  new Card("Cards/he10.png",9,H);
     Cards[36]=  new Card("Cards/hej.png",10,H);
     Cards[37]=  new Card("Cards/heq.png",11,H);
     Cards[38]=  new Card("Cards/hek.png",12,H);
     //Spades
     var S ="Spades";
     Cards[39]=  new Card("Cards/spa.png",13,S);
     Cards[40]=  new Card("Cards/sp2.png",1,S);
     Cards[41]=  new Card("Cards/sp3.png",2,S);
     Cards[42]=  new Card("Cards/sp4.png",3,S);
     Cards[43]=  new Card("Cards/sp5.png",4,S);
     Cards[44]=  new Card("Cards/sp6.png",5,S);
     Cards[45]=  new Card("Cards/sp7.png",6,S);
     Cards[46]=  new Card("Cards/sp8.png",7,S);
     Cards[47]=  new Card("Cards/sp9.png",8,S);
     Cards[48]=  new Card("Cards/sp10.png",9,S);
     Cards[49]=  new Card("Cards/spj.png",10,S);
     Cards[50]=  new Card("Cards/spq.png",11,S);
     Cards[51]=  new Card("Cards/spk.png",12,S);
 return Cards;
 }
 
 function Shuffle()
 {
  Cards=Deck();
 
 var rd =Math.floor(Math.random()* Cards.length) ;
 
 for(var i=0;i<52;i++)
     {
     var index1=rd;
     var index2=  Math.floor(Math.random()* Cards.length);
     SwapCards(index1,index2);
     }
 return Cards
 }
 
 
 function SwapCards(int1, int2)
    {
        var aCard = Cards[int1];
        Cards[int1]=Cards[int2];
        Cards[int2]=aCard;
     }
 function RemoveAt()
 {
    
    if (Cards.length <5)
    {
    Shuffle();
    }
    var acard=Cards[0]
    Cards.shift();
    return acard;
 }
 function Card(Image,Value, Suite)
 {
    this.Image=Image;
    this.Value=Value;
    this.Suite=Suite;
    this.IsFaceUp=false;
    this.picked=0;
    this.deckValue= deckValue(this.Value,this.Suite);
    return this
 }
 
 function deckValue(value,suit)
 {
    switch (suit)
   { 
    case 'Clubs': 
     return value;
    case 'Hearts':
        return value +=13;
    case 'Spades':
            return value +=26;
    case 'Diamonds':
     return  value +=39;
     }   
 }
