	
var Navigation = {
	ids: {
		n1: "home",
		n2: "news",
		n3: "standorte",
		n4: "leistungen",
		n5: "magazin",
		n6: "kontakt",
		n7: "lexikon",
		n8: "partner"
	},
	
	getPath: function() {
		//return "www.tierplus.at/" //
		return window.location.href;
	},
	
	setActiveTab: function(pageId) {
		$.each(Navigation.ids, function(key, value) {
			if (value == pageId.toLowerCase()) {
				$("#navigation ."+key+" a").addClass("active");
			}
		});
	}
}

var Utils = {
	$element: undefined,
	value: 0,
	setLeft: function($element, value) {
		Utils.$element = $element;
		Utils.value = value;
		setTimeout("Utils.deferredSet()",100);
	},
	deferredSet: function() {
		Utils.$element.offset({left:Utils.value});
	}
}

var Leistungen = {
	current: "allgemeine-medizin",
	
	openActive: function($element) {
		$(".leistungClone").parent().removeClass("active");
		$(".leistungClone").parent().find("a").addClass("dotted");
		$(".leistungClone").remove();
		var target = $element.attr("href").split("#")[1];
		if (!Leistungen.hasClone(target)) {
			$element.removeClass("dotted");
		
			var $content = $("#"+target).clone().attr("id",target+"Clone").addClass("leistungClone").addClass("dotted");
			$element.parent().append($content);
			$("#"+target+"Clone").show();
			$element.parent().addClass("active");
		} else {
			$element.addClass("dotted");
			$("#"+target+"Clone").remove();
			$element.parent().removeClass("active");
		}
	},
	
	hasClone: function(target) {
		return $("#"+target+"Clone").length > 0 ? true : false;
	},
	
	setup: function() {
		var hash;
		try {
			hash = Navigation.getPath().split("#")[1];
		} catch (e) {
		}
		if (typeof(hash) == "undefined") {
			 hash = Leistungen.current;
		}
		$("#leistungen li a").addClass("dotted");
				
		var $element = $("a[href*='"+hash+"']");
		if ($element.length > 0) {
			Leistungen.openActive($element);
			window.scrollTo(0, $element.offset().top);
		}
	
		$("#leistungen li").addClass("hand");
		$("#leistungen li").click(function() {
			Leistungen.openActive($(this).find("a"));		
			//return false;
		});
	}
}

var Lexikon = {
	current: "buchstabe-a",
	
	openActive: function($element) {
		$(".lexikonClone").parent().removeClass("active");
		$(".lexikonClone").parent().find("a").addClass("dotted");
		$(".lexikonClone").remove();
		
		var target = $element.attr("href").split("#")[1];
		if (!Lexikon.hasClone(target)) {
			$element.removeClass("dotted");
		
			var $content = $("#"+target).clone().attr("id",target+"Clone").addClass("lexikonClone").addClass("dotted");
			$element.parent().append($content);
			$("#"+target+"Clone").show();
			$element.parent().addClass("active");
		} else {
			$element.addClass("dotted");
			$("#"+target+"Clone").remove();
			$element.parent().removeClass("active");
		}
	},
	
	hasClone: function(target) {
		return $("#"+target+"Clone").length > 0 ? true : false;
	},
	
	setup: function() {
		var hash;
		try {
			hash = Navigation.getPath().split("#")[1];
		} catch (e) {
		}
		if (typeof(hash) == "undefined") {
			 hash = Lexikon.current;
		}
		$("#lexikon li a").addClass("dotted");
		var $element = $("a[href*='"+hash+"']");
		if ($element.length > 0) {
			Lexikon.openActive($element);
		}
	
		$("#lexikon li").addClass("hand");
		$("#lexikon li").click(function() {
			Lexikon.openActive($(this).find("a"));		
			return false;
		});
	}
}


