var numDebugWrites = 1;
function debugWrite( toWrite ) {
	$("#jsDebug").html( $("#jsDebug").html() + "<p>" + numDebugWrites + ": " + toWrite + "</p>" );
	numDebugWrites++;
}

//Initialize the possible colors
var colors = new Array( 3 );
//colors[0] = "#E4403C"
colors[0] = "#B0BA25";
//colors[0] = "#868e1c"; // (darker green)
colors[1] = "#F9A11B";
//colors[1] = "#8d5b0f"; // (darker orange)
colors[2] = "#4DC3CE";
/*colors[0] = "#E4403C";
colors[1] = "#94D5D6";
colors[2] = "#F9A11B";
colors[3] = "#B0BA25";
colors[4] = "#FAF39D";
colors[5] = "#FDBC3B";
colors[6] = "#4DC3CE";
*/
// Function that runs when the DOM is prepared
function domReady() {
	// Set all anchors' mouseover events
	var colorIndex = Math.floor( Math.random() * colors.length );
	$("a:not(.noAutoColour)").each( function() {
		$(this).css( "color", colors[colorIndex] )
		colorIndex++;
		if( colorIndex >= colors.length )
			colorIndex = 0;
	});
	
}

$(document).ready( domReady );




function cycleColorsHandler( event ) {
	var anchorText = "asdf";
	var $elm = $(event.target);
	if( event.target.tagName == "A" ) {
		if( null == $elm.attr( "linkText" ) )
			$elm.attr( "linkText", $elm.text() );
		anchorText = $(event.target).attr( "linkText" );
	}
	else
		anchorText = $(event.target).parent().attr( "linkText" );
	//debugWrite( anchorText );
	var buildText = "";
	for( var i = 0; i < anchorText.length; i++ ) {
		buildText = buildText + "<span style='color: ";
		buildText = buildText + colors[Math.floor( Math.random() * colors.length )];
		buildText = buildText + "'>" + anchorText.charAt(i);
		buildText = buildText + "</span>";
	}

	if( event.target.tagName == "A" )
		$(event.target).html( buildText );
	else
		$(event.target).parent().html( buildText );
}

function openGmap() {
	myRef = window.open( "./ajax/gMap.php", "gMap",
		'left=20,top=20,width=450,height=375,scrollbars=yes, menubar=no');
}

// Admin functions
function logOut() {
	debugWrite( "clicked" );
	$.post( "./ajax/log_out.php", { username: "admin" });
	
	window.location.reload();
}

