﻿var _d1;
var _index;

function Deck()
{
	_d1 = new Array(52);
	_index = 0;
	
	// Loop through the array, and set each element to '1';
	// When a card has been selected, the element that represents the card will be set to 0;
}

// This 'Shuffles' the deck.
Deck.prototype.Shuffle = function()
{
	for(i = 0; i < 52; i++)
	{
		_d1[i] = i+1;
	}
}

Deck.prototype.Deal = function()
{
	var r;
	var success = false;
	var i = 0;
	var _card;
	
	if(_d1 != null)
	{
		do
		{
			r = Math.floor(52*Math.random());

			if(_d1[r] > -1) 
			{ 
				success = true; 
			}
			
			i++;
		}while(success != true && i < 53)

		_card = new Card(_d1[r]);		
		_d1[r] = -1;
		
		return _card;
	}
}

