$(document).ready( function() {
	$('.js-hide').hide();
	$('.js-show').show();
	$('#aspam').val(9);
	// GALLERY /////////////////////////////////////////////////////////////////
	$('.gallery div,.gallery a.next,.gallery a.prev').bind('click', function() {
		var i = 0;
		var gallery = $(this).parents('.gallery');
		var slides = gallery.children('div');
		var done = false;
		var modif = 0;
		if ($(this).hasClass('prev')) {
			modif = -1;
		} else {
			modif = 1;
		}
		slides.each(function(){
			var activeSlide = $(this);
			var activeSlideNo = i;
			if(activeSlide.hasClass('active') && !done){
				activeSlide.removeClass('active');
				activeSlide.fadeOut(200,function(){
					activeSlide.addClass('js-hide');
					var nextSlide = 0;
					nextSlide = activeSlideNo + modif;
					if(nextSlide == slides.length) {
						nextSlide = 0;
					} else if (nextSlide == -1) {
						nextSlide = slides.length - 1;
					}
					slides.eq(nextSlide).removeClass('js-hide');
					slides.eq(nextSlide).addClass('active');
					slides.eq(nextSlide).fadeIn(200,function(){
						done = true;
						gallery.find('span.activeNo').text(nextSlide + 1);
					});
				});
			}
			i = i + 1;
		});
	});
/*	var textVar = $('.gallery span.allCnt').parents('.gallery').children('div').length;
	$('.gallery span.allCnt').text(textVar); */
/*	jQuery 1.4 needed */
	$('.gallery span.allCnt').text(function() {
		return $(this).parents('.gallery').children('div').length;
	});
});

/**
 * Simple (DIV) and Standard (IFRAME) pop-up helper functions
 */
function popupTemplate(width,height) {
	$('body').append('<div id="overlay" onclick="hidePopup();"></div><div id="popup-container"></div>');
	$('#overlay').css('position','absolute');
	$('#overlay').css('z-index',3);
	$('#overlay').css('top',0);
	$('#overlay').css('left',0);
	$('#overlay').css('background-color','white');
	$('#overlay').css('opacity','.9');
	$('#overlay').css('width','100%');
	$('#overlay').css('height',$('body').css('height'));
	$('#popup-container').css('position','absolute');
	$('#popup-container').css('z-index',3);
	$('#popup-container').css('width',width+'px');
	$('#popup-container').css('height',height+'px');
	$('#popup-container').css('background-color','white');
	$('#popup-container').css('border','1px solid black');
	$('#popup-container').css("top", ( $(window).height() - $('#popup-container').height() ) / 2 + $(window).scrollTop() + "px");
	$('#popup-container').css("left", ( $(window).width() - $('#popup-container').width() ) / 2 + "px");
}
function showPopup(src,width,height) {
	popupTemplate(width,height);
	$('#popup-container').append('<iframe id="fasa_popup" scrolling="no" style="width:'+width+'px;height:'+height+'px;border:none;" src="'+src+'"><p>Pro použití této funkce je potřeba, aby váš prohlížeč podporoval HTML tag IFRAME.</p></iframe>');
}
function showPopupSimple(src,width,height) {
	popupTemplate(width,height);
	$('#popup-container').load(src);
}
function hidePopup() {
	var parent_body = $(parent.document.getElementById('fasa_popup')).parent().parent();
	parent_body.children('#overlay').remove();
	parent_body.children('#popup-container').remove();
}
function hidePopupSimple() {
	$('#overlay').remove();
	$('#popup-container').remove();
}
function fromPopup2Parent(elem) {
	parent.window.location = $(elem).attr('href');
}
function resizePopup(newWidth,newHeight) {
	$(parent.document.getElementById('fasa_popup')).css('width',newWidth+"px");
	$(parent.document.getElementById('fasa_popup')).css('height',newHeight+"px");
	var popup_container = $(parent.document.getElementById('fasa_popup')).parent().parent().children('#popup-container');
	popup_container.css('width',newWidth+"px");
	popup_container.css('height',newHeight+"px");
	popup_container.css("top", ( $(parent.window).height() - newHeight ) / 2 + $(parent.window).scrollTop() + "px");
	popup_container.css("left", ( $(parent.window).width() - newWidth ) / 2 + "px");
}
function resizePopupSimple(newWidth,newHeight) {
	$('#popup-container').css('width',newWidth+"px");
	$('#popup-container').css('height',newHeight+"px");
	$('#popup-container').css("top", ( $(window).height() - $('#popup-container').height() ) / 2 + $(window).scrollTop() + "px");
	$('#popup-container').css("left", ( $(window).width() - $('#popup-container').width() ) / 2 + "px");
}
function reloadPopup(elem,newWidth,newHeight) {
	$(parent.document.getElementById('fasa_popup')).attr('src',function() {
		if(newWidth && newHeight) {
			resizePopup(newWidth,newHeight);
		}
		return $(elem).attr('href');
	});
}
function reloadPopupSimple(elem,newWidth,newHeight) {
	$('#popup-container').load($(elem).attr('href'));
	if(newWidth && newHeight) {
		resizePopupSimple(newWidth,newHeight);
	}
}

