$(document).ready(function() {
	function bindHover() {
		$("#listJobs .jobsBy").hover( 
			function() {
				var dropdown = $(".job_dropdown", this);
				if (dropdown.is(":visible")) {
						dropdown.slideUp(400);
				} else {
						dropdown.slideDown(400);
						$("#listJobs h4").removeClass("active");
						$(this).children("h4").addClass("active");
				}	
			},
			function () {
			   $(".job_dropdown", this).slideUp(400);
			   $("#listJobs h4").removeClass("active");
			}
		 ); 
	}
	bindHover();
	
	$("#listJobs .pagination-more, #listJobs .pagination-back").live("click", function() {
		var container = $(this).parents(".job_dropdown:first");
		var containerID = container.attr("id");
		var childContainerID = '#'+containerID+'_content';
		var nextURL = $(this).attr("href");
		$("#listJobs .jobsBy").unbind();
		$("body").append('<div id="tempContainer"></div>');
		container.prepend('<div class="loading"></div>');
		$('.loading').fadeIn("slow", function() {
			$(childContainerID).hide(200, function() {
				$("#tempContainer").load(nextURL+' #'+containerID+' '+childContainerID,'', function() {
					$(this).children("div:first").css("display", "none");
					$(".loading").fadeOut("fast", function() {
						newContainer = $(this).parent();
						var newContent = $("#tempContainer").html();
						newContainer.html(newContent);
						$(childContainerID).show(200, function() {
							$(childContainerID).bind("mouseover", function() {
								bindHover();
								$(this).unbind();
							});
						});
//						var tSlide = setTimeout(function() {$(newContainer).slideUp(500)}, 2000);
						$(this).remove();
						$("#tempContainer").remove();
					});
				});
			});
		});
		return false;
	 });
	$("#listJobs .job_dropdown").hide();
});
