var galReverse = false;
function nowPlaying() {
	$.get(
		'/active/nowplaying.php',
		function(data) {
			//alert(data);
			$('#now-playing').html(data);
			if (data.length < 15) {
				document.getElementById('now-playing').className = 'np-invisible';
			} else {
				document.getElementById('now-playing').className = 'np-visible';
			}
			// $('#now-playing-inner').fadeOut();
			// document.getElementById('now-playing').innerHTML = data;
			//$('#now-playing-inner').fadeIn();
			setTimeout("nowPlaying()",15000);
		}
	);
}
function tinyCam() { 
	var rand = Math.floor(Math.random() * 9123412);
	$('#tinycam a').fadeOut();
	$.get(
		'/active/tinycam.php?rand='+rand,
		function(data) {
			$('#tinycam').html(data);
			
			if (data.length < 15) {
				document.getElementById('tinycam').className = 'tc-invisible';
			} else {
				document.getElementById('tinycam').classname = 'tc-visible';
			}
			$('#tinycam a').fadeIn();
			setTimeout("tinyCam()", 15000);
		}
	);
}
function isBoxUp(theBox) {
	$.get(
		'/active/pingbox.php?id='+theBox,
		function(data) {
			if (data.match(/BOX_IS_ALIVE/)) {
				$('#boxstatus_'+theBox).html('Y');
			} else {
				$('#boxstatus_'+theBox).html('N');
			}
		}
	);
}
function loadPage(thepage) { 
	var pageName = new String(thepage);
	if (pageName.match(/^[a-z]{3,10}$/)) {
		$.get(
			'/active/'+pageName+'-active.php',
			function(data) {
				$('#content-main').html(data);
				$('#content-loading').slideUp();
				$('#content-main').slideDown();
				if (document.getElementById('content-main').innerHTML == '') { 
					jAlert('This page is not done yet.', 'HAHA too bad, sucker.');
				}
				if (pageName == 'photos') {
					$('.photo-select a').tipsy({ gravity: 's' });
				}
				if (pageName == 'boxen') {
					var theBoxString = new String(document.getElementById('box-count').value);
					var theBoxen = theBoxString.split(':');
					for (i = 0; i < theBoxen.length; i++) {
						isBoxUp(theBoxen[i]);
					}
				}
			});
	} else return;
}
function gallerySwap(theImage) {
	var imgBase = '/getimage.php?type=page&filename=';
	if (!galReverse) {
		galReverse = true;
		$('#photo-1').fadeOut(function() {
			document.getElementById('image-2').src=imgBase+theImage;
			document.getElementById('image-1').src='';
			$('#image-2').load(function() {
				$('#photo-2').fadeIn();
			});
		});
	} else {
		galReverse = false;
		$('#photo-2').fadeOut(function() {
			document.getElementById('image-1').src=imgBase+theImage;
			document.getElementById('image-2').src='';
			$('#image-1').load(function() {
				$('#photo-1').fadeIn();
			});
		});
	}
}
function Login() { 
	$('#content-main').slideUp();
	$('#content-loading').slideDown();
	$.post(
		'/active/admin/do-login.php',
		{
			username:	escape(document.getElementById('f_user').value),
			password:	escape(document.getElementById('f_pass').value),
			random:		Math.floor(Math.random()*910324)
		},
		function(data) {
			if (data.match(/LOGIN_FAILURE/)) {
				jAlert('Stop trying to hack my site, asshat.', 'Login failed!');
			} else if (data.match(/DATABASE_FAILURE/)) {
				jAlert('Error accessing user database.', 'Login failed!');
			} else {
				$('#content-main').html(data);
			}
			$('#content-main').slideDown();
			$('#content-loading').slideUp();
		}
	);
}
function admin_logOut() { 
	$('#content-main').slideUp();
	$('#content-loading').slideDown();
	$.post(
		'/active/admin/do-logout.php',
		{
			random:		Math.floor(Math.random()*912340)
		},
		function(data) { 
			window.location='/';
		}
	);
}
