var cardsInDeck = 39;
var cardsToDeal = 11;
var cards = new Array(cardsInDeck);
var cardCaptions = new Array(cardsInDeck);
var cardPositions = new Array(cardsToDeal);
var cardsDealt = new Array(cardsToDeal);
var currentCard = 1;

function dealCard(cardNum)
{
	var card = $('card_'+currentCard);
	card.src = 'images/cards/' + cardNum + '.jpg';
	var a = $('a_'+currentCard);
	a.title = cardCaptions[cardNum-1];
	a.href = 'images/cards/big/' + cardNum + '.jpg';
	card.show();
	//update cardsDealt
	var cardsDealt = $('cardsDealt');
	if(cardsDealt.value === '')
		cardsDealt.value = cardsDealt.value + cardNum;
	else
		cardsDealt.value = cardsDealt.value + ',' + cardNum;
	cards = cards.without(cardNum);
	currentCard++;
}

function deckClicked(event)
{
	var deck = event.element();
		var cardNum = cards[(Math.ceil(Math.random()*cards.length))-1];
	dealCard(cardNum);
		//alert('readCookie(\'threeCards\') == '+readCookie('threeCards'));
	if(currentCard > cardsToDeal)
	{
		deck.stopObserving('click', deckClicked);
		deck.hide();
		$('cardsSubmit').show();
	}
}

function mycontextmenu()
{
	alert('Right clicking is disabled');
	return false;
}

function simplePreload()
{
	var args = simplePreload.arguments;
	document.imageArray = new Array(args.length);
	for(var i=0; i<args.length; i++)
	{
		document.imageArray[i] = new Image;
		document.imageArray[i].src = args[i];
	}
}

