//---------------------------------------------------
// Accordion (Container auf- und zuklappen)
//---------------------------------------------------
jQuery(document).ready(function(){
  // Kalenderleiste
  jQuery(".day:first").addClass('today selected');
  
  jQuery(".day").click(function() {
	jQuery(".day").removeClass('selected');
	jQuery(this).addClass('selected');
  }); 
  jQuery(".day").hover(
	function () {
		jQuery(this).addClass("hover");
		jQuery('.day.selected').removeClass("selected");
		jQuery(this).addClass("selected");
	},
	function () {
		jQuery(this).removeClass("hover");
	}
  ); 


  jQuery('dd.toggle_container').each(function(i,o){
		  if( jQuery(o).children().length ==0 ) {
	  		  jQuery(o).prev().hide();
			  jQuery(o).hide();
		  }
  });
  jQuery('.accordion .container').each(function(i,o){
	  if( jQuery(o).children().length ==0 ) {
  		  jQuery(o).prev().hide();
		  jQuery(o).hide();
	  }
});  
  // Container mit dieser ID werden geöffnet, wenn es entsprechend im Cookie steht
  //var listen = new Array('dt_test','dt_login','dt_video','dt_profile', 'dt_user_filter', 'dt_mailbox', 'dt_calendar', 'dt_buddy');
  // alle Container verstecken beim Seitenstart
  jQuery(".toggle_container").hide();
  jQuery(".accordion .container").hide();
  
  /* Klasse setzen/entfernen je nach Zustand
   * 
   * Element wird beim Klick zunächst für weitere Aktionen gesperrt 
   * und erst nach Abschluss der Animation wieder freigegeben. Das
   * verhindert unschöne Effekte. 
   */
  jQuery(".trigger").toggle(
		function(){
	    // active part of toggle command
			if (!jQuery(this).hasClass("locked")) {
				jQuery(this).addClass("locked");
				jQuery(this).addClass("active");
				jQuery(this).next(".toggle_container").slideDown("slow", function(){
					jQuery(this).prev(".trigger").removeClass("locked");
				});
				//if (jQuery.cookie('start') == 'no' && jQuery.inArray(jQuery(this).attr("id"), listen)) {
				//	jQuery.cookie(jQuery(this).attr("id"), 'open',{ path: '/' });
				//}
			}
		}, 
		function(){
			// not active part of toggle command
			if (!jQuery(this).hasClass("locked")) {
		    jQuery(this).addClass("locked");
		    jQuery(this).next(".toggle_container").slideUp("slow", function(){
		      jQuery(this).prev(".trigger").removeClass("active");
		      jQuery(this).prev(".trigger").removeClass("locked");				
		    });
		    //if (jQuery.cookie('start') == 'no' && jQuery.inArray(jQuery(this).attr("id"), listen)) {
		    //  jQuery.cookie(jQuery(this).attr("id"), 'close',{ path: '/' });
		    //}
			}
  	}
	);
  jQuery(".accordion .csc-header").toggle(
			function(){
		    // active part of toggle command
				if (!jQuery(this).hasClass("locked")) {
					jQuery(this).addClass("locked");
					jQuery(this).addClass("active");
					jQuery(this).next(".accordion .container").slideDown("slow", function(){
						jQuery(this).prev(".accordion .csc-header").removeClass("locked");
					});
					//if (jQuery.cookie('start') == 'no' && jQuery.inArray(jQuery(this).attr("id"), listen)) {
					//	jQuery.cookie(jQuery(this).attr("id"), 'open',{ path: '/' });
					//}
				}
			}, 
			function(){
				// not active part of toggle command
				if (!jQuery(this).hasClass("locked")) {
			    jQuery(this).addClass("locked");
			    jQuery(this).next(".accordion .container").slideUp("slow", function(){
			      jQuery(this).prev(".accordion .csc-header").removeClass("active");
			      jQuery(this).prev(".accordion .csc-header").removeClass("locked");				
			    });
			    //if (jQuery.cookie('start') == 'no' && jQuery.inArray(jQuery(this).attr("id"), listen)) {
			    //  jQuery.cookie(jQuery(this).attr("id"), 'close',{ path: '/' });
			    //}
				}
	  	}
		);  

  
  	// community wird in mk_functions_community.js gesetzt
	// mk_functions_community.js wird nur in den Community-Seiten geladen
	//Script wird nur abgearbeitet, wenn der User im Communitybereich ist
	/*if (typeof(community) != "undefined")
	  {
	  if (community == 1)
		{*/
		//Startcookie setzen zur Unterscheidung von Seite neugeladen und User klickt auf Accordionbreich
	//	jQuery.cookie('start', 'yes',{ path: '/' });
		
		//Prüfen, ob der User sich erst eingeloggt hat und Cookie setzen
		//if (!jQuery.cookie('firstlogin',{ path: '/' }))
//	  		{
//  			jQuery.cookie('firstlogin', 'yes',{ path: '/' });
//  			}
  		
  		//Abarbeiten der Blöcke im Accordion 
//  		for (var i = 0; i < listen.length; i++) 
//  			{
//    		x = listen[i];
//    		if (jQuery.cookie(listen[i])) 
//      			if (jQuery.cookie(x) == 'open') 
//        			jQuery('#' + x).click();
//    		}
    	
    	// Wenn User gerade erst eingeloggt, dann Loginbereich öffnen
//		if (jQuery.cookie('firstlogin') == 'yes')
//  			{
//  			if ((!jQuery.cookie('dt_login')) || (jQuery.cookie('dt_login') == 'close'))
//				{
//				jQuery('#dt_login').click();
//				jQuery.cookie('firstlogin', 'no',{ path: '/' });
//				jQuery.cookie('start', 'no',{ path: '/' });
//				}
//			}	
//  			jQuery.cookie('start', 'no', { path: '/' });			    		
//    	}
//      }
    //Falls User nicht innerhalb Community ist, dann nur Loginbereich auf ausklappen prüfen und setzen	
//      else
//    	{
//    	if (jQuery.cookie('dt_login') == 'open') 
//        			jQuery('#dt_login').click();
//    	}
      
  
  //leere Accordions entfernen
  jQuery('dl.accordion:has(dt:empty),li:has(span.cont:empty)').remove();
  
  //Container mit dieser Klasse werden grundsätzlich geöffnet					
  jQuery('.toggle_head').click();
  
  //Wenn sich der User im Spielplanbereich befindet, dann werden die Höhen der Tage synchronisiert 
  if (typeof(spielplan) != "undefined")
    if (spielplan ==1)
    	{
  		syncheight();
  		}	
  window.setTimeout('check_cal_empty();', 1000);  		
});
//Spielplansynchronisierungsfunktion
function syncheight(){
	     
    for (i=1;i<=31; i++)
    	{
    	var ankerset = 'day' + i;
    	var thalia_h = jQuery('#content .col_left a[name=day'+i+']').parent('.blockhoehe').height();
    	if (thalia_h != 'false')
			{
	    	var gauss_h = jQuery('#content .col_middle a[name=day'+i+']').parent('.blockhoehe').height();
			var new_h = 0;
			//Abgleich aller möglichen Elemente (sidebar/proddet/prodinfo)
			if (thalia_h >= gauss_h)
				{
				new_h = thalia_h;
				} 
			else 
				{
				new_h = gauss_h;
				}
			if ((new_h <= 200) && (new_h > 25)) 
				{
				new_h = 200;
				}
			else 
				{
				if (new_h <=25) 
					{
					new_h = 200;
					}
				else
					{
					new_h = new_h + 10;
					}
				}
			//setze alles auf gleiche Höhe (+Anpassungen)
			jQuery('#content .col_left a[name=day'+i+']').parent('.blockhoehe').parent('.contentblock_fixed').height(new_h);
			jQuery('#content .col_middle a[name=day'+i+']').parent('.blockhoehe').parent('.contentblock_fixed').height(new_h);
		}
	}
}
// Kalenderleiste auf leere Vorstellungen pruefen
function check_cal_empty() {
  var content_new = '<li class="empty_today"><p>Heute keine Vorstellung</p></li>';
  
  jQuery(".day ul").each( function() {
  	if (jQuery(this).find("li.thalia").is(":empty")) {
  		if (jQuery(this).find("li.gauss").is(":empty")) {
  			jQuery(this).find("li").remove();
  		};
	};
  });
  jQuery(".dayrow .day ul:empty").html(content_new);
}

