	var curJob = '', preJob = '', showModal = '', preModal = '';
	var preActive = 'menu-date-all';
	var curLoaded = 0, curTotal = 0, stopShort = true;
	var doneLoading = false, preMenu = '', preSubMenu = '', showSub = false;
	var dateRange = 0;companyFiltersArray = [];
	var allCompanyButtons = '';var allCompaniesArray = [];

	if (companyBox != ''){
		companyFiltersArray.push(companyBox);
	}

	if (jobID != ''){
		dateRange = 4;
	}
	function getJobs(curCount){
		if(curCount == 0){
			//reset stuff
				$("#pager_jobs_list").html('<div align="center" id="tempLoader"><br /><br /><img src="/img/load_new.gif" width="200px" height="20px" /><br />loading...</div>');
				$("#full_job_area").html('<div align="center"><br /><br /><img src="/img/load_new.gif" width="200px" height="20px" /><br />loading...</div>');
				curLoaded = 0;curTotal = 0, stopShort = true;doneLoading = false
		}
		
		var url = "/custScripts/getJobsSearch.php"; // the script where you handle the form input.
		$.ajax({
		   type: "POST",
		   url: url,
		   data: {cL: curCount, dR: dateRange, cF: companyFiltersArray, qB: questionBox, lB: locationBox}, 
		   success: function(receiveData){
			   curLoaded = curLoaded+receiveData['jobsSent'];
			   //get rid of our loader gif
			   $("#tempLoader").remove();
			   var curContent = $("#pager_jobs_list").html();
			   curContent = curContent + receiveData['jobsList'];
			   
			   $("#pager_jobs_list").html(curContent);
			   //turn the more jobs check on again
			   stopShort = true;
			   //did we run out of jobs?
			   if(Number(receiveData['jobsSent']) < 50){doneLoading = true;}
			   //open the first job in the list if the window is big enough
			   if(Number(curLoaded) < 51 && Number(curLoaded) != 0){
					var clickFirst = $(".click-button:first").attr('id');
					$("#full_job_area").html('<div align="center">No job selected.</div>');
					if ($(window).width() > 973) {
						if(jobID != ''){
							showDetails(jobID);
						}else{
							showDetails(clickFirst.substring(4));
						}
					}
				}
					//create/add-to company array
					allCompanyButtons = '';
					//loop new retrieved companies and check for new ones
					for (var k in receiveData['companyList']){
						if (!allCompaniesArray.hasOwnProperty(k)) {
							//add it
								allCompaniesArray[k] = receiveData['companyList'][k]; 
						}
					}
					//create/add-to companies buttons from our "totals" array
					for (var k in allCompaniesArray){
						if (allCompaniesArray.hasOwnProperty(k)) {
							var l = '';
							var idx = $.inArray(k, companyFiltersArray);
							if (idx == -1) {
							  l='';
							} else {
							  l=' class="cat-sub-active"';
							}
							allCompanyButtons = allCompanyButtons + '<a id="'+k+'" onclick="toggleCompany(\''+k+'\')"'+l+'>'+allCompaniesArray[k]+'</a>';
						}
					//show them
					$("#smCompany").html(allCompanyButtons);
				
				}
			}
		});
	}
	
	function showDetails(whichJob){
		//change background color of current job
			if(preJob != ''){preJob.css('background-color', '#fff');}
			if(preModal != ''){preModal.css('display', 'none');}
			curJob = $("#jid-"+whichJob);
			curJob.css('background-color', '#eff0f1');
		//our modal div
			showModal = $("#hid-"+whichJob);
		//put current job into previous job
			preJob = curJob;
			preModal = showModal;
		//open job view

			$("#full_job_area").html('<div align="center"><img src="/img/load_new.gif" width="200px" height="20px" /><br />loading...<br /><br /></div>');
				var url = "/custScripts/getJobsSearchQuick.php";
				$.ajax({
					type: "POST",
					url: url,
					data: {wJ: whichJob}, // serializes the form's elements.
					success: function(receiveData){
						//show the job
							$("#full_job_area").html(receiveData);
							var hash = '';
							if(document.getElementById('coNameURL') && document.getElementById('coNameURL').innerHTML != ''){
								if(hash == ''){
									hash += document.getElementById('coNameURL').innerHTML;
								}
								else{
									hash += '/' + document.getElementById('coNameURL').innerHTML;
								}
							}
							if(document.getElementById('jobNameURL') && document.getElementById('jobNameURL').innerHTML != ''){
								if(hash == ''){
									hash += document.getElementById('jobNameURL').innerHTML;
								}
								else{
									hash += '/' + document.getElementById('jobNameURL').innerHTML;
								}
							}
							if(document.getElementById('jobIdURL') && document.getElementById('jobIdURL').innerHTML != ''){
								if(hash == ''){
									hash += document.getElementById('jobIdURL').innerHTML;
								}
								else{
									hash += '/' + document.getElementById('jobIdURL').innerHTML;
								}
							}

							window.location.hash = hash;
						//is the screen too small to show the job area?
							if ($(window).width() < 974) {
								//show them the modal popup instead??
									showModal.html(receiveData);
									showModal.show();
									var childTop = showModal.offset().top;
									var parentTop = showModal.parent().offset().top;
									var topOffset = childTop - parentTop;
									$('#gj-flow-list').animate({scrollTop: topOffset}, 800);
									$("#hid-"+whichJob+" .row").css("background-color", "#ff6666").animate({ backgroundColor: "#FFFFFF"}, 1500);
							}
					}
				});
	}
	
	function showSubMenu(which){
		//decide if we are opening or closing a submenu
		if(preMenu != ''){
			//a menu is already open, are we changing or closing?
			if(preMenu != which){
				//we are not closing, we are changing
				$('#'+which).addClass('cat-active');
				$("#sm"+which).css("display", "block");
				$("#sm"+preMenu).css("display", "none");
				$('#'+preMenu).removeClass('cat-active');
				showSub = true;
				preMenu = which;
			}else{
				//we are closing
				showSub = false;
				$('#'+preMenu).removeClass('cat-active');
			}
		}else{
			//opening a new menu
				$('#'+which).addClass('cat-active');
				$("#sm"+which).css("display", "block");
				showSub = true;
				preMenu = which;
		}
		//show or hide submenu container
			if(showSub){$("#cat-menu-sub").slideDown("fast");}else{$("#cat-menu-sub").slideUp("fast");$("#sm"+preMenu).css("display", "none");preMenu = '';}
	}
	
	function toggleCompany(whichCompany){
		//multiple choices can be selected
			$('#'+whichCompany).toggleClass('cat-sub-active');
		//add or remove it from our filter array
			var idx = $.inArray(whichCompany, companyFiltersArray);
			if(idx == -1){companyFiltersArray.push(whichCompany);}else{companyFiltersArray.splice(idx, 1);}
		//refresh jobs
			getJobs(0);
	}
	
	function toggleMenu(whatElement){
		//single menu choice only
			if(preActive != ''){$('#'+preActive).removeClass('sub-date-active');}
			$('#'+whatElement).addClass('sub-date-active');
			preActive = whatElement;
		//set new dateRange
			if(whatElement == 'menu-date-all'){};
			switch(whatElement) {
				case 'menu-date-all':dateRange=0;break;
				case 'menu-date-day':dateRange=1;break;
				case 'menu-date-3day':dateRange=2;break;
				case 'menu-date-week':dateRange=3;break;
				case 'menu-date-month':dateRange=4;break;
			}
		//refresh jobs
			getJobs(0);
	}
	
	//make it happen
	$( document ).ready(function() {
		$("#pager_jobs_list").html('<div align="center" id="tempLoader"><br /><br /><img src="/img/load_new.gif" width="200px" height="20px" /><br />loading...</div>');
		$("#full_job_area").html('<div align="center"><br /><br /><img src="/img/load_new.gif" width="200px" height="20px" /><br />loading...</div>');
		
		//get our first set of jobs
			getJobs(curLoaded,dateRange);
		
			$('#gj-flow-list').on('scroll', function() {
				if(stopShort && !doneLoading){
					//they started scrolling, start to get our next set of jobs
						$("#pager_jobs_list").append('<div align="center" id="tempLoader"><br /><img src="/img/load_new.gif" width="200px" height="20px" /><br />loading more...<br /><br /></div>');
						getJobs(curLoaded,dateRange);
						console.log('here');
					//turn the more jobs check off
						stopShort = false;
				}
			});
	});