/**
 / THIRD FUNCTION
 * getPageSize() by quirksmode.com
 * LIGHTBOXOS FELUGRÓ ABLAKOKHOZ SZÜKSÉGES BELSŐ FÜGGVÉNY
 *
 * @return Array Return an array with page width, height and window width, height
 */
function ___getPageSize2() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
};


/** PONTOK ÚJRATÖLTÉSE FELHASZNÁLÓNÁL/ANONYMUSNÁL **/
creditReLoad = function() {
	$('#users_credit').load('ajaxLoader.php?pg=getUserCredit');
}



/** FELUGRÓ ABLAK FELHASZNÁLÓ BELÉPÉSEKOR **/
loginPopup = function() {

	$('body').append('<div id="full-overlay"></div>');
	$('body .mainWrapper').append('<div class="status"><div class="status_content"></div><a href="javascript:void(0);" class="button black" id="status_close">' + aText['close'] + '</a></div>');

	var arrPageSizes = ___getPageSize2();

	$('#full-overlay').css({
		backgroundColor:	'#000',
		opacity:			0.5,
		width:				arrPageSizes[0],
		height:				arrPageSizes[1]
	}).fadeIn();


	$('.status_content').load('ajaxLoader.php?pg=login_success');

	/**  LOGIN ÜDVÖZLŐ SZÖVEG ELREJTÉS A BAZÁRRA KATTINTVA  **/
	$("#status_close").bind('click', function() { 
		$('.status').remove();
		$('#full-overlay').fadeOut(function() { $('#full-overlay').remove(); });
	});

}


/** FELUGRÓ ABLAK ANONÍMUS BELÉPÉSEKOR **/
loginPopupTest = function() {
	
	$('body').append('<div id="full-overlay"></div>');
	$('body .mainWrapper').append('<div class="status"><div class="status_content"></div><a href="javascript:void(0);" class="button black" id="status_close">' + aText['close'] + '</a></div>');

	var arrPageSizes = ___getPageSize2();
	
	$('#full-overlay').css({
		backgroundColor:	'#000',
		opacity:			0.5,
		width:				arrPageSizes[0],
		height:				arrPageSizes[1]
	}).fadeIn();

	$('.status_content').html(aText['login_test_text']);

	/**  LOGIN ÜDVÖZLŐ SZÖVEG ELREJTÉS A BAZÁRRA KATTINTVA  **/
	$("#status_close").bind('click', function() { 
		$('.status').remove();
		$('#full-overlay').fadeOut(function() { $('#full-overlay').remove(); });
	});
	
	
}



