var slideshowCount = 0;
var slideshowLimit = 1;
var intSlideshow = null;

function slideshow(fade) {
	var $old = $j('#slideshow img.first');
	var $new = $old.next().length ? $old.next() : $j('#slideshow img:first');
	$old.addClass('middle');
	$old.removeClass('first');
	$new.css({opacity: 0.0});
	$new.addClass('first');
	$new.animate({opacity: 1.0}, fade, function() {
		$old.removeClass('middle');
	});
	
	if (slideshowLimit > 0) {
		if (slideshowCount <= slideshowLimit) {
			clearInterval(intSlideshow);
		}
		slideshowCount++;
	}
}

function slideshowInterval(fade, pause, limit) {
	document.getElementById('slideshow').className = 'visible';
	
	slideshowLimit = 0;
	if (limit > 0) {
		slideshowLimit = limit;
	}
	intSlideshow = setInterval('slideshow(' + fade + ')', pause);
}

function printFunction(oLink, id, tmpParams) {
	if (oLink.target != '_blank') {
		oLink.href = '/index.php?id=' + id + tmpParams + '&print=1';
		oLink.target = '_blank';
	}
}

/* jQuery no-Conflict-Modus */
jQuery.noConflict();

/* jQuery Accordion */
jQuery(document).ready(function() { 
	jQuery(".chronik").accordion({ 
		active: false,
		header: ".chronikentry .chronikheader",
		animated: "slide",
		autoHeight: false
	});
});

jQuery(document).ready(function() { 
	jQuery(".carusel").accordion({ 
		active: false,
		header: ".header",
		animated: "slide",
		autoHeight: false
	});
});

/* jQuery-Navigation */
jQuery(document).ready(function() {
  var toggle = function(direction, display) {
    return function() {
      var self = this;
      var ul = jQuery("div", this);
      if( ul.css("display") == display && !self["block" + direction] ) {
        self["block" + direction] = true;
        ul["slide" + direction](250, function() {
          self["block" + direction] = false;
        });
      }
    };
  }
  jQuery("li.menu").hover(toggle("Down", "none"), toggle("Up", "block"));
  jQuery("li.menu div").hide();
});

jQuery(document).ready(function(){
	jQuery("li.menu").hover(function(){
		if( !jQuery(this).hasClass("current") ) {
			jQuery(this).addClass("current");
		}
		else {
			jQuery(this).removeClass("current");
		}
	});
});

/* jQuery Interaktive Karte: Imagemap */
jQuery.fn.maphilight.defaults = {
	fill: true,
	fillColor: '189475',
	fillOpacity: 0.95,
	stroke: true,
	strokeColor: 'ff0000',
	strokeOpacity: 0,
	strokeWidth: 0,
	fade: true,
	alwaysOn: false,
	neverOn: false,
	groupBy: false
}
jQuery(function() {
	jQuery('.map').maphilight();
});

/* jQuery Interaktive Karte: Bayern */
jQuery(document).ready(function() {	
  var toggle = function(direction, display) {
    return function() {
      var self = this;
      var ul = jQuery("div#content_bayern");
      if( ul.css("display") == display && !self["block" + direction] ) {
        self["block" + direction] = true;
        ul["slide" + direction](400, function() {
          self["block" + direction] = false;
        });
      }
    };
  }	
  jQuery("area.bayern").click(toggle("Down", "none"), toggle("Up", "block"));
  jQuery("area.bayern").click(function(){
		jQuery('#content_sachsen').hide();
	});
  jQuery("div#content_bayern").hide();
});

/* jQuery Interaktive Karte: Sachsen */
jQuery(document).ready(function() {	
  var toggle = function(direction, display) {
    return function() {
      var self = this;
      var ul = jQuery("div#content_sachsen");
      if( ul.css("display") == display && !self["block" + direction] ) {
        self["block" + direction] = true;
        ul["slide" + direction](400, function() {
          self["block" + direction] = false;
        });
      }
    };
  }	
  jQuery("area.sachsen").click(toggle("Down", "none"), toggle("Up", "block"));
  jQuery("area.sachsen").click(function(){
		jQuery('#content_bayern').hide();
	});
  jQuery("div#content_sachsen").hide();	
});

/* jQuery Interaktive Karte: Schliessen-Link */
jQuery(document).ready(function() {	
	jQuery('a.close').click(function(){
		jQuery('#content_bayern').hide('slow');
		jQuery('#content_sachsen').hide('slow');
	})
});

/* jQuery newsticker */
jQuery(document).ready(function() {
	jQuery("ul#newsticker").liScroll();
});
