var clickOnLoad = false;

jQuery(document).ready(function($) { 

  setInterval("checkAnchor()", 300);
	if(jQuery("#col3 .vlist li.active").length) {
    jQuery("#col3 #content").remove().appendTo("#col3 .vlist .active");
	
  //Auf den ggf. übermittelten Anker reagieren
	if(location.hash) {
	  clickOnLoad = true;
		x = location.hash;
		jQuery("#col3 .vlist .active").removeClass('active');
		y = x.split("?", 2);
    jQuery('#col3 .vlist > ul > li > a[href|="' + x.slice(1) + '"]').parent("li").addClass('active');
		getContent(x.slice(1));
		//getNavigation(x.slice(1));
		jQuery(this).blur();
		//removeEmptyTitle();
	}
 }
 
	//Links per Ajax nachladen
	jQuery("#col3 .vlist > ul > li > a").click(function() {
	  clickOnLoad = true;
		url = jQuery(this).attr("href");//+"?type=101";
		jQuery("#col3 .vlist .active").removeClass('active');
    jQuery(this).parent("li").addClass('active');
		getContent(url);
		jQuery(this).blur();
		//getNavigation(url);
		//jQuery(this).blur();
		//removeEmptyTitle();
		return false;
	});
	
	
	jQuery(".subcolumns .home-box").hover(function() {
	   teaserHeight = jQuery(this).find('.teaser-text').innerHeight();
       //alert(teaserHeight);
       if(teaserHeight != '36'){
            newHeight = 140 - teaserHeight + 36;
            jQuery(this).find('.hover-text').height(newHeight);
        }
     jQuery(this).find('.hover-text').slideDown('fast', function() {
       //jQuery(this).parent(".overflow-text").addClass('open')
     });
  }, function() {
     //jQuery(this).find(".overflow-text").removeClass('open');
     jQuery(this).find('.hover-text').slideUp('fast');
  });
  
  //removeEmptyTitle();
  
  
  clickForFileDownload();
  
	
	
	
});

//Entfernt leere inhalte
function removeEmptyTitle() {
   jQuery(".sb_download_flex .title:empty").remove();
}

//Entfernt leere inhalte
function clickForFileDownload() {
   jQuery(".file_link").click(function() {
      //alert('found!');
        if(jQuery(this).find(".file_link_text a").attr('href')) {
           window.open('http://' + window.location.hostname + '/' + jQuery(this).find(".file_link_text a").attr('href'), 'AERNI', '');
           jQuery(this).find("a").attr('onclick', jQuery(this).find("a").attr("href"));
           jQuery(this).find("a").removeAttr("href");
        } else {
           window.open('http://' + window.location.hostname + '/' + jQuery(this).find(".file_link_text a").attr('onclick'), 'AERNI', '');
        }
        
       });
}

//Holt den Inhalt vom Server
function getContent(url) {
	jQuery.ajax({
   	url: url+"?type=101",
 	  success: function(html) {
      jQuery("#content").hide(10, function() {
        jQuery(this).remove().appendTo("#col3 .vlist .active");
        jQuery(this).html(html).slideDown('fast');
      });
      //
  		location.hash = url;
  		getNavigation(url);
  	}
	});
}

function getNavigation(url) {
	jQuery.ajax({
   	url: url+"?type=102",
 	  success: function(html) {
 	    jQuery("#topnav").hide(0, function() {
        jQuery(this).remove().appendTo(".topnav_outer");
        jQuery(this).html(html).show(0);
      });
  		//location.hash = url;
  		currentAnchor = '#' + url;
  		clickOnLoad = false;
      clickForFileDownload();
 	    //removeEmptyTitle();
  		
  	}
	});
}

var currentAnchor = '';  
//Function which chek if there are anchor changes, if there are, sends the ajax petition  
function checkAnchor(){  
    //Check if it has changes  
    if((currentAnchor != location.hash) && !clickOnLoad){ 
        //alert(currentAnchor +' != ' + location.hash);
        currentAnchor = location.hash;  
        //if there is not anchor, the loads the default section  
        if(!currentAnchor) {
          location.reload();
        }       
        else  
        {  
            x = location.hash;
        		jQuery("#col3 .vlist .active").removeClass('active');
        		y = x.split("?", 2);
            jQuery('#col3 .vlist a[href|="' + x.slice(1) + '"]').parent("li").addClass('active');
        		getContent(x.slice(1));
        		//getNavigation(x.slice(1));
        		jQuery(this).blur(); 
        }  
        //Send the petition  
        //$.get("callbacks.php",query, function(data){  
        //    $("#content").html(data);  
        //});  
    }  

   

}  


