// JavaScript Document
$(function(){
	
	$(window).load(function(){
		//Get original article heights and then give each a unique id
		var articleHeights = new Array();
		$('.editorial article, .keywordTown article').each(function(i) {
			var theHeight = $(this).height();
			articleHeights[i] = theHeight;
			$(this).attr("id",i);
		});
							
		//Default Height
		var defaultHeight = 212 + "px";
	
		//Set the article Divs to appropriate heights
		$('.editorial article, .keywordTown article').css({ "overflow":"hidden", "height": defaultHeight });
		
		//Slide to the original heights and back
		$(".editorial a, .keywordTown a").click(function(e){
			e.preventDefault();
			var articleID = $(this).prev().attr("id");
			if ($(this).hasClass("open")){
				$(this).removeClass("open");
				$(this).prev().animate({ height:defaultHeight },function(){
					$(this).next().text("Click here to Continue Reading");
				});
			} else {
				$(this).addClass("open");
				$(this).prev().animate({ height:articleHeights[articleID] + "px" },function(){
					$(this).next().text("Click here to Finish Reading");
				});
			}
		});
	});
	
	//results next/previos functionality
	var moveAmount = 400;
	var currentAmount = 0;
	var liWidths = 0;
	
	$(".detailsBarWrapper ol > li").each(function(){
		liWidths += $(this).outerWidth();
	});
	
	$(".previousScroll a").attr("id","disabled");
	
	
	$(".previousScroll a").click(function(e){
		e.preventDefault();
		if (currentAmount != 0){
			$(".nextScroll a").removeAttr("id");
			$("#jobDetailFooter ol").animate({ "margin-left": "+=" + moveAmount + "px" }, "slow");
			currentAmount -= moveAmount;
		}
		if (currentAmount == 0){
			$(".previousScroll a").attr("id","disabled");
		}
	});
	
	$(".nextScroll a").click(function(e){
		e.preventDefault();
		$(".previousScroll a,.nextScroll a").removeAttr("id");
		if (currentAmount < liWidths - 400){
			$("#jobDetailFooter ol").animate({ "margin-left": "-=" + moveAmount + "px" }, "slow");
			currentAmount += moveAmount;
		}else {
			$(".nextScroll a").attr("id","disabled");
		}
	});
	
});
