$(function(){
	//Wyktywanie zamiany tekstu na obrazek
	$('[img]').each(function(){
		$el = $(this);
		
		alt = $el.text();
		src = $el.attr('img');
		
		img = new Image();
		img.src = src;
		
		$el.html(img);
		
	});
	
	/*var width = 0;
	var margin = $('#top ul').width();
	
	$('#top ul li').each(function(){		
		width += $(this).outerWidth(true);
		console.log(width,'step');
	});
	
	margin = Math.round((960-width)/2);
	
	console.log(margin,'szerokosc');
	$('#top ul').css('padding-left',120);*/
	
	//animacja menu po zamianie
	$('#top ul span img').css({opacity: "0.5"});
	
	$('#top ul a img').hover(
		function(){						
			$(this).animate({opacity: "0.5"});
		},
		function(){					
			$(this).animate({opacity: "1"});
		}
	);
	
	//lightbox
	var lightBoxConfig = {
		overlayBgColor: '#403425',
		overlayOpacity: 0.8,
		imageLoading: '/img/lightbox/lightbox-ico-loading.gif',
		imageBtnClose: '/img/lightbox/lightbox-btn-close.gif',
		imageBtnPrev: '/img/lightbox/lightbox-btn-prev.gif',
		imageBtnNext: '/img/lightbox/lightbox-btn-next.gif',
		containerResizeSpeed: 350
	};
   
	$('.randfoto a').lightBox(lightBoxConfig);
   
    //galeria
	$('#galery a').lightBox(lightBoxConfig);
	
	//poziome foto
	$('.imgh a').lightBox(lightBoxConfig);
   
   //styl modul
    $('.modul>div').css({
		'padding': '10px 15px 15px 10px'
	})
	.wrap('<div class="bl" />').wrap('<div class="br" />')
	.wrap('<div class="bt" />').wrap('<div class="bb" />')
	.wrap('<div class="lb" />').wrap('<div class="lt" />')
	.wrap('<div class="rb" />').wrap('<div class="rt" />');
	
	//randfoto
	changeFoto();
	setInterval('changeFoto()',5000);
	
	//email
	$('.email').each(function(){
		var $this = $(this);
		var adres = $this.attr('href')+'@'+$this.text();
		
		$this.text(adres).attr('href','mailto:'+adres);		
	});

});	

function changeFoto()
{
	var rand = Math.ceil(Math.random() * 28 + 1);
	var $img= $('.randfoto img');
	var newImage = new Image();
	
	if(rand < 10)
		rand = '0'+rand;
		
	$a = $('.randfoto a').attr('href', 'pic/lato_i_zima/szamanowka'+rand+'.jpg');
	newImage.src = '/pic/lato_i_zima/miniatury/szamanowka'+rand+'.jpg';
	
	$a.animate({opacity: 0},function(){$img.replaceWith(newImage)}).animate({opacity: 1});
	
}		
