var fb = {
	jQuery : $,
 	anzahlBilder : 3,
 	loadNav : function() {
		$.ajax({
  		url: '_topnav.html',
  		dataType: 'html',
  		cache: false,
	    success: function(data) {
    		$('#nav').html(data);
    		fb.initNav();
  			}
		});
 	},
 	loadBoxen : function() {
		$.ajax({
  		url: '_boxen.html',
  		cache: false,
  		dataType: 'html',
	    success: function(data) {
    		$('#boxen').html(data);
    		fb.initBoxenOverlay();
    		fb.checkIOS();
    	}
	});
 	},
 	/*Navigation */
 initNav : function() {	
	$(".nav li ul").hide();
	var toggle = function(direction, display) {
	    return function() {
	      var self = this;
	      var ul = $("ul", this);
	      if( ul.css("display") == display && !self["block" + direction] ) {
	        self["block" + direction] = true;
	        ul["slide" + direction]("slow", function() {
	          self["block" + direction] = false;
	        });
	      }
	    };
	  }
	  $(".nav li").mouseenter(toggle("Down", "none"));
	  $(".nav li").mouseleave(toggle("Up", "block"));
	  $(".nav li ul").hide();
	 
	
	 
	
	
	$(".nav ul ul li").hover(function() {
		$(this).find('a').css("color", "#a3388e");
	});	
	$(".nav ul ul li").mouseleave(function() {
		$(this).find('a').css("color", "white");
	});
	
		
	
	
},

initNav2 : function() {


	$("#.nav li ul").hide(); 

	$(".nav li").hover(
        function () {
		$(this).children("ul").show();
        },function(){
		$(this).children("ul").hide();
	});//hover


},

checkIOS : function() {
	var deviceAgent = navigator.userAgent.toLowerCase();
	$iOS = deviceAgent.match(/(iphone|ipod|ipad)/);
		
		if ($iOS) {
		    $("#box1Classic").hide();
		    $("#box2Classic").hide();
		    $("#box1Html5").show();
		    $("#box2Html5").show();
		} else {
		    // use standard things like jQuery.animate
		}
},


initBoxenOverlay : function() {
 $("a#playVideo1").fancybox({
         'scrolling': false,
         'titleShow': false,
         'padding' : 0,
         'onStart' : function() {
             $("#player").show();
             $f("player",
                     "resources/flowplayer/flowplayer-3.2.7.swf",
                     "resources/movies/fuerstenberg.mp4");
         },
         'onClosed' : function() {
             $("#player").hide();
             $f().unload();
         }
     });

	$("a#playVideo2").fancybox({
         'scrolling': false,
         'titleShow': false,
         'padding' : 0,
         'onStart' : function() {
             $("#player").show();
             $f("player",
                     "resources/flowplayer/flowplayer-3.2.7.swf",
                     "/resources/movies/evabitzer.mp4");
         },
         'onClosed' : function() {
             $("#player").hide();
             $f().unload();
         }
     });

},
	changeHintergrund : function() {
		/*Hintergrundbild wechseln */
		
		var anzahlBilder = $("#hintergrundContainer").children().length;
		
		
		var bild = 1;
		var label="bitzer";
		
		setInterval(function() { 
			$("#hintergrundContainer").children().each(function(index) {
				if(($(this)).is (':visible'))	{
					$(this).fadeOut();
					$(this).removeClass("active");
					bild = index+2;
				}
			});
			
			
			if (bild>anzahlBilder) {
				bild=1
			}
			$("#hintergrundContainer img:nth-child("+bild+")").fadeIn();
			$("#hintergrundContainer img:nth-child("+bild+")").addClass("active");
			fb.changePicControl(bild);
			label = $("#hintergrundContainer img:nth-child("+bild+")").attr('rel');
			fb.changePicDesc(bild);
		}, 8000);
			
	},
	/*Pic Desc */
		changePicDesc : function(hintergrundbildNr) {
			//Fehler: Hier muss ich die Rel des aktiven Bilds aus dem Hintergrundcontainet ermitteln und dann die entsprechende Beschreibung auswählen
			var labelBackground = $("#hintergrundContainer .active").attr('rel');
			//alert(hintergrundbildNr + ": " + labelBackground);
			$(".logoBig").children().each(function(index) {
				if ($(this).attr('rel')==labelBackground) {
					$(this).fadeIn(1500);
				} else {
					$(this).hide();
				}
			});
		},
		
		initBildNavigation : function() {
		//Hier wird die Bildnavigation erzeugt (wird gebraucht, wenn auf der Startseite die Bilder wechseln sollen
		
		for(var i=0;i<fb.anzahlBilder;i++){						
			$(document.createElement("li"))
				.attr('id','picControls' + (i+1))
				.html('<a rel='+ (i+1) +' href=\"javascript:void(0);\">'+ (i+1) +'</a>')
				.appendTo($("#"+ 'picControls'));
		};	
		$("#picControls li:nth-child(1)").addClass("current");		
		$("#picControls a").click(function(){							
					$("#hintergrundContainer").children().each(function(index) {
						if(($(this)).is (':visible'))	{
							$(this).fadeOut();
							$(this).removeClass("active");
						}
					});
					var bildNr = $(this).attr('rel');
					$("#hintergrundContainer img:nth-child("+bildNr+")").fadeIn();
					$("#hintergrundContainer img:nth-child("+bildNr+")").addClass("active");
					
					fb.changePicControl(bildNr);
					fb.changePicDesc(bildNr);
				}); 
															
				
		
		},
		
		/*Pic-Controls*/
		changePicControl : function (bildNr) {
			$("#picControls").children().each(function(index) {
				if (bildNr==(index+1)) {
					$(this).addClass("current");
				} else {
					$(this).removeClass("current");
				}
			});
		},
		
		getUrlVars : function() {
		    var vars = [], hash;
    		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
		    for(var i = 0; i < hashes.length; i++)
		    {
		        hash = hashes[i].split('=');
		        vars.push(hash[0]);
		        vars[hash[0]] = hash[1];
		    }
		    return vars;

		}
		
	


};

jQuery(document).ready(function($) {
	
		
	//Navigation laden
	fb.loadNav();
	fb.loadBoxen();
	

   	
});






 	