function init()
{
	var cardsDealt = $('cardsDealt');
	cardsDealt.value = '';
	for(i=0; i<cardsInDeck; i++)
	{
/*		cards[i] = i+1;                                     */
/*		cardCaptions[i] = "Caption " + (i+1) + " here";     */
	}

		cards[0] = "1";
		cardCaptions[0] = "Here is a picture of universal beauty as it reminds us of the rising and setting of the sun.  All mankind in whichever part of the world we live in, are in awe and wonder at the beauty of these scenes each morning and evening.  Actually this card represents the Father of Creation as Divine Light. Many religions see 'God' or the Supreme Being as light.";
		cards[1] = "2";
		cardCaptions[1] = "Here a lotus flower is seen open. It is beautiful and fragrant. Lotus flowers sit still on top of pond water. Its beautiful head follows the direction of the sun and at night it closes its petals in until the next morning.";
		cards[2] = "3";
		cardCaptions[2] = "A person is seen here sitting on a cloud.  He is in meditation.  Mediation is another way of thinking, of using thoughts in a particular way that brings calm, peace and stillness. This calm brings clarity of thought and through this it is as though a bottomless treasure box is opened. The benefits are endless. This person is shown sitting in clouds because it helps him to feel on top of the world.";
		cards[3] = "4";
		cardCaptions[3] = "In this card there is an additional eye shown in the centre of the forehead and it is larger than the other two eyes. It is portrayed as large, open and bright. As one might expect if we had an additional eye we would literally be able to see more. Actually this third eye is about looking within - insight, a deeper understanding of things.";
		cards[4] = "5";
		cardCaptions[4] = "The lighthouse stands tall, strong, powerful and mighty. It is a life saver. Its primary purpose is to send light out to ships in danger on dark stormy nights. The lighthouse enables the ships to find a safe course back to land, avoiding rocks and other dangers. They have an incredibly powerful light that is perfect for the job.";
		cards[5] = "6";
		cardCaptions[5] = "A wheel is seen in this picture, representing the wheel that is ever turning.  It indicates that time never stands still that it moves on slowly but surely.  It says that your wheel of good fortune is turning for you bringing about better circumstances.";
		cards[6] = "7";
		cardCaptions[6] = "A tree is seen here growing beautifully strong. It is fertile and green. It is firmly rooted in the soil and Earth. It is fresh and green and has many uses. A tree indiscriminately provides shade, fruit and wood which in turn makes so many useful things. Tropical rainforests provide us with essential oxygen. Without these forests life as we know it would cease to exist. Trees and wood are beautiful. They are emblems of generosity.";
		cards[7] = "8";
		cardCaptions[7] = "In this picture there are three worlds. The Earth and the physical universe that we experience through our senses and that can be measured and investigated by the established scientific schools. Beyond the physical world is a subtle region - a realm inhabited by angels. We each of us individual are protected by our own guardian angel and can sometimes experience this in dreams. Sometimes we are looked after by higher order angels when the need arises. Beyond that is the Soul World where all souls have their eternal home. This World is a still world that never changes, and it will never change. This world cannot be detected or measured by physical, scientific instruments as it is a spiritual world made of spiritual matter.";
		cards[8] = "9";
		cardCaptions[8] = "Here is an open door beyond which is glowing golden light. There are stars and colourful tassels floating through the air.  The door feels as though it is inviting us through - almost as though exciting adventures await us. This is a doorway of golden opportunity. Create what you would like to have!";
		cards[9] = "10";
		cardCaptions[9] = "A girl is sitting here quietly thinking in a place where she can visualize her dreams and goals.  She feels connected to the energy of the universe, at one with all things, and thinks about her own special unique role, which only she can play as there is no other quite like her.";
		cards[10] = "11";
		cardCaptions[10] = "An elderly gentleman is holding out his hand offering a bright, special star to some young children.  They are eager to take this star from him because they have a sense of some special significance in this gift.  The full moon, luminous in the background provides a bright, but lesser light than the sun, giving a clue to the true identity of this man who appears seemingly ordinary.";
		cards[11] = "12";
		cardCaptions[11] = "A woman holds the Earth in her arms as though it is a new born babe.  She not only is a carer for human beings, but she cares for the environment too.  She plays a significant role in the healing and cleansing of our planet.";
		cards[12] = "13";
		cardCaptions[12] = "Here are shown an Emperor and an Empress of the World. Their status is above that of kings and queens. They own a huge empire. They have everything in abundance and are short of nothing. They rule together in total harmony.";
		cards[13] = "14";
		cardCaptions[13] = "This card shows a golden palace at a time when everything is absolutely perfect. Everything works in complete order. A place where there are no problems, no worries and no dangers.  It signifies a time of reward and celebration. There is no thought of any end to the pleasure of this place.  It is heaven or paradise.  Nature works in complete harmony.  It is a land of peace.  The lion and the lamb can drink together side by side by the lake.";
		cards[14] = "15";
		cardCaptions[14] = "The moon is seen here with a smiling face. In Crete the &quot;man in the moon&quot; can clearly be seen as a smiling face and that is exactly what this card depicts. A time when things are cheerful and joyful.";
		cards[15] = "16";
		cardCaptions[15] = "This card shows copper coins stacked up on a wooden table.  It pertains to physicality and matters relating to money.  Coins are being given rather than received as this relates to being generous and charitable.";
		cards[16] = "17";
		cardCaptions[16] = "The earth in its 4th stage of development comes under pressure from the sheer volume of the expansion of activities taking place. Populations are at their largest and therefore so are demands on all the earths' resources. In our known history, there have never been the demands being placed on the Earth as there are today.";
		cards[17] = "18";
		cardCaptions[17] = "This card shows four sections relating to time (like 4 seasons). Each has its and its value as explained in the preceding four cards. This card is the most significant in this series as it represents now. It represents not only the end of the cycle of time (before renewal) but also a confluence of the old age with the new.  The clock shows five minutes to midnight which can also be interpreted as the end of the 11th hour!";
		cards[18] = "19";
		cardCaptions[18] = "There is a golden cup sparkling in the light. It is pristine and it is polished. It is beautiful. Inside it is clean and clear.";
		cards[19] = "20";
		cardCaptions[19] = "Two Sisters are seen here delighting in each others' company. They are deeply engrossed in conversation with each other.  There is no effort required to see the friendliness in their interaction.";
		cards[20] = "21";
		cardCaptions[20] = "A beautiful angel is seen here dancing on a cloud.  She is an image of joy and happiness and for good reason.  She doesn't see problems because she does not judge.  She simply gives help where it is needed to the degree which is needed without imposition.";
		cards[21] = "22";
		cardCaptions[21] = "A child is seen here happy and free. He is completely absorbed in playing with his little toy. He hasn't a care in the world.  He playfully works out how his world works.";
		cards[22] = "23";
		cardCaptions[22] = "The huge planet of Jupiter is seen here glowing as it confidently occupies its place in our solar system.  It is big, bright and beautiful.  It has a diameter that is 11 times the size of the Earth's.";
		cards[23] = "24";
		cardCaptions[23] = "Two brothers are shown together talking shaking hands as though in agreement with each other. The spotlight is in each of them observing the choices they are making.";
		cards[24] = "25";
		cardCaptions[24] = "There is a suitcase all packed up neatly and ready to go.  Everything is fitted nicely into its place. It is sitting on fertile green grass against a blue sky, fluffy white clouds sailing by on a gently blowing breeze.";
		cards[25] = "26";
		cardCaptions[25] = "A large group of people are seen here waiting in a queue.  They seem to be aware that it is a long queue, but they know that the wait will be worth it.  The longer we wait for something which we desire the higher we perceive its value.    Notice that the queue is not straight it is windy here and there. Just like the journey throught life!";
		cards[26] = "27";
		cardCaptions[26] = "A river is shown here running into the ocean.  An ocean is such a huge expanse of water, that when small rivers run into it, it makes little difference to the ocean.  The mighty ocean simply accommodates all the little trickles which run into it.";
		cards[27] = "28";
		cardCaptions[27] = "A set of scales are shown here in balance.  Balanced judgment leads to more accurate decisions.  Decision making is a very important aspect of our lives which help us to determine the kind of people we are and the direction which we want to go in.";
		cards[28] = "29";
		cardCaptions[28] = "A jeweller is seen in his shop surrounded by jewels.  Some are real and some are imitation.  Real jewellery is valued much more highly than imitation. On sight much of the imitation jewellery looks so much like the real jewellery that it is difficult to tell them apart.";
		cards[29] = "30";
		cardCaptions[29] = "There are people here stricken with grief in attendance at a funeral service.  Their heads are bent down as they pay their last respects to the departed soul.  As the body is laid to rest, there will be a time of accepting and letting go of the past.  What is needed is courage, openness and hope.  Hope is the thing that makes us completely human.  Without it we would not survive.  Always hope for good things to come - then they will.";
		cards[30] = "31";
		cardCaptions[30] = "Two hands are outstretched pointing towards one another in a friendly gesture. They say many hands make light work; the more there are co-operating in a task, the more quickly the task can be accomplished.";
		cards[31] = "32";
		cardCaptions[31] = "A Tortoise is seen here quite happily going along in his daily life.  He is crawling along at his own pace in his garden on a summer day.  Flowers are in bloom and he gives the impression of not having a care in the world.";
		cards[32] = "33";
		cardCaptions[32] = "Here is the ladder simply sits waiting to be climbed.  It is a symbol of an upward journey.  Ordinarily - if we wanted to go up somewhere we would get up according to our own determination. Here it is like being the gift of a lift!";
		cards[33] = "34";
		cardCaptions[33] = "One can see a bamboo flute that has musical notation in the background indicating that there is music being played.  Beautiful music is harmonious.  There is also a rainbow of bright and beautiful colours in the background.  Everyone's spirits are lifted when beautiful music is played.  We forget our ordinary everyday lives and can feel transported to different realms, inaccessible in our normal consciousness.";
		cards[34] = "35";
		cardCaptions[34] = "Here is a picture of a king.  He is king of his castle  He wears his crown, and holds his sceptre and is dressed in finery fitting for a king.  He is a leader, in complete control of his world.";
		cards[35] = "36";
		cardCaptions[35] = "Here a queen is seen standing outside of her palatial residence.  All is well in her world as she enjoys being outdoors in her garden on this warm summer's day.  She feels the warmth of the sun on her face and smells the fragrant odours from nearby flowers and herbs, billowing around her in the wind.";
		cards[36] = "37";
		cardCaptions[36] = "There is a beautiful white swan gliding along on a river.  There is clear open water which he is free to swim around in.  He holds his majestic head in the air confident of his grace and beauty. Because he is honest, he does not worry about looking over his shoulder.  He has inner cleanliness as his conscience is clear.";
		cards[37] = "38";
		cardCaptions[37] = "A magnificent white horse has spread its wings in flight as it traverses the universe knowing no boundaries and free to go where it will. It is able to cross over physical boundaries being able to enter the angelic and spiritual realms. Just as a baby bird knows there is a time when he must spread his wings and fly, so too does one who has achieved a state of mastery know that it is time to soar.";
		cards[38] = "39";
		cardCaptions[38] = "A palette can be seen with an array of bright beautiful colours.  There is the paintbrush ready to create a masterpiece.  The rainbow background showing harmony is all set allowing the painter to create what he will.";

	document.oncontextmenu = mycontextmenu;
	if(readCookie('threeCards') != null)
	{
		//deal previously dealt cards
		var threeCards = readCookie('threeCards').split(',');
		for(var i=0; i<threeCards.length; i++)
			dealCard(threeCards[i]);
				eraseCookie('threeCards');
			}
	var deck = $('deck');
	deck.src = 'images/cards/deck.gif';
	deck.show();
	deck.observe('click', deckClicked);
}
