	/*
		Initialization
	*/	
	
	$(document).ready(function() {
		CreateBaloon();
		ValidateForms();
		
		$("#overlay").css({
			width: $(document).width() + 'px',
			height: $(document).height() + 'px'
		});
		
	});
	
	/*
		Registration
	*/
		
	function validateRegistration(f)
	{
		if(validateForm(f)) {
			if(f.f_passwd.value != f.f_passwdd.value) {
				alert("Passwords must be the same!");
				f.f_passwd.value = "";
				f.f_passwdd.value = "";
				return false; 
			} else {
				return true;
			}
		} else return false;
	}
	
	function reloadCaptcha()
	{
		var now = new Date();
		id = "" + now.getTime() + Math.floor(Math.random() * 99999);
		
		$("#captcha")[0].src = '/testimg.php?' + id;
	}
	
	function showLoginBox(id)
	{
		if(id == 'ord') {
			$("#openidlogin").hide();
			$("#openidpoint").removeClass('lbselect');
			$("#openidpoint").addClass('lbnselect');

			$("#ordlogin").show();
			$("#ordpoint").removeClass('lbnselect');
			$("#ordpoint").addClass('lbselect');
		
		} else {
			$("#ordlogin").hide();
			$("#ordpoint").removeClass('lbselect');
			$("#ordpoint").addClass('lbnselect');

			$("#openidlogin").show();
			$("#openidpoint").removeClass('lbnselect');
			$("#openidpoint").addClass('lbselect');
		}
	}
	
	// C & S
	
	function mpInit(obj) {
		var player = $("#mpi")[0];		
		player.addModelListener('STATE', 'stateChanged');
	}
	
	function stateChanged(obj) 
	{
		if(obj.newstate == "PLAYING") {
			$("#overlay").fadeIn();
		} else {
			$("#overlay").fadeOut();			
		}; 
	}
	
	// Live
	function plInit(obj) {
		var player = $("#mpli")[0];
		
		setTimeout( function() {	
			player.sendEvent("PLAY","true");
			setTimeout( function() {
				player.sendEvent("PLAY","false");
				setTimeout( function() {	
					player.sendEvent("PLAY","true");
				}, 1000); 	
			}, 3000);
		}, 1000);
		
	}
	
	
	function controlLive(id, opt)
	{
		var txt = $("#livead").val();

		if(opt == 1) { $("#boff").show(); $("#bon").hide(); };
		if(opt == 2) { $("#boff").hide(); $("#bon").show(); };
		jQuery.get("/index.php?usecase=CommitLive&id=" + id + "&opt=" + opt + "&livead=" + txt, {}, function(data, stat) {
			if(stat == 'success') $("#livead").val('');
		});
		
		return false;
	}
	
	function updateLive(id)
	{
		var b = escape($("#liveborder").html());
		$("#livelog").load("/index.php?usecase=UpdateLive&id=" + id + "&b=" + b, {}, function(res, stat, req) {
			if(stat == 'success') 
				setTimeout("updateLive(" + id + ")", 10000);
			else 
				setTimeout("updateLive(" + id + ")", 30000);
		});
	}
		
	