﻿function banner_fade(obj, fade_speed, change_speed) {
	var i = 0;
	var i_next = 0;
	var $banner_pics = $('#' + obj + ' > img');
	var max = $banner_pics.length - 1; // počet obrázku mínus jedna
	
	pic = [];
	$banner_pics.each(function(index) { // preloader obrázků
		picsrc = $(this).attr("src");
		pic[index] = new Image();
		pic[index].src = picsrc;
	});
	
	$banner_pics.hide();
	$banner_pics.eq(i).fadeIn(2000, function() { // načtení úvodního obrázku
		setInterval(function() {
				i_next = i + 1;
				if (i_next > max) i_next = 0;
				$banner_pics.eq(i).fadeOut(fade_speed);
				$banner_pics.eq(i_next).fadeIn(fade_speed);
				i = i_next;
			}, change_speed);
	});
}

$(document).ready(function() {
	if (getObj("header-left")) { // pouze když je třeba
		banner_fade("header-left", 1000, 5000);
	}
});
