$(document).ready(function() {

	$("#people").fadeIn("fast", function() {
		$("#subtitle").fadeIn();
	});

	$(".rowTitle:even").attr("style", "width:70px;");
	$(".formRow:even").attr("style", "width:260px;")
	$(".rowInputContainer").fadeTo("fast", 0.75);	
	
	$(".formRow input").focus(function() {
		$(this).parent().fadeTo("fast", 1.0);
	});
	
	$(".formRow input").blur(function() {
		amt = ($(this).val().replace(/\s/g, '').length > 0) ? "0.5" : "0.75";
		$(this).parent().fadeTo("fast", amt);
	});
	
	$("input[id^='bday']").focus(function() {
		$(".active").each(function() {
			$(this).fadeOut("fast");
			$(this).removeClass("active");
		});
		omgHideShit();
		$("#popUpGuide").show();
		$("#bday" + $(this).attr("id").replace(/bday/, "") + "Box").fadeIn(301);
		$("#bday" + $(this).attr("id").replace(/bday/, "") + "Box").addClass("active");
		$("#pageBlinds").fadeTo(1, 0.6, function() {
		  $("#pageBlinds").animate({ height: $(document).height() }, 300);	
		});
	});
	
	$("#stateInput").focus(function() {
	  $(".active").each(function() {
		  $(this).fadeOut("fast");
		  $(this).removeClass("active");
	  });
	  omgHideShit();
		$("#popUpGuide").show();
		$("#stateSelect").fadeIn(301);
		$("#stateSelect").addClass("active");
		$("#pageBlinds").fadeTo(1, 0.8, function() {
		  $("#pageBlinds").animate({ height: $(document).height() }, 300);	
		});
	});
	$("#genderInput").focus(function() {
	  $(".active").each(function() {
		  $(this).fadeOut("fast");
		  $(this).removeClass("active");
	  });
	  omgHideShit();
		$("#popUpGuide").show();
		$("#genderSelect").fadeIn(301);
		$("#genderSelect").addClass("active");
		$("#pageBlinds").fadeTo(1, 0.6, function() {
		  $("#pageBlinds").animate({ height: $(document).height() }, 300);	
		});
	});
	
  $("div[id^='bday'] a").hover(
	  function () { $(this).animate({ backgroundColor: "#454344" }, 200); },
	  function () { $(this).animate({ backgroundColor: "#343233" }, 200); }
	);
	
	$("div[id$='Select'] a").hover (
		function () { $(this).animate({ backgroundColor: "#454344" }, 200); },
	  function () { $(this).animate({ backgroundColor: "#343233" }, 200); }
	);
	
	$("#bdayDayBox a").click(function() {
		$("#bdayDay").attr("value", $(this).html());
		$("#bdayDayBox").fadeOut("fast");
	});
	
	$("#bdayMonthBox a").click(function() {
		$("#bdayMonth").attr("value", $(this).html().substr(0, 3));
		$("#bdayMonthBox").fadeOut("fast");
	});
	
	$("#bdayYearBox a").click(function() {
		$("#bdayYear").attr("value", "19" + $(this).html().replace(/'/, ""));
		$("#bdayYearBox").fadeOut("fast");
	});
	
	$("#stateSelect a").click(function() {
		$("#stateInput").attr("value", $(this).html());
		$("#stateSelect").fadeOut("fast");
	});
	
	$("#genderSelect a").click(function() {
		$("#genderInput").attr("value", $(this).html().toLowerCase());
		$("#genderSelect").fadeOut("fast");
	});
	
	$("#voteDiv").click(function(e) {
		e.stopPropagation();
	});
	
	$("#pageBlinds").click(function(e) {
		$(".active").each(function() {
			$(this).fadeOut("fast");
			$(this).removeClass("active");
		});
		$(this).animate({ height: "1px" }, function() {
			$(this).fadeTo("fast", 0.0);
		});
		$("#popUpGuide").hide();
	});
	
	$("#popUpGuide").click(function() {
		$(".active").each(function() {
			$(this).fadeOut("fast");
			$(this).removeClass("active");
		});
		$("#pageBlinds").animate({ height: "1px" }, function() {
			$("#pageBlinds").fadeTo("fast", 0.0);
		});
		$(this).hide();
	});	
	
});

function omgHideShit() {
	document.getElementById('genderSelect').className = '';
	document.getElementById('bdayMonthBox').className = '';
	document.getElementById('bdayDayBox').className   = '';
	document.getElementById('bdayYearBox').className  = '';
	document.getElementById('stateSelect').className  = '';
}

var content = new Array();
function toggleField(id) {
	var e    = document.getElementById("inner_" + id);
	var n    = content.length;
	var f    = null;
	for(i=0;i<n;i++) {
    if(content[i][0] == id) {
	    var active_content = content[i][1];
			$("#edit_" + id).fadeOut("normal", function() {
				e.innerHTML = active_content;
				$("#view_" + id).fadeIn("normal");
			});
			content.splice(i, 1);
			return true;
    }
	}
	
	content[content.length] = new Array(id, e.innerHTML);
	$("#view_" + id).append(" &nbsp; <img src=\"http://situationdigital.com/auditions/img/loading.gif\" alt=\"Loading...\" />");
	$.post("/account/edit/details/" + id, function(data) {
		$("#view_" + id).fadeOut("normal", function() {
		  e.innerHTML = data;
		  $("#edit_" + id).fadeIn("normal");
		});
	});
	
}

var editContent = new Array();
function edit(id) {
	var e    = document.getElementById(id);
	var n    = editContent.length;
	var f    = null;
	for(i=0;i<n;i++) {
    if(editContent[i][0] == id) {
	    var active_content = editContent[i][1];
			$("#edit_" + id).fadeOut("normal", function() {
				e.innerHTML = active_content;
				$("#view_" + id).fadeIn("normal");
			});
			editContent.splice(i, 1);
			$("#" + id + "_toggle").html("edit");
			return true;
    }
	}
	
	editContent[editContent.length] = new Array(id, e.innerHTML);
	$("#view_" + id).append(" &nbsp; <img src=\"http://situationdigital.com/auditions/img/loading.gif\" alt=\"Loading...\" />");
	$.post("/account/edit/details/" + id, function(data) {
		$("#" + id + "_toggle").html("cancel");
		$("#view_" + id).fadeOut("normal", function() {
		  e.innerHTML = data;
		  $("#edit_" + id).fadeIn("normal");
		});
	});
	
}

function checkSearch(obj) {
	if (obj.value == "Enter a name") { obj.value = ''; }
}

function repopulateSearch(obj) {
	if (obj.value.length == 0 ) { obj.value = "Enter a name"; }
}

function pop(url, w, h) {
	id = new Date().getTime();
  window.open(url, 'pop' + id, 'toolbar=0, scrollbars=1, location=0, statusbar=0, menubar=0, resizable=1, width=' + w + ', height=' + h);
}
