

function Accordeon (accordeon_part, catid, hua) {
	this.accordeon_part = accordeon_part;
	this.catid = catid;
	this.hua = hua;
	
	var unbinded;
    var hoverColor = "#ffde00";
    
    var construct = function(accordeon_part, keepFirstOpen ){ 
   		newButtons = '<a href="#" class="arrow_link all_texts"><img src="images/pfeil_link.gif"/><span>alle Texte vollständig anzeigen</span></a><a href="?mix=true" class="arrow_link shuffle_texts"><img src="images/pfeil_link.gif"/>100 Gründe mischen</a>';
       	$(".sub_select_body").html(newButtons);
      	if( !keepFirstOpen ) closeAll();
    	$(".all_texts").toggle(function(){this.blur();openAll();}, function(){this.blur(); closeAll();});
    	
    	closeAccordeon($(accordeon_part).filter(".close"));
    	openAccordeon($(accordeon_part).filter(".open"));
    };	
   
    
    var bindClick = function(obj){
    	 $(obj).click(function(){
    		 if( urchinTracker ){
	    		var matcher = $(this).children("h3").text().match(/#(\d+).*/);
	    		if( matcher ){
	    			urchinTracker( "/lesen.xhtml?reason=" + matcher[1] );
	    		}
	    	}
    		 closeAll();
    		 openAccordeon(this);
    	 });
    };	
    var unBindClick = function(obj){
    	$(obj).unbind("click");
    };	
    
    
    var bindHover = function(obj){	   
		 $(obj).mouseover(function(){highlight(this);});
		 $(obj).mouseout(function(){unhighlight(this);});	
   };	
   var unBindHover = function(obj){
	   	$(obj).unbind("mouseover");
		$(obj).unbind("mouseout");
   };	
   
   
   var highlight = function(obj){
		 $(obj).css("background", hoverColor);
		 $(obj).css("cursor", "pointer");
		 $(obj).children(".hovertip").css("display", "block");
    };
    var unhighlight = function(obj){
    	 $(obj).css("cursor", "default");
		 $(obj).css("background", "white");
		 $(obj).children(".hovertip").css("display", "none");
    };	
    
    
    var openAll  = function(){
    	unbinded = null;
    	$(".all_texts span").text('alle Texte zuklappen');
    	openAccordeon($(accordeon_part));
    };
    var closeAll  = function(){
    	unbinded = null;
    	$(".all_texts span").text('alle Texte vollständig zeigen');
    	closeAccordeon($(accordeon_part)); // not(".open")	 
    };
    
    
    var openAccordeon = function(obj){
    	unhighlight(obj);
    	showElem(obj);
    	
    	unBindHover(obj);
    	unBindClick(obj);
    	
    	if(unbinded){
	    	closeAccordeon(unbinded);
    	}
    	unbinded = obj;
    };
    var closeAccordeon  = function(obj){
  		bindClick(obj);	 
   		bindHover(obj);	
   	    hideElem(obj);	
    };
    
    
    var showElem = function(obj){
    	$(obj).children().not(".hovertip").css("display", "block");
    	$(obj).children("h5").css("font-weight", "bold"); 
    	$(obj).children("h3").css("font-size", "1.75em"); 
    };        
    var hideElem = function(obj){
		$(obj).children().not("h3").not("h5").css("display", "none");
		$(obj).children("h5").css("font-weight", "normal"); 
		$(obj).children("h3").css("font-size", "1.4166em"); 

    };
    


    construct(accordeon_part, this.hua != null  );
}