$(document).ready(function() {
  $('#menu .subnav').hide();
  //$('#content *').not('#pages, img').css({ display: 'none'}).fadeIn(700);
  
  $("a[rel=galeria]").fancybox({
    'transitionIn'  : 'fadeIn',
    'transitionOut' : 'fadeOut',
    'speedIn'       : 500,
    'speedOut'      : 500,
    'overlayShow'   : true,
    'overlayOpacity': 0.7,
    'overlayColor'  : '#000'
	});

  $('#menu .topnav').hover(
    function () {
      //show its submenu
      $('ul', this).slideDown(100);
    }, 
    function () {
      //hide its submenu
      $('ul', this).slideUp(100);         
    }
  );
if(!$.browser.msie){
  $.each($(".pageContent"), function(i, elm){
        $(elm).attr('id', 'div_'+$(elm).attr('id'));
  });
  if(location.hash){
        $(document).scrollTop($(location.hash.replace('#', '#div_')).offset().top-60);
        $('#menu').addClass('fixed');
  }
  var top = 210;// $('#menu').offset().top - parseFloat($('#menu').css('marginTop').replace(/auto/, 0));
  $(window).scroll(function (event) {
    // what the y position of the scroll is
    var y = $(this).scrollTop();
  
    // whether that's below the form
    if (y >= top) {
      // if so, ad the fixed class
      $('#menu').addClass('fixed');
    } else {
      // otherwise remove it
      $('#menu').removeClass('fixed');
    }
  });
  lastScroll = $(document).scrollTop();
  scroll = function(to){
        var scrolled = $(document).scrollTop(),
            scrollBy = to - scrolled > 0 ? 20 : -20;
        if(Math.abs(to - scrolled)<20){
                scrollBy = to - scrolled;
                clearTimeout(s);
        } else {
                s = setTimeout(
                        $.proxy(function(){scroll(this);}, to),
                        2 //This number determine speed of scrolling, the heigher number, the slower speed
                );
        }
        if(scrolled != to){
                $(document).scrollTop(scrolled+scrollBy);
        }
        if(lastScroll == $(document).scrollTop()){
                clearTimeout(s);
        } else {
                lastScroll = $(document).scrollTop();
        }
  }
  $("ul.subnav li").click(function(e) {
        if($('a', this).attr('href').match(/(.*)#/) == location.href.replace(/\/(.*)#/, ''))e.preventDefault();
        var elm = $('a', this).attr('href').replace(/(.*)#/,'');
        scroll($('#div_'+elm).offset().top-60);
        location.hash = elm;
  });
  } else {
        $(".backontop").hide();
  }
/*
  //When page loads...
	$(".pageContent").hide(); //Hide all content
	$("ul.subnav li:first").addClass("active").show(); //Activate first tab
	//$(".pageContent:first").show(); //Show first tab content

	$("ul.subnav li").click(function() {

		$("ul.subnav li").removeClass("active");
		$(this).addClass("active");
		$(".pageContent").slideUp();

    var activePage = $(this).find("a").attr("rel");
    
    if ($('#' + activePage).length > 0) {
    //console.log('#div_' + activePage);
      $('#' + activePage).slideDown();
      //windows.location = $(location).attr('hash'); //'#' + activePage;
	//	  return false;
    }
    else {
      var url = $(this).find("a").attr("href");
      window.location = url;
      return false;
    }

	});

  var currentURL = $(location).attr('hash');
	if ($(currentURL).length > 0) {
	  $(".pageContent").slideUp(); //Hide all tab content
    $(currentURL).slideDown(); //Fade in the active ID content
	  return false;
  }
*/
});

