function getScrollTop () {
  return window.pageYOffset || document.documentElement && document.documentElement.scrollTop || document.body.scrollTop;
}

function docgeladen() {
  $('img[@src$=.png]', '#main').rollover(); 
  $('#main div').pngfix(); 
  $('img[@src$=.png]:not("#versteckt")').pngfix(); 
	
	$('td.hover').each(function(i,obj) {
		$(obj).mouseover(function() {
		$(this).addClass('highlight');
		});
		
		$(obj).mouseout(function() {
		$(this).removeClass('highlight');
		});
		
		$(obj).click(function() {			
			var id = $(this).find('p:eq(0)').attr('id');
			if (id != undefined) {
        var hashUrl = '#!e='+id;						// ADDED
        window.location.hash = hashUrl;
				$.get(base_url+"kalender_detail", { id: id },
				  function(data){
				    $('.ajaxcontainer').html(data);
				    $('div.detail').show();
					$('#versteckt').pngfix();
				  });
			}
		});
	});
	
	$('div.detaillink').each(function(i,obj) {
		$(obj).click(function() {
			var id = $(this).attr('id');
			if (id != undefined) {
			var hashUrl = '#!e='+id;						// ADDED
        window.location.hash = hashUrl;
				$.get(base_url+"kalender_detail", { id: id },
				  function(data){
				    $('.ajaxcontainer').html(data);
					$('.detail').css('top',getScrollTop()+115)
				    $('div.detail').show();
					$('#versteckt').pngfix();
				  });
			}
		});
	});
	
	$('div.close').click(function() {
		$('div.detail').hide();
		$('#versteckt').pngunfix();
	});
	
	function getHash() {
		var hash = window.location.hash;
	  	var getIt = hash.substring(4);
	  	if(getIt=='' || getIt == 'undefined'){
	  		return false;
	  	} else {
		  	$.get(base_url+"kalender_detail", { id: getIt },
				  function(data){
				    $('.ajaxcontainer').html(data);
					$('.detail').css('top',getScrollTop()+115)
				    $('div.detail').show();
					$('#versteckt').pngfix();
				  });
	  	}
	}
	getHash();
};

window.onload = docgeladen;
