/*
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(5(){$(1u).1v(5(){H();$(X).1w(H);Y=$("#1x-1y").1z(\'1A\');$("I.J-Z y.J-11 13").1B(5(){$(7).K(\'y:14\').6({15:"1C",1D:"1E"}).1F();$(7).C().C().16().N("17")},5(){$(7).K(\'y:14\').6({15:"1G"});$(7).C().C().16().18("17")});$(\'I.J-Z y.J-11 13 > y.1a\').1b(5(){3 a=$(7).C().z();$(7).z(a);$(7).K(\'a.1a\').1b(5(){$(7).z(a-12)});$(7).K(\'y\').6(\'1c\',a)});3 j=$("#1d");4(j.A){3 k=[];3 l=\'1H\';j.1e({1f:\'1g\',1h:1i,1j:"#1d",1k:1,1I:5(a,b){1J(3 i=k.A;--i>=0;){k[i].18(l)}a&&k[$(a).1K()].N(l);D 1i},1L:(5(){3 d=$(\'#1M\');3 e=$(\'<I/>\').1l(d);3 f=24;3 g=19;3 h=-f*g;3 i=0;D 5(b,c){3 a=$(\'<a 1N="#">\'+(b+1)+\'</a>\');4(!((b+1)%(f+1))){i++;e=$(\'<I/>\').6({1O:\'1P\',1c:g*i,8:h}).1l(d)}k.O(a);e.P(a);D a}}())})}3 n=$("#1m-1n");4(n.A){n.1e({1f:\'1g\',1h:1Q,1j:"#1m-1n",1k:1})}3 o=$("a#1R-1S");4(o.A)o.Q(5(){1o.O(["1T","/1U-1V/"])});4(~1W.1X.1Y(\'1Z\')){3 p=$(\'#l-R\');4(p.A){p.N(\'R-20\')}}9{3 q=21;3 r=-1;5 1p(){4(r==-1)D;9 4(r==1)r=0;3 m=S(s.6("x-8"),10);4(m<-E){s.L({"x-8":m+E})}9{s.L({"x-8":0});r=-1}}5 1q(){4(r==1)D;9 4(r==-1)r=0;3 m=S(s.6("x-8"),10);4((h+m-q)>E){s.L({"x-8":m-E})}9{s.L({"x-8":-h+q-10});r=1}}3 s=$("#l-R-1r");3 h;4(s.A){h=S(s.6("T"),10);4(h>q){3 t=$(\'<a 1s="1t-22"></a>\');3 u=$(\'<a 1s="1t-23"></a>\');$("#l-25").P(u).P(t);t.Q(1p);u.Q(1q)}}}});5 H(){3 c,v,F;4(B c==\'M\')c=$(X);4(B v==\'M\')v=$("#v");4(B F==\'M\')F=$("#1r-26");4(B c!=B v!=B F!=\'M\')(H=5(){3 a=27,U=28,V=29,W=2a;3 w=c.z(),h=c.T();3 b,G;4(h<a){b=a;G=0}9 4(h<V){b=h;G=U-(V-h)/2}9{b=h;G=U}v.6(\'T\',b);F.6(\'x-8\',G);4(w<W)v.6(\'z\',W);9 v.6(\'z\',\'E%\')})()}5 2b(a,b){1o.O([\'2c\',\'2d\',\'2e\',Y])}}());',62,139,'|||var|if|function|css|this|top|else||||||||||||||||||||||site||margin|ul|width|length|typeof|parent|return|100|cont|newm|resizeSite|div|menu|find|animate|undefined|addClass|push|append|click|inner|parseInt|height|marg|baseh2|basew|window|gallery_name|is||l1||li|first|visibility|children|childselect|removeClass||l2|each|left|gallery|cycle|speed|slow|timeout|8000|next|pause|appendTo|front|slideshow|_gaq|scrollUp|scrollDown|content|id|nav|document|ready|resize|track|title|attr|value|hover|visible|display|none|show|hidden|activeSlide|timeoutFn|for|index|pagerAnchorBuilder|navigation|href|position|relative|5000|mail|to|_trackPageview|kontakt|mailto|navigator|userAgent|search|MSIE|ie|445|up|down||navi|box|591|40|671|960|navClicked|_trackEvent|Galeria|nast_zdjecie'.split('|'),0,{}))

*/

