/*
 * jQuery Timer Plugin
 * http://www.evanbot.com/article/jquery-timer-plugin/23
 *
 * @version      1.0
 * @copyright    2009 Evan Byrne (http://www.evanbot.com)
 */ 

jQuery.timer = function(time,func,callback){
	var a = {timer:setTimeout(func,time),callback:null}
	if(typeof(callback) == 'function'){a.callback = callback;}
	return a;
};

jQuery.clearTimer = function(a){
	clearTimeout(a.timer);
	if(typeof(a.callback) == 'function'){a.callback();};
	return this;
};

/*

THE applivcation JS

*/

$(document).ready(function(){
	//$.datepicker.setDefaults($.datepicker.regional['de']);
	$('.ra').slideUp();
	$.datepicker.setDefaults(
			$.extend(
				{'dateFormat':'dd.mm.yy'},
				$.datepicker.regional['de']
			)
	);
		
	$('.teaserimage').hide();
	$("#breadCrumb").jBreadCrumb();
	$(".heightgroup0").equalHeights();
	$(".heightgroup1").equalHeights();
	$('.pngfix').pngFix();

	
  $("#paragraphs").hide();
  $('#loading').hide();
  $('#ajax-content').hide();


  $("#toggle-ajax").click(function(event){  
    if ($('#toggle-ajax').hasClass('hidden')) { // checks if the content is visible
      $('#loading').show();
      $("#ajax-content").load("ajax-response.html");
      $('#loading').hide();
    } else { 
    }
    
    return false;
	});

  $(".hidden,.visible").click(function(event){  
    if ($(this).hasClass('hidden')){
      $(this).removeClass('hidden')
      $(this).addClass('visible');
    } else {
      $(this).removeClass('visible')
      $(this).addClass('hidden');
    }
    $(this).parent().next().slideToggle();
    
    return false;
  });

	$("#accordion dd:not(:first)").hide();
	$("#accordion dt").click(function(){
		$("#accordion dd:visible").slideUp("slow");
		$(this).next().slideDown("slow");
		return false;
	});

	$("#section-menu dd:not(:first)").hide();
	$("#section-menu dt").click(function(){
		$("#section-menu dd:visible").slideUp("slow");
		$(this).next().slideDown("slow");
		return false;
	});
	$(".foldme p.fold_action").prepend('<img style="margin-top:3px;float:right;" src="assets/img/arrows/white_small_down.gif">');
	$(".foldme p.fold_content:not(:first)").hide();
	$(".foldme p.fold_action").click(function(){
		$(".foldme p.fold_content:visible").slideUp("slow");
		$(this).next("p.fold_content").slideDown("fast");
		return false;
	});
	
	$(".foldme2 div.fold_action2").prepend('<img style="margin-top:3px;float:right;" src="assets/img/arrows/white_small_down.gif">');
	$(".foldme2 div.fold_content2").hide();
	
	$(".foldme2 div.fold_content2").each(function() {
	    	if($(this).height()>200){
				$(this).css("overflow","auto");
				//$(this).css("overflow","hidden");
				$(this).height(200);
			}
			//$(this).height( $(this).parent().height() - 50 );
	  });
	
	$(".foldme2 div.fold_content2:not(:first)").hide();
	$(".foldme2 div.fold_action2").click(function(){
		$(".foldme2 div.fold_content2:visible").slideUp("slow");
		$(this).next("div.fold_content2").slideDown("fast");
		return false;
	});
	
	
	$('.teaserimage').slideDown(2000);
	
	//$('#topslider').fadeTo('fast', 0.5);
	//$('#topcontent').hide();
	//$('#topcontent').fadeTo('fast', 0.95);
	
	$("#topslider").hover(
	  function () {
	    $(this).fadeTo('slow', 0.99);
	  },
	  function () {
	    $(this).fadeTo('slow', 0.5);
	  }
	);
	$('#topcontent').hide();
	/*$('#topcontent').animate({
    	height: 'toggle'
  	}, 0, function() {
    	// Animation complete.
  	});*/
	$('#topslider').click(function() {
		//$('#topcontent').toggle();
	  	//$(#topslider).fadeTo('fast', 0.99);
		//$(this).fadeTo('slow', 0.99);
		$('#topcontent').animate({
	    	//opacity: 0.25,
	    	//top: '+=175',
	    	height: 'toggle'
	  	}, 1000, function() {
	    	// Animation complete.
	  	});
		
	});
	

	$('#mm_kurse').mouseover(function(){
		if ( !$('#kursepulldown').hasClass("mactive") ){	
			$('#kursepulldown').slideDown();
			$('#kursepulldown').addClass('mactive');
			$('#mm_kurse').addClass('kurseover');
			$('#topcontent').slideUp();	
		}
		$('#reisenpulldown').slideUp();
		$('#mm_reisen').removeClass('reisenover');
		$("#reisenpulldown ").removeClass('mactive');
	});
	/*
	$('#mm_reisen').mouseover(function(){
		if ( !$('#reisenpulldown').hasClass("mactive") ){
			$('#reisenpulldown').slideDown();
			$('#reisenpulldown').addClass('mactive');
			$('#mm_reisen').addClass('reisenover');
			$('#topcontent').slideUp();
		}
		$("#kursepulldown").slideUp();
		$('#mm_kurse').removeClass('kurseover');
		$("#kursepulldown ").removeClass('mactive');
	});
	*/
	$('body').mousemove(function(e){
			 //$('#status').html(e.pageX +', '+ e.pageY);
			if(e.pageY<65 || e.pageY>320){
				$("#kursepulldown").slideUp();
				$("#kursepulldown ").removeClass('mactive');
				$('#mm_kurse').removeClass('kurseover');
				$("#reisenpulldown").slideUp();
				$("#reisenpulldown ").removeClass('mactive');
				$('#mm_reisen').removeClass('reisenover');
			}
			if(e.pageY>200){
				$('#topcontent').slideUp();
			}
	});
	//$('.mainnav li').not('#mm_reisen').not('#mm_kurse').mouseover(function(){
	$('.mainnav li').not('#mm_kurse').mouseover(function(){
		//$('#reisenpulldown').slideUp();
		//$('#reisenpulldown').removeClass('mactive');
		//$('#mm_reisen').removeClass('reisenover');
		$('#kursepulldown').slideUp();
		$('#kursepulldown').removeClass('mactive');
		$('#mm_kurse').removeClass('kurseover');
	});
	$(".adddatepicker").datepicker();
	$(".gbview_tablesorted").tablesorter(); 
	$('.confirm').click(function(){

		var res = confirm($(this).attr("title"));
		if (res == true) {
			return true;
		} else {
			return false;
		}
		
	});
	
	
	
	
});   

