jQuery(function() {
	var $ = jQuery;
	
	$(function() {
    
    //MENU
      $(".regionalMenu").buildMenu(
      {
        menuWidth:120,
        openOnRight:false,
        menuSelector: ".menuContainer",
        iconPath:"ico/",
        hasImages:false,
        fadeInTime:100,
        fadeOutTime:300,
        adjustLeft:2,
        minZindex:"auto",
        adjustTop:10,
        shadow:true,
        openOnClick:false,
        closeOnMouseOut:true,
        closeAfter:500
      });
	
          
        if ($.fn.lightBox) {
            $('a[rel=lightbox]').lightBox({
				imageLoading: '/images/indicator_big.gif',
				imageBtnClose: '/images/cross.png',
				imageBtnPrev: '/images/arrow_left.png',
				imageBtnNext: '/images/arrow_right.png',
				txtImage: 'Obrázek',
				txtOf: 'z'
			});
		}
        
        // PDF archive menu item has special class..
        $('#menu a:contains(Archiv tištěných čísel)').addClass('archive');
        
        $('#issues-regions .issues.column').each(function() {
        	$('img', this).hide().eq(0).show();
        	$('.link a', this).mouseover(function() {
        		$(this).parents('.issues.column').find('img').hide();
        		$('#'+$(this).attr('id').replace('link', 'image')).show();
        	})
        });
        
		var menus = $('#menu a');
		menus.each(function() {
		    var a = $(this);
		    if (a.width() < 50) { //55
		        a.css({
		            width: '50px' //55
		        });
		    }
		});
		
		// Layout hack
		setTimeout(function() {
			$('#short').css('height', ($('#top-right').height()-22)+'px');
			$('#issues-next, #issue-cover').css('height', ($('#top-right').height()-16)+'px');
		}, 10);	
		// Ajax loading of issues
		$('#issues-next .ajax').click(function() {
		    $('#issue-cover').load($(this).attr('href'));
		    return false;
		});

    var myWidth = 0, myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
      //Non-IE
      myWidth = window.innerWidth;
      myHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
      //IE 6+ in 'standards compliant mode'
      myWidth = document.documentElement.clientWidth;
      myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
      //IE 4 compatible
      myWidth = document.body.clientWidth;
      myHeight = document.body.clientHeight;
    }

    window.onscroll = function()
    {
    
      var scrOfX = 0, scrOfY = 0;
      if( typeof( window.pageYOffset ) == 'number' ) {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
      } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        //DOM compliant
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
      } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        //IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
      }
      if( scrOfY <= 615 ){
        $('#side_adv_float').css('top', 615);
      } else if($('#all').height() > (myHeight + scrOfY )) {
        $('#side_adv_float').css('top', scrOfY);
      }
    }

	});
});