$(document).ready(function() {
	

	/**  PÓTJÁTÉK MEGNYITÁS ÉS BEZÁRÁS  **/
	$("#re_game_close").click(function() {
		$('.information').fadeOut('slow');
	});

	$("#re_game").click(function() {
		$('.information').fadeIn('slow');
	});
	
	
	/**  REGISZTRÁCIÓS DIV  **/
	$("#registration_link").click(function() {
		
		$('.registration').load('ajaxLoader.php?pg=registration_form', function() {
			
	    	$(".close-btn").click(function() {
		        $(".registration").css('display', 'none');
			});
	    	
	    	
	    	$("#registration_form_submit").bind('click', function() { 
	    		regFormSubmit();
	    	});
	    	
		});
        
		$(".registration").css('display', 'block');
        $(".registration").css('zIndex', '1000');
        
	});
	
	
	/**  ADATMÓDOSÍTÁS DIV - ugyanúgy a .registration class-ba töltődik be, de a datamodify tartalom  **/
	$("#datamodify_link").click(function() {
		
		$('.registration').load('ajaxLoader.php?pg=datamodify_form', function() {
			
	    	$(".close-btn").click(function() {
		        $(".registration").css('display', 'none');
			});
	    	
	    	
	    	$("#registration_form_submit").bind('click', function() { 
	    		regFormSubmit();
	    	});
	    	
	    	$("#registration_delete").bind('click', function() {
	            if ( confirm('' + aText['reg_delete_confirm']) ) {
	                window.location = "reg_delete.php";
	            }
	    	});
	    	
		});
        
		$(".registration").css('display', 'block');
        $(".registration").css('zIndex', '1000');
        
	});
	
	
	
	/**  ELFELEJTETT JELSZÓ DIV  **/
	$("#forgot_link").click(function() {
		
		$('.forgot').load('ajaxLoader.php?pg=forgot_form', function() {
			
	    	$("#forgot_close").click(function() {
		        $('.forgot').fadeOut('slow');
			});

	    	$("#forgot_form_submit").bind('click', function() { 
	    		forgotFormSubmit();
	    	});
	    	
		});
        
		$('.forgot').fadeIn('slow');
        
	});

	
	
	/**  GYORS MEGHÍVÓ DIV  **/
	$("#quick_invitation_link").click(function() {
		
		$('.quick_invitation').load('ajaxLoader.php?pg=quick_invitation_form', function() {
			
	    	$("#quick_invitation_close").click(function() {
		        $('.quick_invitation').fadeOut('slow');
			});

	    	$("#quick_invitation_form_submit").bind('click', function() { 
	    		quickinvitationFormSubmit();
	    	});
	    	
		});
        
		$('.quick_invitation').fadeIn('slow');
        
	});



	/*******************************************************************************************************************/
	/**  JÁTÉK JÁTÉK JÁTÉK JÁTÉK JÁTÉK JÁTÉK JÁTÉK JÁTÉK JÁTÉK JÁTÉK JÁTÉK JÁTÉK JÁTÉK JÁTÉK JÁTÉK JÁTÉK JÁTÉK JÁTÉK  **/
	/*******************************************************************************************************************/
	
	/**  JÁTÉK NAPOK DIV BETÖLTÉSE FŐOLDALON  **/
	

	resultReLoad = function() { $('#result_div').load('ajaxLoader.php?pg=result', function() {
			
		
			/** MAI NAP -> MEHET A JÁTÉK **/
	    	$(".play_today").bind('click', function() {

	    		
	    		$('body').append('<div id="full-overlay"></div>');
	    		$('body .mainWrapper').append('<div class="question-box"></div>');
	    		
	    		var arrPageSizes = ___getPageSize2();
	    		
				$('#full-overlay').css({
					backgroundColor:	'#000',
					opacity:			0.5,
					width:				arrPageSizes[0],
					height:				arrPageSizes[1]
				}).fadeIn();
				
	    		/**  JÁTÉK DIV KATTINTÁSRA  **/
	    		$('.question-box').html('<div style="text-align:center; padding-top:20px; padding-bottom:20px;"><img src="images/loading.gif" width="160" height="24" alt="" /></div>');
	    		$('.question-box').load('ajaxLoader.php?pg=play&day=' + $(this).attr("id"), function() {
	    			
	       	    	$("#game_form_submit").bind('click', function() {
	    	    		gameFormSubmit();
	    	    	});
	    	    	
	    		});
	    		
	    	});

	    	
	    	
	    	/** MÚLTBELI IDŐPONT -> KOCKA DOBÁS **/
	    	$(".play_past").bind('click', function() {
	    		
	    		var dice_result = "";
	    		var act_day = $(this).attr("id");
	    		
	    		
	    		$.ajax({
	    			url : "dice_generator.php?day="+act_day,
	    			type : "GET",
	    			dataType: 'text',
	    			cache : false,
	    			async: false,

	    			success : function(data) {
	    				dice_result = data;
	    			}
	    		});

	    		$('body').append('<div id="full-overlay"></div>');
	    		$('body .mainWrapper').append('<div id="dicedrop"></div>');
	    		
	    		var arrPageSizes = ___getPageSize2();
	    		
				$('#full-overlay').css({
					backgroundColor:	'#000',
					opacity:			0.5,
					width:				arrPageSizes[0],
					height:				arrPageSizes[1]
				}).fadeIn();
	    		
	    		diceroll = function() {

	    			$('#dicedrop').remove();

	    			if ( dice_result == "6" ) {
	    				
			    		/**  JÁTÉK DIV KATTINTÁSRA  **/
	    				$('body .mainWrapper').append('<div class="question-box"></div>');
	    				
			    		$('.question-box').html('<div style="text-align:center; padding-top:20px; padding-bottom:20px;"><img src="images/loading.gif" width="160" height="24" alt="" /></div>');
			    		$('.question-box').load('ajaxLoader.php?pg=play&day=' + act_day, function() {
			    			
			       	    	$("#game_form_submit").bind('click', function() {
			    	    		gameFormSubmit();
			    	    	});
			    	    	
			    		});

	    			}
	    			else {
	    				
	    	    		$('body .mainWrapper').append('<div class="status2"><div class="status_content2"></div></div>');
	    				
	    				$('.status_content2').html(aText['dicedrop_bad']);
	    			
	    				$(".status2").delay(2000).fadeOut(500, function() {
	    					$('.status2').remove();
	    					$('#full-overlay').fadeOut(function() { $('#full-overlay').remove(); });
	    					resultReLoad();
	    				});
	    				
	    			}

	    		};
	    		
	    		
	    		var flash_support = false;
	    		var flashvars = {};
	    		var attributes = {};
	    		var params = {};
	    		
	    		params.allowscriptaccess = "always";
	    		params.scale = "Showall";
	    		params.quality = "high";
	    		params.bgcolor = "989898";

	    		flashvars.num = dice_result;

	    		
	    		
	    		
				function outputStatus(e) {
			        flash_support = e.success;
			        
			        if ( !flash_support ) {
			        	
				            var js_dice_image_src = "images/dice/dobas" + dice_result + ".gif"

			        		function dice_action() {
			    				$("#dicedrop").fadeIn().delay(6000).fadeOut(500, function() {
			    					diceroll();
			    				});
			        		}

				            $("#dicedrop").css('display', 'none');
			        		$('#dicedrop').html('<img name="js_dice_image_name" src="" name="js_dice_image" width="232" height="96" />');
			        		
			        		document.images.js_dice_image_name.src = js_dice_image_src;
			        		document.images.js_dice_image.onload = dice_action();

                     }
			    }

	    		
	    		
	    		swfobject.embedSWF("dice.swf", "dicedrop", "232", "96", "9.0.0", "dice.swf", flashvars, params, attributes, outputStatus);
	    		
	    	});
	    	
	    	
	    	
	    	/** MÁR LEJÁTSZOTTA **/
	    	$(".play_ok").bind('click', function() {
	    		
	    		$('body').append('<div id="full-overlay"></div>');
	    		$('body .mainWrapper').append('<div class="status2"><div class="status_content2"></div></div>');
	    		
	    		var arrPageSizes = ___getPageSize2();
	    		
				$('#full-overlay').css({
					backgroundColor:	'#000',
					opacity:			0.5,
					width:				arrPageSizes[0],
					height:				arrPageSizes[1]
				}).fadeIn();

				
				$('.status_content2').html(aText['play_ok']);
			
				$(".status2").delay(2000).fadeOut(500, function() {
					$('.status2').remove();
					$('#full-overlay').fadeOut(function() { $('#full-overlay').remove(); });
					resultReLoad();
				});
				
	    	});
	    	
	    	
	    	/** NEM JÁTSZHAT MOST **/
	    	$(".play_bad").bind('click', function() {
	    		
	    		$('body').append('<div id="full-overlay"></div>');
	    		$('body .mainWrapper').append('<div class="status2"><div class="status_content2"></div></div>');
	    		
	    		var arrPageSizes = ___getPageSize2();
	    		
				$('#full-overlay').css({
					backgroundColor:	'#000',
					opacity:			0.5,
					width:				arrPageSizes[0],
					height:				arrPageSizes[1]
				}).fadeIn();

				
				$('.status_content2').html(aText['play_bad']);
				
				$(".status2").delay(2000).fadeOut(500, function() {
					$('.status2').remove();
					$('#full-overlay').fadeOut(function() { $('#full-overlay').remove(); });
					resultReLoad();
				});
				
	    	});

	    	
	    	/** a JÁTÉKHOZ LÉPJ BE **/
	    	$(".play_today_noright").bind('click', function() {
	    		
	    		$('body').append('<div id="full-overlay"></div>');
	    		$('body .mainWrapper').append('<div class="status2"><div class="status_content2"></div></div>');
	    		
	    		var arrPageSizes = ___getPageSize2();
	    		
				$('#full-overlay').css({
					backgroundColor:	'#000',
					opacity:			0.5,
					width:				arrPageSizes[0],
					height:				arrPageSizes[1]
				}).fadeIn();

				
				$('.status_content2').html(aText['play_noright']);
				
				$(".status2").delay(2000).fadeOut(500, function() {
					$('.status2').remove();
					$('#full-overlay').fadeOut(function() { $('#full-overlay').remove(); });
					resultReLoad();
				});
				
	    	});
	    	
	    	
	    	/** a JÁTÉKHOZ LÉPJ BE **/
	    	$(".play_past_noright").bind('click', function() {
	    		
	    		$('body').append('<div id="full-overlay"></div>');
	    		$('body .mainWrapper').append('<div class="status2"><div class="status_content2"></div></div>');
	    		
	    		var arrPageSizes = ___getPageSize2();
	    		
				$('#full-overlay').css({
					backgroundColor:	'#000',
					opacity:			0.5,
					width:				arrPageSizes[0],
					height:				arrPageSizes[1]
				}).fadeIn();

				
				$('.status_content2').html(aText['play_noright']);
				
				$(".status2").delay(2000).fadeOut(500, function() {
					$('.status2').remove();
					$('#full-overlay').fadeOut(function() { $('#full-overlay').remove(); });
					resultReLoad();
				});
				
	    	});
	    	
	    	
	    	creditReLoad();
	    	
	    	
		});

	

	}
	
	/** Főoldalon fut csak le, mert ott (mert ott létezik a div csak) **/
	resultReLoad();
	

	/** Mindenhol lefut, ha be vagyunk lépve (mert akkor létezik a span) **/
	creditReLoad();
	
	
});


function show_preview(id,img)
{
	var position = $('#'+id).position();
	var x_pos = position.left + 35;
	var y_pos = position.top + 25;
	//var position = $('#'+id).position();
	//alert(x_pos+', '+y_pos);
	
	if (img)
	{
		y_pos -=img.height;
		$('#preview')
			.html('<img src="'+img.src+'" class="img">')
			.css({display: 'block', top: y_pos+'px', left: x_pos+'px'});
	}
	
}

function hide_preview()
{
	$('#preview').css('display','none');
}

function getAbsPos( oId, tl ) {
	var o = ( typeof oId == 'String' ) ? document.getElementById( oId ) : oId;
	var val = 0;
	while ( o.nodeName != "BODY" ) {
		val += parseInt( ( tl == 'top' ) ? o.offsetTop : o.offsetLeft );
		o = o.parentNode;
		}
	return val;
	}

