var admin = false;

$(function(){

	admin = $("#amina-panel").length == 0 ? false : true;
	
	$('body').append('<div id="bg"><img /></div>');
	
	var _bg = $('html').css('backgroundImage');
		 _bg = _bg.replace(/^url|[\(\)]/g, '');
		 _bg = _bg.replace('"', '');
		 _bg = _bg.replace('"', '');
	//_bg = '/css/img/html-wide.jpg';
	_bg = '/img/html-wide.jpg';

	$('#bg img').attr('src', _bg);
	
	winResize();
	$(window).resize(function(){
		winResize();
	});
	
	$(".galerie > span > a").fancybox({padding:0, overlayOpacity: 0.2, overlayColor: '#77a2b4', transitionIn: 'elastic', transitionOut: 'elastic', speedIn: 400, speedOut: 400, changeSpeed: 0});
	
	if(admin == false) {
		$('.set').addClass('set-js');
		$('.set-js h2').click(function(){
			if($(this).next('.galerie').is(':hidden')) {
				$('.galerie:visible').slideUp();
				$(this).next('.galerie').slideDown();
			}
		});
	}
	
});

function winResize() {

	var _img = $('#bg img');

	var okno = $('#bg').width() / $('#bg').height();
//	var obraz = _img.width() / _img.height();
	var obraz = 2154 / 953;
	
	if( okno > obraz) {
		_img.css({
				'width': $('#bg').width() + 'px',
				'height': ( $('#bg').width() * obraz ) + 'px'
				});
	}
	else {
		_img.css({
				'height': $('#bg').height() + 'px',
				'width': ( $('#bg').height() * obraz ) + 'px'
				});
	}

	_img.css({
			'marginLeft': '-' + ( parseInt( _img.width() ) / 2 ) + 'px',
			'marginTop': '-' + ( parseInt( _img.height() ) / 2 ) + 'px'
		});

}

