var Deck = new Class({
	
	//implements
	Implements: [Options],

	//options
	options: {
		id: 0,
		cardsPerDeck: 52,
		numDecks: 1,
		numjokers: 0
	},
	
	Cards: new Array(),
	
	
	//initialization
	initialize: function(options) {
		this.setOptions(options);
		
		this.reloadCards();
	},
	
	
	// Shuffle the cards
	shuffleCards: function(value) {
		this.Cards.shuffle();
	},
	

    // Return the top card
	hasNext: function() {
		return this.Cards.length;
	},


    // Return the top card
	getNext: function() {
		return this.Cards.shift();
	},
	

    // Return the top card
	cut: function() {
		var cutCard = this.Cards.getRandom();
		
		this.Cards.erase(cutCard);
		cutCard.setCut(true);
		
		return cutCard;
	},
	
	
	initCards: function() {
		for (var c=0; c<(this.options.cardsPerDeck*this.options.numDecks)+this.options.numjokers; c++) {
			this.Cards[c].setValues();
		}
	},
	
	
	reloadCards: function() {
		this.Cards.empty();
		
		// Add the cards for each deck
		for (var c=0; c<this.options.cardsPerDeck*this.options.numDecks; c++) {
			this.Cards.push(new Card({value: c}));
		}
		
		// Add the Jokers
		for (var c=1; c<this.options.numjokers+1; c++) {
			this.Cards.push(new Card({value: -1*c}));
		}
		
		this.initCards();
		//console.log(this.Cards);
	},

    
    getCardById: function(id) {
		var ret = null;
		
		for (var c=0; c<this.Cards.length; c++) {
			if (this.Cards[c].getId() == id) {
				ret = this.Cards[c];
			}
		}
				
		return ret;
    },
    
    
    findJokers: function() {
    	var ret = Array();
    	
		for (var c=0; c<this.Cards.length; c++) {
			if (this.Cards[c].getId() < 0 || this.Cards[c].getId() > this.options.cardsPerDeck*this.options.numDecks) {
				ret.push(this.Cards[c]);
			} 
		}
		
		return ret;
    }
});

