// JavaScript Document

var nehpOverviewSecond = 0;

$("document").ready(function() {

    $.preloadImages("/media/semiconductor-sub-fab-utility-module-700x480.jpg","/media/life-sciences-custom-700x480.jpg","/media/about-us-clean-room-700x480.jpg");
    
    $("body").addClass("enhanced");
    
    $("textarea.markitup").markItUp(mySettings);
        
    $("#nav-main li").mouseover(function () {
		$(this).addClass("sfHover");
	});
	$("#nav-main li").mouseout(function () {
		$(this).removeClass("sfHover");
	});
    
    $("form :input:not(input[type='submit']):visible:first").focus();
    
    $("body.news #content .inner dd.help").mouseover(function() {
        $(this).addClass("hover");
    });
    $("body.news #content .inner dd.help").mouseout(function() {
        $(this).removeClass("hover");
    });
    
    $("#content .inner ul.sitemap > li:eq(3),#content .inner ul.sitemap > li:eq(6),#content .inner ul.sitemap > li:eq(9)").css("clear","both");
    
    $("#module-console .module-key dl dt").mouseover(function() {
        var id = $(this).attr("id");
        $("#module-console #fab-facility img#" + id + "-highlight").removeClass("module").addClass("module-highlight");
    });
    $("#module-console .module-key dl dt").mouseout(function () {
        var id = $(this).attr("id");
        $("#module-console #fab-facility img#" + id + "-highlight").removeClass("module-highlight").addClass("module");
    });
    $("#module-console #fab-facility map#fab-facility-map area").mouseover(function() {
        var id = $(this).attr("id");
        $("#module-console .module-key dl dt#" + id + "-key").addClass("hover");
        $("#module-console #fab-facility img#" + id + "-key-highlight").removeClass("module").addClass("module-highlight");
    });
    $("#module-console #fab-facility map#fab-facility-map area").mouseout(function () {
        var id = $(this).attr("id");;
        $("#module-console .module-key dl dt#" + id + "-key").removeClass("hover")
        $("#module-console #fab-facility img#" + id + "-key-highlight").removeClass("module-highlight").addClass("module");
    });

//    $(".slideshow ul#controls").show();
//    $(".slideshow ul#controls li a#play").parent().hide();
    $(".slideshow").addClass("loop");
	
	$.timer(1000, function (timer) {
		if ($(".slideshow").hasClass("loop")) {
			nehpOverviewSecond++;
			if (nehpOverviewSecond >= 5) {
				nehpOverviewSecond = 0;
				moveNext();
			}
		}
	});
	
	$("ul#controls li a#next").click(function (){
		pause();
		moveNext();
		$("ul#controls li a#pause").parent().hide();
		$("ul#controls li a#play").parent().show();
		return false;
	});
	$("ul#controls li a#previous").click(function (){
		pause();
		movePrevious();
		$("ul#controls li a#pause").parent().hide();
		$("ul#controls li a#play").parent().show();
		return false;
	});
	$("ul#controls li a#play").click(function (){
		moveNext();
		play();
		$("ul#controls li a#play").parent().hide();
		$("ul#controls li a#pause").parent().show();
		return false;
	});
	$("ul#controls li a#pause").click(function (){
		pause();
		$("ul#controls li a#pause").parent().hide();
		$("ul#controls li a#play").parent().show();
		return false;
	});

    $("form.delete").submit(function() {
        if (!confirm("Are you sure you want to delete this entry?")) {
            return false;
        }
    });

});

function moveNext() {
	if ($(".slideshow li.current").next("li").size() == 0) {
			$(".slideshow li.current").fadeOut(500).removeClass("current");
			$(".slideshow li").fadeOut(500).filter(":first").addClass("current").fadeIn(500);
		} else {
			$(".slideshow li.current").fadeOut(500).removeClass("current").next("li").addClass("current").fadeIn(500);
		}
};
function movePrevious() {
	if ($(".slideshow li.current").prev("li").size() == 0) {
			$(".slideshow li.current").fadeOut(500).removeClass("current");
			$(".slideshow li").fadeOut(500).filter(":last").addClass("current").fadeIn(500);
		} else {
			$(".slideshow li.current").fadeOut(500).removeClass("current").prev("li").addClass("current").fadeIn(500);
		}
};
function play() {
	nehpOverviewSecond = 0;
	$(".slideshow").addClass("loop");
};
function pause() {
	$(".slideshow").removeClass("loop");
};