var handleLink = function(scope) {
	var url = scope.attr('href');
	$('#page-content').slideUp('fast',function() {
		window.location.href = url;
	});
  return(false);
};

var checkContentLinks = function() {
	$('#content a').each(function() {
		var url = $(this).attr('href');		
		if(url == undefined || url == '') return;
		if(url.substr(0,7) == 'http://' || url.substr(0,8) == 'https://') {
			return;
		} else if(url.substr(0,7) == 'mailto:') {
			return;
		} else if(url.substr(0,11) == 'javascript:') {
			return;
		} else {
			var dotPos = url.indexOf('.');
			//link auf dateien
			if( url.substr(0,10) == 'fileadmin/' || (dotPos > -1 && url.substr(dotPos,3) != 'php')) {
				return;
			} 
			$(this).click(function() {
				$('#navigation a').removeClass('active');
				$("#navigation a[href='" + url + "']").addClass('active');
				return(handleLink($(this)));
			});
		}
  });
};

$(document).ready(function() {
  if(window.location.href.indexOf('#') > -1) {
    
    $('#page-content').slideDown('fast', function() {
	var s = window.location.href.split('#');
	var offset = $('#'+s[1]).position();
	// alert(offset.top);
	var yPos = offset.top;
	//window.scrollTo(0,  yPos);
	
	$('html,body').animate({scrollTop: yPos}, 1000);
    });
  } else {
    $('#page-content').slideDown('fast');
  }
  $('#navigation a').each(function () { 
    $(this).click(function () {      
      $('#navigation a').removeClass('active');
      $(this).addClass('active');
      return(handleLink($(this)));
    });
  });
  $('#logo a').click(function() {
    $('#navigation a:first').click();
    return(false);
  });
  $('#size a').each(function () { 
    $(this).click(function () { 
			$('#size a').removeClass('active');
			$(this).addClass('active');
			 return(handleLink($(this)));
    });
  });
  checkContentLinks();
});

