﻿jQuery.preloadImages = function() {
    for (var i = 0; i < arguments.length; i++) {
        jQuery("<img>").attr("src", arguments[i]);
    }
}

// preload images first (can run before page is fully loaded)
$.preloadImages("btnRegistercv_on.png", "btnCareers_on.png", "btnGraduates_on.png", "btnRecruiters_on.png");
$(
	function() {
	    // set up rollover
	    $("img.rollover").hover(
			function() {
			    this.src = this.src.replace("_off", "_on");
			},
			function() {
			    this.src = this.src.replace("_on", "_off");
			}
		);
			$("input.rollover").hover(
			function() {
			    this.src = this.src.replace("_off", "_on");
			},
			function() {
			    this.src = this.src.replace("_on", "_off");
			}
		);
	}
)

function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ($active.length == 0) $active = $('#slideshow IMG:last');

    var $next = $active.next().length ? $active.next()
    : $('#slideshow IMG:first');

    $active.addClass('last-active');

    $next.css({ opacity: 0.0 })
    .addClass('active')
    .animate({ opacity: 1.0 }, 1000, function() {
        $active.removeClass('active last-active');
    });
}

$(function() {
    // Start slideshow
    setInterval("slideSwitch()", 5000);
});

// img rollover
$(function () {
    $("IMG.hover").hover(function () {
        $(this).attr("src", $(this).attr("src").split(".").join("-hover."));
    }, function () {
        $(this).attr("src", $(this).attr("src").split("-hover.").join("."));
    });
});

// Show email address with javascript to avoid spam
$(function () {
    $(".enquiresemail").attr("href", "mailto:enquiries@facilita.com");
    $(".enquiresemail").text("enquiries@facilita.com");
});
