

var scInc = 915;
var scSlides = 5;
var scCurrentSlide = 1;
var scAnimating = false;

var scSliderShowOn = true;
var scSliderShowTimeout = 10 * 1000;
var scSliderShowPause = false;

function scSlide () {
		$("div#slider").clearQueue();
		scAnimating = true;
		$("div#slider-nav").hide();
		$("div#slider").animate({
			scrollLeft: (scCurrentSlide)*scInc
		}, 700, function () {
			if (scCurrentSlide < 1) {
				scCurrentSlide = scSlides;
				$("div#slider").scrollLeft(scCurrentSlide * scInc);
			}
			if (scCurrentSlide > scSlides) {
				scCurrentSlide = 1;
				$("div#slider").scrollLeft(scCurrentSlide * scInc);
			}
			$("div#slider-nav").show();
			scAnimating = false;
		});
}

function scPrev () {
	if (!scAnimating) {
		scSliderShowOn = false;
		scCurrentSlide--;
		scSlide();
	}
}

function scNext () {
	if (!scAnimating) {
		scSliderShowOn = false;
		scCurrentSlide++;
		scSlide();
	}
}

function scSlideShow() {
	if (scSliderShowOn) {
		if (!scSliderShowPause) {
			scCurrentSlide++;
			scSlide();
		}
		setTimeout("scSlideShow()", scSliderShowTimeout);
	}
}

$(document).ready(function() {
		
	$("div#slider").scrollLeft(scCurrentSlide * scInc);
													 
	$("div#slider-nav a#prev").click(function(e) {
		scPrev();
		e.preventDefault();
	});

	$("div#slider-nav a#next").click(function(e) {
		scNext();
		e.preventDefault();
	});

	// pause slider while mouseover showcase
	$("div#slider").hover (
		function () {
			scSliderShowPause = true;
		},
		function () {
			scSliderShowPause = false;
		}
	);
	
	// start the slideshow
	setTimeout(scSlideShow, scSliderShowTimeout);
	
	// social media tooltips
	$("div#social-media div a").each(function () {
		$(this).tipTip({defaultPosition: "top", maxWidth: "auto", edgeOffset: 15, delay: 0});
	});
	
	$("div#home-content a").hover(
	  function () {
			$(this).find("div.bar").animate({
				opacity: 1
			}, 500);
		},
		function () {
			$(this).find("div.bar").animate({
				opacity: 0.4
			}, 500);
		}
	)
	
	$("ul.sub-menu").parent().hover (
    function () {
			$(this).addClass("hover");
			$(this).find("ul.sub-menu").show();
			$(this).hover(
				function () {
				},
				function () {
					$(this).find("ul.sub-menu").hide();
					$(this).removeClass("hover");
				}
			);
		},
		function () {
		}
	);
	
	// preload images
	$.preloadImages("images/legend_roadways.png",
									"images/menu-ro_bk.gif",
									"images/icon-fb-ro.png",
									"images/icon-tw-ro.png",
									"images/icon-in-ro.png",
									"");
	
	$("#toc").tableOfContents("#content", {
		startLevel: 2
	});
	
	$.localScroll();
	
});
