﻿	function f_clientHeight() {
		return f_filterResults (
			window.innerHeight ? window.innerHeight : 0,
			document.documentElement ? document.documentElement.clientHeight : 0,
			document.body ? document.body.clientHeight : 0
		);
	}
	
	function f_clientWidth() {
		return f_filterResults (
			window.innerWidth ? window.innerWidth : 0,
			document.documentElement ? document.documentElement.clientWidth : 0,
			document.body ? document.body.clientWidth : 0
		);
	}
	
	function f_filterResults(n_win, n_docel, n_body) {
		var n_result = n_win ? n_win : 0;
		if (n_docel && (!n_result || (n_result < n_docel)))
			n_result = n_docel;
		return n_body && (!n_result || (n_result < n_body)) ? n_body : n_result;
	}
	
	/*
	 *  Winning Numbers popup functionality
	 */
	function openWinningNumbers(game){
		var windowWidth = f_clientWidth();
		var windowHeight = f_clientHeight();
		var popupHeight = $("#winningNumbers").height();
		var popupWidth = $("#winningNumbers").width();
		var top = windowHeight/2-popupHeight/2;
		var left = windowWidth/2-popupWidth/2;
		//alert("windowHeight: " + windowHeight + "\npopupHeight: " + popupHeight + "\nwindowHeight/2-popupHeight/2: " + (windowHeight/2-popupHeight/2) + "\ntop: " + top + ", left: " + left);
	
		$("#winningNumbers").css({
			"position": "absolute",
			"top": top,
			"left": left
		});
		
		$("#WinningNumbersMan").css({
			"position": "absolute",
			"top": top - 60,
			"left": left + 220
		});
		
		$("#WinningNumbersClose").css({
			"position": "absolute",
			"top": top,
			"left": left + 508
		});
		
		$("#WinningNumbersLink").css({
			"position": "absolute",
			"top": top + 146,
			"left": left + 294
		});
		
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("fast");
		$("#winningNumbers").fadeIn("fast");
		
		$("#WinningNumbersMan").fadeIn("fast");
		$("#WinningNumbersClose").fadeIn("fast");
		$("#WinningNumbersLink").fadeIn("fast");
		
		//display only the game selected
		if(game=='pbWn') {
			$("#Powerball").css({"display": "block"});
		} else {
			$("#Powerball").css({"display": "none"});
		}
		
		if(game=='mmWn') {
			
			$("#Mega_Millions").css({"display": "block"});
		} else {
			$("#Mega_Millions").css({"display": "none"});
		}
		
		if(game=='p3Wn') {
			$("#Pick_3").css({"display": "block"});
		} else {
			$("#Pick_3").css({"display": "none"});
		}
		
		if(game=='p4Wn') {
			$("#Pick_4").css({"display": "block"});
		} else {
			$("#Pick_4").css({"display": "none"});
		}
		
		if(game=='cbWn') {
			$("#Cash_Ball").css({"display": "block"});
		} else {
			$("#Cash_Ball").css({"display": "none"});
		}
		
		if(game=='dodWn') {
			$("#Decades_of_Dollars").css({"display": "block"});
		} else {
			$("#Decades_of_Dollars").css({"display": "none"});
		}
		
		if(game=='fccWn') {
			$("#5_Card_Cash").css({"display": "block"});
		} else {
			$("#5_Card_Cash").css({"display": "none"});
		}
		
	}
	
	function openAllWinningNumbers(){
		var windowWidth = f_clientWidth();
		var popupWidth = $("#allWinningNumbers").width();
		
		var left = windowWidth/2-popupWidth/2;
		//alert("windowHeight: " + windowHeight + "\npopupHeight: " + popupHeight + "\nwindowHeight/2-popupHeight/2: " + (windowHeight/2-popupHeight/2) + "\ntop: " + top + ", left: " + left);
	
		$("#allWinningNumbers").css({
			"position": "absolute",
			"top": "70px",
			"left": left
		});		
				
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("fast");
		$("#winningNumbers").fadeOut("fast");
		$("#allWinningNumbers").fadeIn("fast");
	}
	
	function closeWinningNumbers() {
		$("#backgroundPopup").fadeOut("fast");
		$("#winningNumbers").fadeOut("fast");
		$("#allWinningNumbers").fadeOut("fast");
		
		$("#WinningNumbersMan").fadeOut("fast");
		$("#WinningNumbersClose").fadeOut("fast");
		$("#WinningNumbersLink").fadeOut("fast");
	}
	
	$(function() {
		$(".xClose").click(function() {
			closeWinningNumbers();
		});
	
		$(".winningNumberBall").click(function() {
			openWinningNumbers($(this).attr("id"));
		});
		
		$(".allWinNums").click(function() {
			closeWinningNumbers();
			openAllWinningNumbers();
		});
		
		$("#winningNumbersBox div.more").click(function() {
			openAllWinningNumbers();
		});
	
		//Click out event
		$("#backgroundPopup").click(function(){ closeWinningNumbers(); });
			//Press Escape event
			$(document).keypress(function(e){
			if(e.keyCode==27){ closeWinningNumbers(); }
		});
	
		$('#mmWn').jrumble({
			rumbleEvent: 'hover',
			rangeX: 10,
			rangeY: 10,
			rangeRot: 4,
			posX: 'left',
			posY: 'top'
		});
	
		$('#pbWn').jrumble({
			rumbleEvent: 'hover',
			rangeX: 10,
			rangeY: 10,
			rangeRot: 4,
			posX: 'left',
			posY: 'top'
		});
	
		$('#p3Wn').jrumble({
			rumbleEvent: 'hover',
			rangeX: 10,
			rangeY: 10,
			rangeRot: 4,
			posX: 'left',
			posY: 'top'
		});
	
		$('#p4Wn').jrumble({
			rumbleEvent: 'hover',
			rangeX: 10,
			rangeY: 10,
			rangeRot: 4
		});
	
		$('#cbWn').jrumble({
			rumbleEvent: 'hover',
			rangeX: 10,
			rangeY: 10,
			rangeRot: 4,
			posX: 'right',
			posY: 'top'
		});
	
		$('#dodWn').jrumble({
			rumbleEvent: 'hover',
			rangeX: 10,
			rangeY: 10,
			rangeRot: 4,
			posX: 'right',
			posY: 'top'
		});
	
		$('#fccWn').jrumble({
			rumbleEvent: 'hover',
			rangeX: 10,
			rangeY: 10,
			rangeRot: 4,
			posX: 'right',
			posY: 'top'
		});		
	});

