$(document).ready(function(){
	$('#top-img div').show();

	// zajisti skok na nahodny dalsi obrazek ( krom prvniho) po deseti sekundach
	var rand = Math.round(($('#top-img p img').length-1) * Math.random())+1;
	var t=setTimeout('$("#top-img p").cycle('+rand+');Cufon.replace("#nav a");',4000);

	// aktivni polozky menu
	$(".menu ul li").hover(
		function() {
			$(this).addClass("sfhover");
		},
		function() {
			$(this).removeClass("sfhover");
		}
	);
	
	// oznaceni prvniho prvku v menu aktivnim
	if ($(".ms li.active").length == 0){
		$(".ms li:first").addClass ("active");
	}
	
	// oprava delky stranky
	if ($('#content').height() < 420 && $('#content img').length == 0) {
		$('#content').height("420px");
	}
	
	//function(currSlideElement, nextSlideElement, options, forwardFlag)
	function onAfter(curr, next) {
		// onAfter se vola i pri uvodni inicializaci, v tomto pripade jsou ale shodne oba obrazky, takze se nenuluje timer
		// ten se vynuluje pouze v pripade ze nekdo prepl obrazky drive nez vyprsel timer...
		if(curr.src != next.src)
			clearTimeout(t);
		var re=/[\/]/; 
		var res = next.src.split(re); 
		//alert(next.src + "  -  " + res);
    	$('#wrap').css("background-image", "url('/files/img/cz/podklad/"+res.pop()+"')");
		Cufon.replace('#nav a');
	}
	
	$('#top-img p').cycle({ 
    	fx:     'fade', 
    	speed:  1000,
    	timeout: 0,
		pagerEvent: 'mouseover',
    	pager:  '#nav',
		after:	onAfter
	});
	
	$('#news .content').cycle({ 
    	fx:     'scrollUp', 
    	speed:  'fast', 
    	timeout: 8000,
		random:  1
	});
	

	/* uprava praveho panelu u kontaktu*/
	if($('body').hasClass('kontakty') || $('body').hasClass('contact') || $('body').hasClass('kontakt')) {
		
		$('.panel .realizace:eq(0) a').each(function() {
			$(this).attr("href", 'http://maps.google.com/maps?f=q&hl=cs&geocode=&q=+Holasice+75&ll=49.07796,16.59931&spn=0.022487,0.03562&z=14&ie=UTF8&g=Holasice+75+Holasice&iwloc=addr&sll=49.07796,16.59931&sspn=0.022487,0.03562');
								  http://maps.google.com/maps?f=q&hl=cs&geocode=&q=+Hilleho+6+Brno&sll=37.0625,-95.677068&sspn=34.724817,79.101563&ie=UTF8&ll=49.203719,16.611757&spn=0.013347,0.038624&z=15&g=Hilleho+6+Brno&iwloc=addr
			$(this).addClass("map");
			$(this).attr("rel", "gmap");
		});
		$('.panel .realizace:eq(1) a').each(function() {
			$(this).replaceWith( $(this).children());
		});
		//alert($('.panel .realizace:eq(1) a').html());
	}
	
	
	(function ($) {
	$.fn.descSplit = function() {
		this.each(function () {
			//alert($(this).html());
			var desc = $(this).text();
			if(!desc) {
				$(this).addClass("dn");
				return;
			}
			var data = desc.split(/[,]/);
			
			var cust = data.slice(0,1);
			var loc = data.slice(1,5).join(", ");
			
			if(cust == undefined) cust = "";
			if(loc == undefined) loc = "";
			$(this).html('<div class="tl fl"><strong>'+cust+'</strong></div><div class="tr fr">'+loc+'</div');
		});
	};
	})(jQuery);
	
	$('#gallery .image .desc').descSplit();
	$('.highslide-caption').descSplit();
	$('#content #info .realizace .desc').descSplit();
	
	Cufon.replace('#nav a');
	
});

