jQuery.noConflict();
jQuery(document).ready(function($) {
	$(document).ready(function () {
		
		$("#logo").mouseover(function(){ 
			$("#popupMenue").show(600); 
		});
		$("#popupMenueClose").click(function(){ $("#popupMenue").hide(600); });
		$("#menue").mouseover(function(){
			if ($("#popupMenue").css("display") == 'block'){
				$("#popupMenue").hide(600);
			}
		});
				
		$('#banner').nivoSlider({
			effect: 'fade', //Specify sets like: 'fold,fade,sliceDown'
			slices: 3,
			animSpeed: 600, //Slide transition speed
			pauseTime: 6000,
			startSlide: Math.floor(Math.random() * $('#banner img').length ), //Set starting Slide (0 index)
			//keyboardNav:true, //Use left & right arrows
			pauseOnHover: true, //Stop animation while hovering
			manualAdvance: false, //Force manual transitions
			captionOpacity: 0.8, //Universal caption opacity
			directionNav: true
		});
		
		// News initialisieren
		$("#vg-aktuell li").each(function(i){
			$(this).attr("id", "article-" + i);
			if (i != 0){
				$(this).hide();
			}
		});
		
		// Hover-Effekt für News
		$("#vg-aktuell-hover li").hover(function(a){
			if (!$(this).hasClass("active")){
				// alle Artikel verstecken
				$("#vg-aktuell li").each(function(){
					$(this).removeClass("active");
					$(this).hide();
				});
				// Artikel auf den gezeigt wird einblenden
				$("#" + $(this).attr("class")).show();
				
				// Hover-Effekt aktualisieren
				$("#vg-aktuell-hover li").each(function(){
					$(this).removeClass("active");
				});
				$(this).addClass("active");
			}
		});
		
		// Aemterauswahl
		$("#aemterauswahl").change(function(i){
			var amtId = $("#aemterauswahl option:selected").attr("value");
			var amtName = $("#aemterauswahl option:selected").text();
			var url = "http://www.vg-schoellkrippen.de/index.php?id=68&publish[bbwtyp]=behoerde&publish[bbwid]="+amtId+"&bbwtitle="+escape(amtName);
			location.replace(url);
		});
		
		// Gemeindeübersicht
		$("#gemeindeuebersicht").change(function(){	
			var pageId = $("#gemeindeuebersicht option:selected").attr("value");
			var url = document.location.href.replace(/id=\d+/, "id=" + pageId);
			location.replace(url);
		});
		
		$(".splitList").easyListSplitter({ 
			// Insert here the number of columns you want. 
			// Consider that the plugin will create the number of cols requested only if there's enough items in the list.
			colNumber: 3
		});
		
		//
		$('#kalender').mouseenter(function() {
			$("#kalender").stop(true, false).css("background-image", "url(fileadmin/templates/images/home-layout04-kalender-active.jpg)").animate({ 
				height:"290px",
				top:"-209px"
			}, 500, function() { });
		});
		$('#kalender').mouseleave(function() {
			$("#kalender").stop(true, false).animate(
				{ height: "79px", top:"0" }, 500, function() { $("#kalender").css("background-image", "url(fileadmin/templates/images/home-layout04-kalender.jpg)"); 
			});
		});
		$('#kalender .news:last').css('border-bottom', '0');
		
		$('#fundbuero').mouseenter(function() {
			$("#fundbuero").stop(true, false).css("background-image", "url(fileadmin/templates/images/home-layout04-fundbuero-active.jpg)").animate({ 
				height:"290px",
				top:"-209px"
			}, 500, function() { });
		});
		$('#fundbuero').mouseleave(function() {
			$("#fundbuero").stop(true, false).animate(
				{ height: "79px", top:"0" }, 500, function() { $("#fundbuero").css("background-image", "url(fileadmin/templates/images/home-layout04-fundbuero.jpg)"); 
			});
		});
		
		$('#vereine').mouseenter(function() {
			$("#vereine").stop(true, false).css("background-image", "url(fileadmin/templates/images/home-layout04-vereine-active.jpg)").animate({ 
				height:"290px",
				top:"-209px"
			}, 500, function() { });
		});
		$('#vereine').mouseleave(function() {
			$("#vereine").stop(true, false).animate(
				{ height: "79px", top:"0" }, 500, function() { $("#vereine").css("background-image", "url(fileadmin/templates/images/home-layout04-vereine.jpg)"); 
			});
		});
		//
		
		$.preLoadImages(
			"fileadmin/templates/images/menueebene0.jpg", "fileadmin/templates/images/menueebene0-hover.jpg",
			"fileadmin/templates/images/menueebene1.jpg", "fileadmin/templates/images/menueebene1-hover.jpg",
			"fileadmin/templates/images/menueebene2.jpg", "fileadmin/templates/images/menueebene2-hover.jpg",
			"fileadmin/templates/images/menueebene3.jpg", "fileadmin/templates/images/menueebene3-hover.jpg",
			"fileadmin/templates/images/menueebene4.jpg", "fileadmin/templates/images/menueebene4-hover.jpg"
		);
		
	});
});

(function($) {
    var cache = [];
    $.preLoadImages = function() {
        var args_len = arguments.length;
        for (var i = args_len; i--;) {
            var cacheImage = document.createElement('img');
            cacheImage.src = arguments[i];
            cache.push(cacheImage);
        }
    }
})(jQuery)
