/*
 * script.js - scripty
 * Autor: Radek Liska, radarfox at seznam.cz 
 */

$(document).ready(function(){

	// LIGHTBOX
	$('a.lightbox').lightBox();
	Carousel.init( Array() );

});


/**********************************************
	rotacia carouselov
	(c) Maros Gonda 
 **********************************************/
Carousel = {
	timeout: Array(),
	active: Array(),
	slides: Array(),
	
	max_height: 0,
	max_width: 0,
	
	init: function(settimeouts) {
		
		$('.banner').each(function(index) {
			
			$(this).css("position", "relative");
			var id = $(this).attr('id');
			
			
			Carousel.timeout[id] =  settimeouts[id] ?  settimeouts[id] : 5000;
			Carousel.slides[id] = $(this).find('.slide');
			
			
			if (Carousel.slides[id].length > 1) {
				
				Carousel.slides[id].each(function(){
					var maxheight = $(this).height();
					var maxwidth = $(this).width();
					Carousel.max_height = maxheight > Carousel.max_height ? maxheight : Carousel.max_height;
					Carousel.max_width  = maxwidth  > Carousel.max_width  ? maxwidth  : Carousel.max_width;
				});
				
				Carousel.slides[id].css("position", "absolute");
				$(this).width(Carousel.max_width);
				$(this).height(Carousel.max_height);
				
				Carousel.slides[id].hide();
				Carousel.active[id] = 0;
				Carousel.change(id);
				
			}
			
		});
		
		
	},
	
	change: function(id) {
		
		
		$('#'+id+'.banner .n'+ Carousel.active[id]).fadeOut(1500);
		
		if ((++Carousel.active[id])>Carousel.slides[id].length)
			Carousel.active[id] = 1;
		
		$('#'+id+'.banner .n'+ Carousel.active[id]).fadeIn(1500);
		
		setTimeout("Carousel.change('"+id+"')", Carousel.timeout[id]);
		
	}
}