var Standorte = {
	setup: function() {
		if ($("#slider").length == 0) {
			// this is the location overview
			window.location.replace(Navigation.getPath()+tpCookie.getCookieLocation().toLowerCase());
			
		} else {
			// this is a location page
			$(window).unload(function() {
				tpCookie.saveFilter();
			}); 
			tpCookie.getFilter();
			
			$(".openDetails").click(function() {
				var $descriptionElement = $(this).parent().parent().find(".staffFull").clone();
				$(".staffFullContainer").append($descriptionElement).fadeIn(300);
				$(".staffFullContainer .staffFull").show();
				var left = $("#content").offset().left + 113;
				Utils.setLeft($(".staffFullContainer .staffFull"), left);
				$(window).resize(function(){
					var left = $("#content").offset().left + 113;
					$(".staffFullContainer .staffFull").offset({left:left});
				});
				$(".staffFullContainer").find(".closeDetails").click(function() {
					$(".staffFullContainer").fadeOut(200, function() {
						$(this).html("<div class='bg'></div>");
					});
					$(window).unbind("resize");
				});
			});
			
			$("#slider").nivoSlider({
				effect:'sliceDownLeft', // Specify sets like: 'fold,fade,sliceDown'
				slices:15, // For slice animations
				boxCols: 8, // For box animations
				boxRows: 4, // For box animations
				animSpeed:1000, // Slide transition speed
				pauseTime:4000, // How long each slide will show
				startSlide:0, // Set starting Slide (0 index)
				directionNav:true, // Next & Prev navigation
				directionNavHide:true, // Only show on hover
				controlNav:true, // 1,2,3... navigation
				controlNavThumbs:false, // Use thumbnails for Control Nav
				controlNavThumbsFromRel:false, // Use image rel for thumbs
				controlNavThumbsSearch: '.jpg', // Replace this with...
				controlNavThumbsReplace: '_thumb.jpg', // ...this in thumb Image src
				keyboardNav:true, // Use left & right arrows
				pauseOnHover:true, // Stop animation while hovering
				manualAdvance:false, // Force manual transitions
				captionOpacity:0, // Universal caption opacity
				prevText: '', // Prev directionNav text
				nextText: '', // Next directionNav text
				beforeChange: function(){}, // Triggers before a slide transition
				afterChange: function(){}, // Triggers after a slide transition
				slideshowEnd: function(){}, // Triggers after all slides have been shown
				lastSlide: function(){}, // Triggers when last slide is shown
				afterLoad: function(){} // Triggers when slider has loaded
			});
			$(".nivo-controlNav").width($(".nivo-control").length*22);
			$(".nivo-controlNav").css("left",new String(Math.round(300-$(".nivo-controlNav").width()/2))+"px");
			$(".nivo-control").text("");
		}
		
		$("#standorteSubnavigation").find("a").click(function() {
			var filter = $(this).attr("id").substring(3);
			filterOption = filter;
			tpCookie.saveFilter();
		});
	}

}

Magazin = {
	setup: function() {
		$(".openDetails").click(function() {
			var filename = $(this).attr("href");
			$(".staffFullContainer").append("<div class='iframeContainer'><a class='closeDetails'>X</a><iframe id='magazineflash' src='flash.php?i="+filename+"' width='964' height='691' scrolling='no' frameborder='0'></iframe><h2>Zum Blättern bitte in die Ecken klicken!</h2></div>").fadeIn(300);
			var left = $("#content").offset().left - 62;
			Utils.setLeft($(".staffFullContainer .iframeContainer"), left);
			$(window).resize(function(){
				var left = $("#content").offset().left - 62;
				$(".staffFullContainer .iframeContainer").offset({left:left});
			});
			$(".staffFullContainer").find(".closeDetails").click(function() {
				$(".staffFullContainer").fadeOut(200, function() {
					$(this).html("<div class='bg'></div>");
				});
				$(window).unbind("resize");
			});
			return false;
		});
	
	}
}

Kontakt = {
	setup: function() {
		$(window).unload(function() {
			tpCookie.saveFilter();
		}); 
		tpCookie.getFilter();
	}
}

News = {
	setup: function() {
		$(window).unload(function() {
			tpCookie.saveFilter();
		}); 
		tpCookie.getFilter();
		$("#dateFilter").find("a[href='#alle']").addClass("selected");
		$("#dateFilter").find("a").click(function() {
			var key = $(this).attr("href").split("#")[1];
			tpCookie.getFilter();
			$("#dateFilter").find("a").removeClass("selected");
			$(this).addClass("selected");
			switch (key) {
				case "alle": break;
				case "ja": $(".eintrag").each(function(key, value) {
						if (!$(this).hasClass("ja"+Datum.jahr)) {
							$(this).hide();
						}
					});
					break;
				case "mo": $(".eintrag").each(function(key, value) {
						if (!$(this).hasClass("mo"+Datum.monat)) {
							$(this).hide();
						}
					});
					break;
				case "wo": $(".eintrag").each(function(key, value) {
						if (!$(this).hasClass("wo"+Datum.woche)) {
							$(this).hide();
						}
					});
					break;
			} 
			return false;
		});
	}
}

$(function() {
	try {
		window[pageName].setup();
	} catch (err) {}
	Navigation.setActiveTab(pageName);
	/*$("#head").addClass("hand");
	$("#head").click(function() {
		window.location.href = "http://www.tierplus.at";
	});*/
	$("#headcover").addClass("hand");
	$("#headcover").click(function() {
		window.location.href = "/versicherung";
	});
});
