var imagesLoaded=0;

function imageLoaded(image)
{
	imagesLoaded++;
	if (imagesLoaded==15)
	{
		yesNo.display();
	}
}

var CYesNo=Class.create(
{
	initialize: function()
	{
		this.timeout=null;
	},
	choose: function()
	{
		result=Math.floor(Math.random() * 10000);
		if (result % 2)
		{
			$('yes_no_positive_result').style.display='';
			$('yes_no_negative_result').style.display='none';
		}
		else
		{
			$('yes_no_positive_result').style.display='none';
			$('yes_no_negative_result').style.display='';
		}
		this.timeout=setTimeout(this.reset.bind(this),5000);
	},
	buttonPushed: function()
	{
		$('yes_no_button').style.display='none';
		this.choose();
	},
	reset: function()
	{
		if (this.timeout)
		{
			clearTimeout(this.timeout);
			this.timeout=null;
		}
		$('yes_no_positive_result').style.display='none';
		$('yes_no_negative_result').style.display='none';
		$('yes_no_button').style.display='';
		
	},
	begin: function()
	{
		hideAll();
		$('yes_no').style.display='none';
		$('ajax_loader').style.display='';
		setTimeout(this.display.bind(this), 500);
	},
	display: function()
	{
		$('yes_no').style.display='';
		$('ajax_loader').style.display='none';
		Element.setOpacity($('yes_no_option'),0.5);
		Element.setOpacity($('coin_option'),1);
		Element.setOpacity($('dice_option'),1);
	}
});


var CCoin=Class.create(
{
	initialize: function()
	{
		this.timeout=null;
	},
	choose: function()
	{
		result=Math.floor(Math.random() * 100);
		if (result % 2)
		{
			$('coin_positive_result').style.display='';
			$('coin_negative_result').style.display='none';
		}
		else
		{
			$('coin_positive_result').style.display='none';
			$('coin_negative_result').style.display='';
		}
		this.timeout=setTimeout(this.reset.bind(this),5000);
	},
	buttonPushed: function()
	{
		$('coin_button').style.display='none';
		this.choose();
	},
	reset: function()
	{
		if (this.timeout)
		{
			clearTimeout(this.timeout);
			this.timeout=null;
		}
		$('coin_positive_result').style.display='none';
		$('coin_negative_result').style.display='none';
		$('coin_button').style.display='';
		
	},
	begin: function()
	{
		hideAll();
		$('coin').style.display='none';
		$('ajax_loader').style.display='';
		setTimeout(this.display.bind(this), 500);
	},
	display: function()
	{
		$('coin').style.display='';
		$('ajax_loader').style.display='none';
		Element.setOpacity($('yes_no_option'),1);
		Element.setOpacity($('coin_option'),0.5);
		Element.setOpacity($('dice_option'),1);
	}
});

var CDice=Class.create(
{
	initialize: function()
	{
		this.timeout=null;
	},
	hideResults: function()
	{
		$('dice_result_1').style.display='none';
		$('dice_result_2').style.display='none';
		$('dice_result_3').style.display='none';
		$('dice_result_4').style.display='none';
		$('dice_result_5').style.display='none';
		$('dice_result_6').style.display='none';
	},
	choose: function()
	{
		result=Math.floor(Math.random() * 6) + 1;
		this.hideResults();
		$('dice_result_' + result).style.display='';
		this.timeout=setTimeout(this.reset.bind(this),5000);
	},
	buttonPushed: function()
	{
		$('dice_button').style.display='none';
		this.choose();
	},
	reset: function()
	{
		if (this.timeout)
		{
			clearTimeout(this.timeout);
			this.timeout=null;
		}
		this.hideResults();
		$('dice_button').style.display='';
		$('dice_image').src="images/dice_unknown.png";
		
	},
	begin: function()
	{
		hideAll();
		$('dice').style.display='none';
		$('ajax_loader').style.display='';
		setTimeout(this.display.bind(this), 500);
	},
	display: function()
	{
		$('dice').style.display='';
		$('ajax_loader').style.display='none';
		Element.setOpacity($('yes_no_option'),1);
		Element.setOpacity($('coin_option'),1);
		Element.setOpacity($('dice_option'),0.5);
	}
});


var yesNo=new CYesNo();
var coin=new CCoin();
var dice=new CDice();


function hideAll()
{
	$('yes_no')	.style.display='none';
	$('coin').style.display='none';
	$('dice').style.display='none';
}

function pageLoaded()
{
//	setTimeout(hideNavigationBar, 100);
//	yesNo.display();
}

function hideNavigationBar()
{
	window.scrollBy(0,1);
}

