$(document).ready(function() {
	//alert("ahoj");
	
	var menuOk = true;	
	// pohyb myši po menu
	$("div.menu a").mousemove(function(e) {
		$(".block").css("cursor", "pointer");
		var url = $(this).attr("href");
		$(".block").click(function() {
			location.href=url;
		});
		
		$(".block").stop();
		var bleft = $(this).position().left;
		$(".block").animate({"left": bleft}, "slow");
		
		menuOk = false;
	});
	
	
	// opuštění menu
	$(".block").mouseout(function(e) { 
		var x = e.pageX;
		var y = e.pageY;
		var sx = 175;//$(".menu").offset().left;
		var sy = $(".menu").offset().top;
		if (((x <= sx) || (x >= /*sx+960*/1107)) ||
			((y <= sy) || (y >= sy+42)))
		{
			var bleft = $(".active").position().left;
			//$(".block").css("left", bleft);
			$(".block").animate({"left": bleft}, "slow");
			menuOk = true;
		}
		else
			menuOk = false;
	});
	
	// náprava menu po opuštění do původního stavu
	$("*:not(div.menu a, .block)").mouseover(function() {
		if (!menuOk) {
			$(".block").stop();
			var bleft = $(".active").position().left;
			$(".block").animate({"left": bleft}, "slow");
			menuOk = true;
		}
	});
	$(".block").mouseover(function() {
		menuOk = true;
	});
	
	
	// nastavení souřadnic bloku aktivní stránky
	var btop;
	var bleft;
	if ($(".active").length > 0) {
		btop = $(".active").position().top;
		bleft = $(".active").position().left;
	}
	else {
		btop = 314;
		bleft = $("div.menu").position().left;
	}

		
	$(".block").css("top", btop);
	$(".block").css("left", bleft);
	//$(".block").animate({"left": "+=50px"}, "slow");
	
	// gallery
	$('a.lightbox').lightBox({
		fixedNavigation:true,
		txtImage: 'Fotografie',
		txtOf: 'z'
	});
	
	// window resize
	$(window).bind('resize', function() {
		$(".block").stop();
		var bleft = $(".active").position().left;
		$(".block").css("left", bleft); //.animate({"left": bleft}, "slow");
	});
	/*
	// jquery.galleria
	$('ul.galerie').galleria({
		onImage   : function(image,caption,thumb) { // let's add some image effects for demonstration purposes
				
			// fade in the image & caption
			if(! ($.browser.mozilla && navigator.appVersion.indexOf("Win")!=-1) ) { // FF/Win fades large images terribly slow
				image.css('display','none').fadeIn(1000);
			}
			caption.css('display','none').fadeIn(1000);
			
			// fetch the thumbnail container
			var _li = thumb.parents('li');
			
			// fade out inactive thumbnail
			_li.siblings().children('img.selected').fadeTo(500,0.3);
			
			// fade in active thumbnail
			thumb.fadeTo('fast',1).addClass('selected');
			
			// add a title for the clickable image
			image.attr('title','Next image >>');
		},
		onThumb : function(thumb) { // thumbnail effects goes here
			
			// fetch the thumbnail container
			var _li = thumb.parents('li');
			
			// if thumbnail is active, fade all the way.
			var _fadeTo = _li.is('.active') ? '1' : '0.3';
			
			// fade in the thumbnail when finnished loading
			thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
			
			// hover effects
			thumb.hover(
				function() { thumb.fadeTo('fast',1); },
				function() { _li.not('.active').children('img').fadeTo('fast',0.3); } // don't fade out if the parent is active
			)
		}
	});*/
	/*
	var gallery = $('#galerie').galleriffic('#thumbs', {
        delay:                  3000, // in milliseconds
        numThumbs:              20, // The number of thumbnails to show page
        preloadAhead:           40, // Set to -1 to preload all images
        enableTopPager:         false,
        enableBottomPager:      true,
        imageContainerSel:      '', // The CSS selector for the element within which the main slideshow image should be rendered
        controlsContainerSel:   '', // The CSS selector for the element within which the slideshow controls should be rendered
        captionContainerSel:    '', // The CSS selector for the element within which the captions should be rendered
        loadingContainerSel:    '', // The CSS selector for the element within which should be shown when an image is loading
        renderSSControls:       true, // Specifies whether the slideshow's Play and Pause links should be rendered
        renderNavControls:      true, // Specifies whether the slideshow's Next and Previous links should be rendered
        playLinkText:           'Play',
        pauseLinkText:          'Pause',
        prevLinkText:           'Previous',
        nextLinkText:           'Next',
        nextPageLinkText:       'Next &rsaquo;',
        prevPageLinkText:       '&lsaquo; Prev',
        enableHistory:          false, // Specifies whether the url's hash and the browser's history cache should update when the current slideshow image changes 
        autoStart:              false, // Specifies whether the slideshow should be playing or paused when the page first loads 
        onChange:               undefined, // accepts a delegate like such: function(prevIndex, nextIndex) { ... }
        onTransitionOut:        undefined, // accepts a delegate like such: function(callback) { ... }
        onTransitionIn:         undefined, // accepts a delegate like such: function() { ... }
        onPageTransitionOut:    undefined, // accepts a delegate like such: function(callback) { ... }
        onPageTransitionIn:     undefined  // accepts a delegate like such: function() { ... }
    });*/

});
