// JavaScript Document
$(document).ready(function () {
		
	$(".job:odd").css("background-color", "#FFEE9C"); //all odd jobs are yellow
	$(".job_info:nth-child(3n)", this).css({
			fontWeight:  'bold'
		});
	$("#content_text p:first").css({ paddingTop: 0, marginTop: 0 });
	
	//This function opens and closes the job info panel
	$("#job_listings .job").click( function() { //slide function for job divs
		$(".job_detail", this).slideToggle("slow");
	}); 
	
	//This function creates the style for the info bar at the top of the info panel
	$("#job_listings .job").toggle( function () {
		$(".job_essentials", this).wrap('<div class="background_shade" />'); //appends the background style
		$(".job_info", this).css({ //sets the text to yellow
			color:  '#FFD200'
			});
		$(".job_info:first", this).css({//first child is white
			color:  '#FFF'
			});
		$(".job_info:last", this).css({//flast child is white
			color:  '#FFF'
		});
	}, function () {
		$(".job_essentials", this).unwrap(); //upon toggling the click background style is removed
		$(".job_info", this).css({
			color:  '#002D62', //colors are set back to normal
			fontWeight: 'normal'
			});
		
	});
	
	$("#employer_login").click(function (){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
		//load login.php
		$("#contactArea").load('login.php', function () {
			
				//establishes actions necessary for password recovery.
				
				$('#get_password').bind('click', 
					function() {
						$("#login_right").load("get_password.php", 
							function() {
								$('#password_button').bind('click',
									function(data) {
										$.get("password_recovery.php", { email: $("#email").val() },
										 function(data2) {
											
											if(data2=="")
											{
												$("#message").html("<span>Error: Email is not in database. Please register a new account for that email.</span>"); //gives error if no data
											}
											else
											{
												$("#message").html(data2); //lets user know email has been sent
											}
									
									});
							});
					});
				});	
				
			//login button functionality is established
			$('#login_button').click(function() {
			  	$.get("login_action.php", { user: $("#login_name").val(), password: $("#login_password").val() },
				   		function(data){
							if(data=="")
							{
								$("#message").html("<span>Error: Username or Password is incorrect. Please try again.</span>"); //gives error if no data
							}
							else
							{
								$("#message").html("Welcome, " + data); //welcome message 
								$("#popupContact").delay(800).fadeOut("fast", function() { //fadeout login box
									disablePopup(); //close pop-up box
									$("#login_option").load('logout_link.php', function() { 
										$("#employer_logout").click( function() {
											$.get("logout_action.php", function () {
												window.location = 'index.php';
											});
										});
									}); //reload top links to show log out link
									
								});
							}
						});
				});
			
			});
		
	});
	
	$("#employer_logout").click( function() {
		$.get("logout_action.php", function () {
			window.location = 'index.php';
		});
	});
	
	
	$(".delete").click(function (e) {
		e.stopPropagation();
	});
					
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function()
	{
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function()
	{
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e)
	{
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
	}
	
	});
	
	
});
