/* common functions */

jQuery.noConflict();

// carousel
function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};


/* Tooltipp */
this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 10;
		yOffset = 20;	/* distance from cursor */	
	/* END CONFIG */		
	jQuery("a.tooltip, input.tooltip, img.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		jQuery("body").append("<p id='tooltip'>"+ this.t +"</p>");
		jQuery("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		jQuery("#tooltip").remove();
    });	
	jQuery("a.tooltip").mousemove(function(e){
		jQuery("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};



/* Ready Funktions for present DOM Elements */

jQuery(document).ready(function(){
	 
	
	/* Image Links */
	jQuery('a img').bind("mouseover",function(){
		jQuery(this).fadeTo(250, 0.6);
    	});
    jQuery('a img').bind("mouseleave",function(){
		jQuery(this).fadeTo(100, 1);
    	});

	/* carousel */
	jQuery('#mycarousel').jcarousel({
        auto: 2,
        wrap: 'last',
        initCallback: mycarousel_initCallback
    });
	
	/* Alle internen Links weich scrollen lassen */
     jQuery('a[href*=#]').click(function() {
	 if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
	 && location.hostname == this.hostname) {
	   var $target = jQuery(this.hash);
	   $target = $target.length && $target
	   || jQuery('[name=' + this.hash.slice(1) +']');
	   if ($target.length) {
	  var targetOffset = $target.offset().top - 45;
	  jQuery('html,body')
	  .animate({scrollTop: targetOffset}, 400);
		return false;
	   }
	 }
  });


		
	/* Disable Button visualy */
	
	jQuery('input[type=submit], input[type=reset], input[type=button]').each(function(){
		if (jQuery(this).attr('disabled') == true) {
          		jQuery(this).parent('div').fadeTo("fast", 0.50);
				}
         else {
                 jQuery(this).parent('div').fadeTo('slow',1);
                }

		});
		
	/* Disable Inputs visualy*/
	
	jQuery('input[type=text], input[type=password], textarea').each(function(){
		if (jQuery(this).attr('disabled') == true) {
          		jQuery(this).fadeTo("fast", 0.50);
				}
         else {
                 jQuery(this).fadeTo('slow',1);
                }

		}); 
		
	/* disable plz switch */
	jQuery("#control").toggle(
		function ()
		{
			jQuery('#plz, #ort').removeAttr("disabled");
			jQuery('#control').empty().append("PLZ / Ort deaktivieren");
			jQuery('#plz, #ort').removeClass('disabled');
		},
		function ()
		{
			jQuery('#plz, #ort').attr("disabled", true);
			jQuery('#control').empty().append("PLZ / Ort aktivieren");
			jQuery('#plz, #ort').addClass('disabled');
		});
	

	
	
	/* Calendar Legend */
	jQuery('.LegendButton').click(function() {
		var position = jQuery(this).position();
		var cssleft = (position.left - 210) + 'px';
		var csstop = (position.top - 10) + 'px';
		var currentvis = jQuery('#CalendarLegend').css('display');
		
	
		jQuery('#CalendarLegend').css({ "position": "absolute", "top": csstop, "left": cssleft });
		if (currentvis == 'none') jQuery('#CalendarLegend').fadeIn('slow');
		if (currentvis != 'none') jQuery('#CalendarLegend').fadeOut('slow');
  	});
	
	/* Calendar Legend onMouseOut */
	jQuery('#CalendarLegend').click(function() {
		jQuery('#CalendarLegend').fadeOut('slow');							 
		});

	
	/* starting the tooltip script */
	tooltip();

	/* Modal Dialog */
	jQuery('a.nyroModal').nyroModal({height: null});
		
		
	/* Close Tableoptions onClick */
	jQuery('#optionactions a').click(function() {
				jQuery('#optionactions').fadeOut('slow');
				});
	
	/* Close Tableoptions onMouseOut */
	jQuery('#optionactions').bind("mouseleave",function(){
		jQuery('#optionactions').fadeOut('slow');
    });

	
	/* Accordions */
	jQuery('div.accordion> div').hide(); 
	  jQuery('div.accordion> h3').click(function() {
		var $nextDiv = jQuery(this).next();		
			$nextDiv.slideToggle('fast');
		  });
	
	jQuery("div.accordion h3").toggle(function(){ /* Toggles Inhaltsverzeichnis-Button up/down */
			jQuery(this).addClass("current");
	  }, function () {
			jQuery(this).removeClass("current");
	});

	
	/* openall */
	jQuery('#accordion_openall').click(function() {
			jQuery('.accordion div').slideDown('fast');							   
		});
	/* closeall */
	jQuery('#accordion_closeall').click(function() {
			jQuery('.accordion div').slideUp('fast');							   
		});
	

	
});

	

