/**
 * Utiliza jQuery para criar o efeito no plano de fundo.
 */

var bgResize = function() {
	$("#bgslide li").each(function() {
		var imgwidth = $("#bgslide li img").width();
		var imgheight = $("#bgslide li img").height();

		var winwidth = $(window).width();
		var winheight = $(window).height();

		if (imgheight > winheight) {
			$("#bgslide li img").css({
				width : winwidth,
				height : 'auto'
			});
		} else if (winwidth < winheight) {
			$("#bgslide li img").css({
				width : 'auto',
				height : winheight + 'px'
			});
		} else {
			$("#bgslide li img").css({
				width : winwidth,
				height : 'auto'
			});

		}
	});
};

$(window).ready(bgResize);

$(window).ready(function slide(timer) {
	var i = 1;
	var current = 1;
	var next = 1;
	$("#bgslide li").each(function() {
		$(this).addClass("slide" + i);
		i++;
	});
	
	$("#bgslide li:first-child").addClass("first");
	$(".first").show();

	$(".slide" + current + 1).load(setInterval(function() {
		$(".slide" + current).fadeIn(2000);

		if (current == 1) {
			$(".slide" + (i - 1)).fadeOut(2000);
		} else {
			$(".slide" + (current - 1)).fadeOut(2000);
		}
		if (i == current + 1) {
			current = 1;
		} else {
			current++;
		}
	}, 4000));
});

$(window).resize(bgResize);

