// JavaScript Document

$(window).load(function() {		
						
	for (j=1; j<5; j++) {
		$("h"+j).each(function() {
			var a = $(this).get(0);
			var arr = a.innerHTML.split(" ");
			for(i = 0; i < arr.length; i++ ) {
				arr[i] = "<span>" + arr[i].substr(0,1) + "</span>" + arr[i].substr(1);
			}
			a.innerHTML = arr.join(" ");
		});
	}
	
	$("div#empireapp").hide();
	
	$(".left_navlink").parents("li").siblings().hide();
	$(".left_navlink").toggle(function() {
		$(this).parents("li").siblings().show();
	}, function() {
		$(this).parents("li").siblings().hide();
	});
	$("#selected").click();
	
	$("#closeApp").mousedown(function() {
		$("#content_slide").fadeOut("normal");
	});
	
	$("#passcode").keyup(function() {
		var pass_val = $(this).attr("value");
		if(pass_val.toLowerCase() == "chanj86") {
			$("div#content_slide").css("background", "url(http://empiremocktrial.org/public/_img/splash_bg.png) repeat");
			$("div#splash").hide();
			$("div#empireapp").show();
			$(this).attr("disabled", true);
			app("app_1");
		}
									   });
	
	
	$("input").each(function() {
		$(this).focus(function() {
			$(this).css("background-color", "#FFC");
							   });
		
		$(this).blur(function() {
			if($(this).get(0).value.length > 0) {
				$(this).css("background-color", "#CFC");
			}
			var value = $(this).get(0).value;
			var id = $(this).attr("id");
			validate(id, value);
							  });
									   });
	
	$("textarea").each(function() {
		$(this).focus(function() {
			$(this).css("background-color", "#FFC");
							   });
		
		$(this).blur(function() {
			if($(this).get(0).value.length > 0) {
				$(this).css("background-color", "#CFC");
			}
			var value = $(this).get(0).value;
			var id = $(this).attr("id");
			validate(id, value);
							  });
									   });
	
	$(".nav_button").each(function() {
		var bg = $(this).css("background");
		$(this).hover(
		function() {
			$(this).css("background", "none");
		}, 
		function() {
			//alert('out');
			$(this).css("background", bg);
		})
		
		$(this).mouseup(
			function() {
			window.location = $(this).attr("id");
		});
						
	});
	
	$(".app_nav").each(function() {
		var bgc = $(this).css("background-color");
		var fc = $(this).css("color");
		$(this).hover(
		function() {
			$(this).css("background-color", "#006");
			$(this).css("color", "#FFF");
		}, 
		function() {
			//alert('out');
			$(this).css("background-color", bgc);
			$(this).css("color", fc);
		}
	);
		
		$(this).mousedown(function() {

			$(".app_nav").each(function() {
				$(this).css("border", "1px solid #FFF");
			});
			
			
			$(this).css("border", "1px solid #006");
			
			var page = $(this).attr("id");
			app(page);
		});
								   });
	
	$("#app_submit").mousedown(function() {
										
		var app_errors = 0
		;
		$("#application input").each(function() {
			if($(this).get(0).value.length == 0) {
				$(this).css("background-color", "#F99");
				app_errors++;
			}
		});
		
		$("#application textarea").each(function() {
			if($(this).get(0).value.length == 0) {
				$(this).css("background-color", "#F99");
				app_errors++;
			}
		});
		
		if(app_errors > 0) {
			alert('Your application is incomplete!');
		} else {
			//$("form#application").submit();
		}
								   });
	
						});
	
	
	function app(page) {
		$("div.app").each(function() {
			if($(this).attr("id") != page) {
				$(this).hide();
			} else {
				$(this).show();
			}
								   });
	
}

$(document).ready(function() {
// REGISTER ACCOUNT AJAX JAVASCRIPT
	
	$("#registerjudge").ajaxForm({
		 target:    '#registerjudgemsg', 
   		 url:       'auth.apply_judge.php', 
  		 type:		'POST'
	});
						   });
