
//show the news
//as this will be called onLoad disBlur() is also called here

function showHomepage(){
	$('wrapper').addClassName('backgound_home'); 
	$('menu_home_top').addClassName('trans');
     disBlur();
     Ajax.Responders.register({
			onComplete:function() {
			 disBlur();
			}		
	 });
	 
     //show the Newsnavi
     new Ajax.Updater('news_list', '/news/list?count=3', {asynchronous:true, evalScripts:true, onComplete:showNewsTeaser()});
     //show all news in news_detail
     new Ajax.Updater('news_detail', '/news/listall', {asynchronous:true, evalScripts:true, onComplete:showNewsDetails()}); 
    
} 

/*
 * will highlight the klicked links
 * and "unhighlight" all others
 */
function hilightLink(id){
    $$('td').each(function(ele){
                ele.removeClassName('hilightLink');
          }
        );
     document.getElementsByClassName('news_item').each(function(ne){
                ne.removeClassName('hilightLink');
          }
        );  
        
    $(id).addClassName('hilightLink');
}

/*
 * will highlight the klicked links in the 2ndlevel menu
 * and "unhighlight" all others
 */
function hilightMenuLink(id){
    $$('td').each(function(ele){
                ele.removeClassName('hilightMenuLink');
          }
        );
    $(id).addClassName('hilightMenuLink');
}

/*
 * will highlight the klicked links in the main menu
 * and "unhighlight" all others
 */
function hilightMainMenuLink(id){
    $$('td').each(function(ele){
                ele.removeClassName('hilightMainMenuLink');
          }
        );
    $(id).addClassName('hilightMainMenuLink');
    
}

function showNewsTeaser(){
    hideAllBut('news2ndLevel',1);
    return false;
}

function showNewsDetails(){
    var div =  $('news_detail');
    div.show(); 
    Element.addClassName(div,'opened');
    return false;
}

function showDetails(id){
    if($(id).hasClassName('open')){
         $(id).addClassName('closed'); 
    }
    else{
	     Element.show(id);
         $(id).addClassName('opened');
         
    }
  
}

function hideAllBut(id, level){

  document.getElementsByClassName('navlevel'+level).compact().each (function(aid){
                if (aid.getAttribute('id')!=id) {
			           aid.removeClassName('navlevel'+level);
			         //  Effect.toggle(aid,'blind');
			            Element.hide(aid);
		        }
            }    
   );     
   
   var nextlevel = level + 1;

  document.getElementsByClassName('navlevel'+nextlevel).compact().each (function(aid){
                if (aid.getAttribute('id')!=id) {
			           aid.removeClassName('navlevel'+nextlevel);
			           //Effect.toggle(aid,'blind');
			           Element.hide(aid);
		        }
            }    
   );  
   
   if( $(id).hasClassName('navlevel'+level)){
        $(id).removeClassName('navlevel'+level);        
   }
   else{
       $(id).addClassName('navlevel'+level);
   }
   	 if(id != 'results'){
		Effect.toggle(id,'blind');
	}
	   
   
	   if($('author_detail').hasClassName('opened')){
	      Element.hide('author_detail');
	       $('author_detail').removeClassName('opened');
	   }
	   if($('author_detail_small').hasClassName('opened')){
	      Element.hide('author_detail_small');
	       $('author_detail_small').removeClassName('opened');
	   }
	    if($('book_detail').hasClassName('opened')){
	      Element.hide('book_detail');
	       $('book_detail').removeClassName('opened');
	   }
	   if($('news_detail').hasClassName('opened')){
	      Element.hide('news_detail');
	       $('news_detail').removeClassName('opened');
	   }
	    if($('book_detail_large').hasClassName('opened')){
	      Element.hide('book_detail_large');
	       $('book_detail_large').removeClassName('opened');
	   }
	   if($('authors').hasClassName('opened')){
	      Element.hide('authors');
	       $('authors').removeClassName('opened');
	   }
	   if($('books').hasClassName('opened')){
	      Element.hide('books');
	       $('books').removeClassName('opened');
	   }
	   if($('service').hasClassName('opened')){
	      Element.hide('service');
	       $('service').removeClassName('opened');
	   }
	   if($('manuscripts').hasClassName('opened')){
	      Element.hide('manuscripts');
	       $('manuscripts').removeClassName('opened');
	   }
		if($('weblinks_details').hasClassName('opened')){
	      Element.hide('weblinks_details');
	       $('weblinks_details').removeClassName('opened');
	   }
	   Element.hide('main_content');
}

function removeWrapperClassnames(){
    $('wrapper').classNames('test').each (function(cname){
                $('wrapper').removeClassName(cname);
            }    
     )
}

function updateBackgoundImage(title){
    removeWrapperClassnames();
    
	if (title == "menu_home"){ 
       $('wrapper').addClassName('backgound_home'); 
	   $('menu_home_top').addClassName('trans'); 
	  toggleMenus(title); 
	}
	else if (title == "menu_books"){
	  $('wrapper').addClassName('backgound_books');
	  toggleMenus(title);
	}
	else if (title == "menu_authors"){ 
	    $('wrapper').addClassName('backgound_authors');
	    toggleMenus(title);
    	
	}
	else if (title == "menu_service"){  
	    $('wrapper').addClassName('backgound_service');
	    toggleMenus(title);
	}
	else if (title == "menu_contact"){ 
	    $('wrapper').addClassName('backgound_contact');
	    toggleMenus(title);
	}
}
          timeout=0;
		  function openInfoDialog1() { 
			Dialog.info("cosinus wurde zu Deinen Favoriten hinzugefgt !<br> (3s ...)", {windowParameters: {width:250, height:100}, showProgress: true}); 
			timeout=3; 
			setTimeout(infoTimeout, 1000) 
		} 
		
		 function openInfoDialog2() { 
			timeout--; 
			if (timeout >0) { 
			Dialog.setInfoMessage("cosinus wurde zu Deinen Favoriten hinzugefgt !<br> (" + timeout + "s ...)"); 
			setTimeout(infoTimeout, 1000); 
			} else Dialog.closeInfo();
		}
		
		
		function linkFromQuickSearch(type){
		  new Ajax.Updater(type+'s', '/'+type+'/list', {
		          asynchronous:true, evalScripts:true, onComplete:function(request){showDetails(type+'s',2);
		          return false}});
		  if(type == 'book'){
		       showDetails('book_detail_large');
		  } else if (type == 'author'){
		      showDetails('author_detail');
		  }
		  
		         
		 
		  Element.hide('results');
		  Element.show(type+'s2ndLevel');
		  $(type+'s2ndLevel').addClassName('navlevel1');
		  return false;
		}
		
		
		
function toggleMenus(id){
    var currId = id+"_top";
    $(currId).addClassName('trans');
    $(currId).removeClassName('opac');
    
    var menues  =  new Array('menu_home_top', 'menu_books_top', 'menu_authors_top','menu_service_top','menu_contact_top');
    menues.each (function(aid){  
            if(currId != aid){
                $(aid).removeClassName('trans');
                $(aid).addClassName('opac');
            }
         }
    );
    
}		


function hide_author_detail_small(){
	 Element.hide('author_detail_small');
	$('author_detail_small').removeClassName('opened');
}

function hide_book_detail(){
	 Element.hide('book_detail');
	$('book_detail').removeClassName('opened');
}

//unblurs the links
function disBlur(){
    $$('a').each(function(ele){ele.onfocus = ele.blur;});
}		
		
		
		
	