var h;
var th;
var ca = 3;
var intval;

function sethash(hash) {
	if (hash != null) h = hash;
}

function game(gid, gw, gh) {
	$('#modalcontainer').modal({
		close:false,
		position: ["25px",],
		overlayId:'confirmModalOverlay',
		containerId:'confirmModalContainer', 
		onShow: function (dialog) {
			var iframe = '<iframe src ="/game/play/' + gid + '/' + h + '" width="' + gw + '" height="' + (gh + 80) + '" frameborder="0" scrolling="no" id="g_iframe"></iframe>';
			dialog.data.find('.modal_content').html(iframe);
		}
	});
}

function preroll(gid, pw, ph) {
	$('#modalcontainer').modal({
		close:false,
		position: ["25px",],
		overlayId:'confirmModalOverlay',
		containerId:'confirmModalContainer', 
		onShow: function (dialog) {
			var iframe = '<iframe src ="/game/play/' + gid + '/' + h + '" width="715" height="550" frameborder="0" scrolling="no" id="g_iframe"></iframe>';
			dialog.data.find('.modal_content').html(iframe);
		}
	});
}

function feedback(txt, positive, header) {
	$('#feedbackcontainer').modal({
		position: ["45%",],
		overlayId:'feedbackModalOverlay',
		containerId:'feedbackModalContainer', 
		onShow: function (dialog) {
			var ui = '<div class="fb_modal_buttons">';
			ui += '<div class="no modalClose" onclick="$.modal.close();"><img src="/images/buttons/button_close.gif" border="0" style="cursor:pointer; position:absolute; top:5px; right:5px;" /> <span style="font-size:11px; color:#FFF; font-weight:bold;">';

			if (header != '' && header != null) {
				ui += header;
			} else {			
				if (positive == true) {
					ui += 'BEWERKING VOLTOOID';
				} else {
					ui += 'ER HEEFT ZICH EEN FOUT VOORGEDAAN';
				}
			}			
		
			ui += '</span></div></div>';
			ui += '<div class="fb_modal_content"><p>' + txt + '</p></div>';
			$('#feedbackModalContainer').html(ui);
		}
	});
}

function redir(p) {
	document.location.href = p;	
}

function checkEnter(key, obj) {
	var characterCode = key.keyCode;
	if (characterCode == 13) {
		switch(obj) {
			case(1):
				$('#loginForm').submit();
			break;
			case(2):
				$('#form_login').submit();
			break;
		}
	}
}

$(document).ready(function() {
	processSize();
	$(window).resize(function(){
		processSize();
	});
});
	
function processSize() {
	if (checkWidth() <= 935) {
		$('html').css('overflow', 'auto');
	} else {
	//	$('html').css('overflow', 'hidden');
	}
	if (checkHeight() <= 740) {
		$('#gp_container').css('margin', '-95px 0px 0px 0px');
	} else {
		$('#gp_container').css('margin', '0px');
	}
}
	
function checkWidth() {
	if(document.layers) {
		return window.innerWidth;
	} else {
		return document.body.clientWidth;
	}
}

function checkHeight() {
	if(jQuery.browser.msie){
    	return document.documentElement.offsetHeight;
    } else {
		return window.innerHeight;
    }
}

function getHS(gid, page, div){
	var data = '';
	$.post("/game/rankings/" + gid + "/" + page + "/" + div, data, function(ret){
		$('#' + div).html(ret);
	});
}

function getAddress() {
	if ($('#memberZipcode1').val() != '' && $('#memberZipcode2').val() != '' && $('#memberHousenumber').val() != '') {
		try {
		//	intval = setTimeout("unlockFieldsWebservice()", 3000);
			var zip = $('#memberZipcode1').val() + $('#memberZipcode2').val();
			var houseno = $('#memberHousenumber').val();
			var data = '';
			$.post("/member/zip/" + zip + "/" + houseno, data, function(ret) {
				clearInterval(intval);
				var address = new Array();
				if (ret != "false") {
					eval(ret);
					$('#memberAddress').val(address[0]);
					$('#memberCity').val(address[1]);
				}
			});		
		} catch(e) {
			unlockFieldsWebservice();
		}
	}
}

function unlockFieldsWebservice() {
	$('#memberAddress').removeAttr("disabled");
	$('#memberCity').removeAttr("disabled");
	$('#zce').html('&nbsp;');
	$('#memberAddress').css('background-color', '#ffffff');
	$('#memberCity').css('background-color', '#ffffff');
	clearInterval(intval);
}

function scrollGames(dir, max, amt) {
	
	var curx = $('#gp_games_scroll').css('left');
	curx = Number(curx.substring(0, curx.length - 2));
    var step = 100;
    max = Math.round(step / amt);

	switch (dir) {
		case (0): // left
			if (ca > 3) {
		    	$('#gp_games_scroll').animate({ left : "+=" + step + "px"}, 250);
				--ca;
			}
			break;
		case (1): // right
			if (ca < max) {
				$('#gp_games_scroll').animate({ left : "-=" + step + "px"}, 250);
				++ca;
			}
			break;
	}
	
	if (ca == max) {
		$('#gp_scroll_right').css('display', 'none');
	} else {
		$('#gp_scroll_right').css('display', 'block');		
	}
	
	if (ca == 3) {
		$('#gp_scroll_left').css('display', 'none');
	} else {
		$('#gp_scroll_left').css('display', 'block');		
	}

}

function hideClose() {
	$('#modal_buttons').css('display', 'none');
}

function showClose() {
	$('#modal_buttons').css('display', 'block');
}

function hideBanner() {
	$('#b_flash').html('');
}

function expandIframe(w, h) {
	$('#g_iframe').width(w);
	$('#g_iframe').height(h + 80);
}