(function () {
	$(document).ready(function(){
		resizeSite();
		$(window).resize(resizeSite);
		gallery_name = $("#track-title").attr('value');
		
		$("div.menu-is ul.menu-l1 li").hover(function(){
			$(this).find('ul:first').css({visibility: "visible",display: "none"}).show();
			$(this).parent().parent().children().addClass("childselect");
			},
			function(){
			$(this).find('ul:first').css({visibility: "hidden"});
			$(this).parent().parent().children().removeClass("childselect");
		}); 
	 
		$('div.menu-is ul.menu-l1 li > ul.l2').each(function () {
			var width = $(this).parent().width();
			$(this).width(width);
			$(this).find('a.l2').each(function () {
				$(this).width(width-12);
			});
			$(this).find('ul').css('left',width);

		}); 
		

		
		var gal = $("#gallery");
		if (gal.length)
		{
			var navigation = [];
			var activeClass = 'activeSlide';

			gal.cycle({ 
				speed:  'slow', 
				timeout: 8000, 
				next:   "#gallery", 
				pause:   1,
				// hook to change class on active element in navigation
				timeoutFn: function (currSlide, nextSlide) {
					for (var i = navigation.length; --i >= 0; ) {
						navigation[i].removeClass(activeClass);
					}
					currSlide && navigation[$(currSlide).index()].addClass(activeClass);
					return 8000;
				},
				pagerAnchorBuilder: (function () {
					var nav = $('#navigation');
					var currentDiv = $('<div/>').appendTo(nav);
					var max = 24;
					var tile_size = 19;
					var rel_height = -max * tile_size;
					var counter = 0;
					
					return function (ind, slide) {
						var a = $('<a href="#">' + (ind + 1) + '</a>');
						if (!((ind + 1) % (max + 1))) {
							counter++;
							currentDiv = $('<div/>').css({
								position: 'relative',
								left: tile_size * counter,
								top: rel_height
							}).appendTo(nav);
						} 
						navigation.push(a);
						currentDiv.append(a);
						return a;
					}
				}())
			});
		}
		
		var galfront = $("#front-slideshow");
		if (galfront.length)
		{
			galfront.cycle({ 
				speed:  'slow', 
				timeout: 5000, 
				next:   "#front-slideshow", 
				pause:   1
			});
		}  
		
		var link_mail = $("a#mail-to");
		if (link_mail.length) link_mail.click(function(){
			_gaq.push(["_trackPageview","/kontakt-mailto/"]);
			});
		
		
		if (~navigator.userAgent.search('MSIE'))
		{
			var linner = $('#l-inner');
			if (linner.length)
			{
				linner.addClass('inner-ie');
			}
		}
		else
		{
			var hmax = 445;
			var stopped = -1;

			function scrollUp()
			{
				if (stopped==-1) return;
				else  if (stopped==1) stopped=0;
				var m = parseInt(lcontent.css("margin-top"),10);
				if (m < -100)
				{
					lcontent.animate({"margin-top": m+100});
				}
				else
				{
					lcontent.animate({"margin-top": 0});
					stopped = -1;
				}          
			}
			
			function scrollDown()
			{
				if (stopped==1) return;
				else if (stopped==-1) stopped=0;
				var m = parseInt(lcontent.css("margin-top"),10);
				if ((h+m-hmax) > 100)
				{
					lcontent.animate({"margin-top": m-100});
				}
				else
				{
					lcontent.animate({"margin-top": -h+hmax-10});
					stopped = 1;
				}      
			}
			
			var lcontent = $("#l-inner-content");
			var h;
			if (lcontent.length)
			{
				h = parseInt(lcontent.css("height"),10);
				if (h>hmax)
				{
					var navup = $('<a id="nav-up"></a>');
					var navdown = $('<a id="nav-down"></a>');
					$("#l-navi").append(navdown).append(navup);
					navup.click(scrollUp);
					navdown.click(scrollDown);
				}
			}
		}
	});

	function resizeSite()
	{
		var win,site,cont;
		if (typeof win == 'undefined')
			win = $(window);   
		if (typeof site == 'undefined')
			site = $("#site");
		if (typeof cont == 'undefined')
			cont = $("#content-box");
		if (typeof win != typeof site != typeof cont != 'undefined' )
		(resizeSite = function()
		{
			var baseh = 631, marg = 40, baseh2 = 681, basew = 960;
			var w = win.width(), h = win.height();
			var newh, newm;
			
			if (h<baseh)
			{
				newh = baseh;
				newm = 0;
			}
			else if (h<baseh2)
			{
				newh = h-1;
				newm = marg-(baseh2-h)/2;
			}
			else
			{
				newh = h-1;
				newm = marg;
			}
			site.css('height', newh);
			cont.css('margin-top', newm);
			
			if (w<basew) site.css('width', basew);
			else site.css('width','100%')      
		})();
	}

	function navClicked(nr, content)
	{
		_gaq.push(['_trackEvent','Galeria','nast_zdjecie',gallery_name]);
	}
}());
