var top;

$(window).load(function() {
	top = $('#sidebar').offset().top - parseFloat($('#sidebar').css('marginTop').replace(/auto/, 0));
});

$(function() {
	top = $('#sidebar').offset().top - parseFloat($('#sidebar').css('marginTop').replace(/auto/, 0));
	var colheight = parseFloat($('#sidebar').css('height').replace(/auto/, 0));
    
	$(window).scroll(function (event) {
	    var y = $(this).scrollTop();
    
	    if ($.browser.msie) {
	        $('#sidebar').css("margin-top", Math.max(y-top+10, 0) +"px");
	    } else {
	        if (y >= top-10) {
	            if (colheight <= window.innerHeight) {
	                $('#sidebar').addClass('fixed');
	            } else {
	                $('#sidebar').removeClass('fixed');
	            }
	        } else {	
	            $('#sidebar').removeClass('fixed');
	        }
	    }
	});
	
	$('#main-menu > li').each(function() {
		if ( ! $(this).hasClass('active') ) {
			//var bgp = $(this).css('background-position').split(' ');
			var bgp = new Array();
			bgp[0] = '0px';
			bgp[1] = -225*$(this).attr('rel') + 'px';
			$(this).css('background-position', bgp.join(' '))
				.hover(function() {
					$(this).children('a').css('font-weight', 'bold');
					//var bgp = $(this).css('background-position').split(' ');
					var bgp = new Array();
					bgp[0] = '-160px';
					bgp[1] = -225*$(this).attr('rel') + 'px';
					$(this).css('background-position', bgp.join(' '));
					$(this).children('ul').show();
				}, function() {
					$(this).children('a').css('font-weight', 'normal');
					//var bgp = $(this).css('background-position').split(' ');
					var bgp = new Array();
					bgp[0] = '0px';
					bgp[1] = -225*$(this).attr('rel') + 'px';
					$(this).css('background-position', bgp.join(' '));
					$(this).children('ul').hide();
				}).find('ul').hide();
		}
	});
	
	$('#kuk-menu').hover(function() {
		$(this).addClass('js-hover');
	}, function() {
		$(this).removeClass('js-hover');
	});
	
	$("a.image").lightBox({
        overlayOpacity: 0.4,
        overlayBgColor: "#000000"
    });
});
