function ___getPageSize(){var xScroll,yScroll;if(window.innerHeight&&window.scrollMaxY){xScroll=window.innerWidth+window.scrollMaxX;yScroll=window.innerHeight+window.scrollMaxY;}else if(document.body.scrollHeight>document.body.offsetHeight){xScroll=document.body.scrollWidth;yScroll=document.body.scrollHeight;}else{xScroll=document.body.offsetWidth;yScroll=document.body.offsetHeight;}
var windowWidth,windowHeight;if(self.innerHeight){if(document.documentElement.clientWidth){windowWidth=document.documentElement.clientWidth;}else{windowWidth=self.innerWidth;}
windowHeight=self.innerHeight;}else if(document.documentElement&&document.documentElement.clientHeight){windowWidth=document.documentElement.clientWidth;windowHeight=document.documentElement.clientHeight;}else if(document.body){windowWidth=document.body.clientWidth;windowHeight=document.body.clientHeight;}
if(yScroll<windowHeight){pageHeight=windowHeight;}else{pageHeight=yScroll;}
if(xScroll<windowWidth){pageWidth=xScroll;}else{pageWidth=windowWidth;}
arrayPageSize=new Array(pageWidth,pageHeight,windowWidth,windowHeight);return arrayPageSize;};function ___getPageScroll(){var xScroll,yScroll;if(self.pageYOffset){yScroll=self.pageYOffset;xScroll=self.pageXOffset;}else if(document.documentElement&&document.documentElement.scrollTop){yScroll=document.documentElement.scrollTop;xScroll=document.documentElement.scrollLeft;}else if(document.body){yScroll=document.body.scrollTop;xScroll=document.body.scrollLeft;}
arrayPageScroll=new Array(xScroll,yScroll);return arrayPageScroll;};




jQuery(function($) {
	Cufon.replace('h1, h2, h3, p.versal, p.versalbig');
	Cufon.replace('#metanavs, #search label, #search button, #subnav, .linklist, #body li a', {
		hover: true
	});
	Cufon.replace("#nav", {hover:false}); // hover wird hier speziell behandelt

	// klappbare Seitenteile
	$(".foldable").each(function() {
		var folded = $(this),
			folder = folded.prev();
            
        folder.hover(function(){
            if (!folder.hasClass('no-hover')) {
                $(this).addClass('opacHover');
            }
        }, function(){
            $(this).removeClass('opacHover');
        });
		
		if (folder.hasClass("unfold")) {
			folder.css("cursor", "pointer").bind("click", function() {
				if (folder.hasClass("fold")) {
					folder.removeClass("fold");
					folded.slideDown();
				}
				else {
					folder.addClass("fold");
					folded.slideUp();
				}
			});
			if (!folded.hasClass("open")) {
				folder.addClass("fold");
				folded.hide();
			}
			
		}
	});

	$(window).bind("resize", (function() {
		$('.fullwidth-media').each(function() {
			var elem = $(this).width("100%");
			elem.width(elem.width()+14);
		});
		return arguments.callee;
	})());
	
	
	
	
	// Drucken Button
	$('<p id="print-icon">Drucken</p>').click(function() {
		printPage();
	}).appendTo("#footer");
	
	
	
	
	// label "SEARCH" in input, diesen bei focus ggf. löschen
	$("#search label").each(function() {
		var thisLabel = $(this).hide(),
			labelFor = thisLabel.attr("for"),
			input = $("#"+labelFor).css("visibility", "hidden"),
			newValue = $(this).show().text().toUpperCase();
		//alert(this["for"]);
		if (input[0] && !input[0].value) input[0].value = newValue;
		thisLabel.bind("click mouseover", function() {
			input.focus();
		});
		
		input.bind("focus", function() {
			thisLabel.hide();
			input.addClass("hasfocus").css("visibility", "visible");
			if (this.value == newValue) this.value = "";
		}).bind("blur", function() {
			if (!this.value) {
				thisLabel.show();
				input.removeClass("hasfocus").css("visibility", "hidden");
				this.value = newValue;
			}
		});
        
	});
	
	
	
	
	// Sprache Dropdown
	$("#metanavs li.dropdown").each(function() {
		var slideUpTimeout,
			thisLi = this;
		$(this).hover(function() {
			if (slideUpTimeout) window.clearTimeout(slideUpTimeout);
			$(">ul", thisLi).slideDown();
		}, function() {
			slideUpTimeout = window.setTimeout(function() {
				$(">ul", thisLi).slideUp();
			}, 250);
		});
	});
	
	
	
	// zusammen mit CSS den gepunkteten Rahmen loswerden
	$("a").bind("click", function() {
		this.blur();
	});
    
    
    // Klapptabellen umwandeln
    $('.pulldowncontainer').each(function(){
        var objContainer = $(this);
        var strContainerId = $(this).attr('id');
        $('.' + strContainerId).each(function(){
            $(objContainer).append($(this));
        });
        $(this).find('.' + strContainerId).removeClass('hidden');
        $(this).find('.contenttable').each(function(){
            $(this).wrap('<div class="tablediv"></div>');
            $(this).parent().hide();
            //$(this).css('visibility', 'hidden');
            $(this).find('td').each(function(){
                $(this).html('<div class="underlined">' + $(this).html() + '</div>');
            });
        });
        $(this).find('h6').each(function(){
            var intWidth = $(this).width();
            $(this).next().css('width', intWidth + 'px');
        }).click(function(){
            //$(this).next().slideToggle(1000);
            $(this).next().toggle();
            $(this).toggleClass('open');
        }).hover(function(){
            $(this).addClass('hover');
        },function(){
            $(this).removeClass('hover');
        });;
    });
    
    
});


jQuery(function($) {
	// resize expander
	var expander = $("#expander"),
		container = $("p", expander).css("overflow", "hidden"),
		borderWidth = parseInt(container.css("margin-left"), 10) + parseInt(container.css("margin-right"), 10),
		borderHeight = parseInt(container.css("margin-top"), 10) + parseInt(container.css("margin-bottom"), 10),
		image = $("img", expander),
		xScale = true; // wird in der Breite skaliert? Ansonsten wird in der Höhe skaliert
	
	$(window).bind("resize", function() {
		var w = expander.width()-borderWidth,
			h = expander.height()-borderHeight;
		container.height(h);
		if (image.height() < h) {
			image.css({"width": "auto", "height": "100%", "top": 0});
			xScale = false;
		}
		else if (image.width() < w) {
			image.css({"width": "100%", "height": "auto", "left": 0});
			xScale = true;
		}
		if (xScale) {
			image.css("top", Math.round((h-image.height())/2));
		}
		else {
			image.css("left", Math.round((w-image.width())/2));
		}
	}).bind("load", function() {
		$(window).trigger("resize");
	});
});





jQuery(function($) {
	
	// setup Mainmenü
	$("#nav li").each(function(i) {
		//if (!submenus[i]) return;
		var thisLi = $(this),//.append($(submenus[i]).hide().css("opacity", 0.9));
			menuTimeout,
			thisLink = $(">a", this),
			thisSubmenu = $(">ul", this).hide().detach(), // detach, da IE und Cufon sonst total spinnen
			isVisible = false;
		
		
		
		thisLi.hover(function() {
			
			thisLink.addClass("hasfocus");
			Cufon.replace(thisLink.get(0));
			if (!thisSubmenu.length) {
				return;
			}
			
			if (menuTimeout) window.clearTimeout(menuTimeout);
			if (isVisible) return;
			menuTimeout = window.setTimeout(function() {
				isVisible = true;
				Cufon.replace(thisLink.get(0));
				
				thisSubmenu.appendTo(thisLi).slideDown();
			}, 100);
		}, function() {
			if (!isVisible) {
				// Menü noch nicht offen bzw. kein Menü
				thisLink.removeClass("hasfocus");
				Cufon.replace(thisLink.get(0), {"color": "#333"});
				
				if (menuTimeout) window.clearTimeout(menuTimeout);
				return;
			}
			
			menuTimeout = window.setTimeout(function() {
				menuTimeout = null;
				thisLink.removeClass("hasfocus");
				Cufon.replace(thisLink.get(0));
				
				isVisible = false;
				thisSubmenu.slideUp(function() {
					thisSubmenu.detach();
				});
			}, 250);
		});
	});
});




jQuery(function($){

	var pathToSwfs = "swf/";
	var pathToImages = "img/";



	// flvplayer an die entsprechenden Links binden
	$("a.flvplayer, a.swfplayer").bind("click", function() {
		if (!swfobject) {
			alert("swfobject is not embedded, therefore cannot embed player");
			return false;
		}

		var sizes = this.hash.match(/(\d+)x(\d+)/);
		var url = this.href.replace("#"+sizes[0], "#");
		if (url.substring(url.length-1) == "#") url = url.substring(0, url.length-1);
		//alert("Öffne Video "+url+" in "+sizes[1]+"x"+sizes[2]);
		var jWin = $(window);
		var pageSize = ___getPageSize();

		var isSWF = $(this).hasClass("swfplayer");


		var screenSize = [$(window).width()-20, $(window).height()-20];
		// falls zu groß für Screen -> resize
		if (sizes[1] > screenSize[0] || sizes[2] > screenSize[1]) {
			var scale = Math.min((screenSize[0])/sizes[1], (screenSize[1])/sizes[2]);
			sizes[1] = sizes[1]*scale;
			sizes[2] = sizes[2]*scale;
		}



		//
		var div = $("<div id=\"fullscreen-flvplayer-container\"><div id=\"fullscreen-close\"></div><div id=\"fullscreen-flvplayer\"></div></div>").css({"margin-left": -Math.floor(sizes[1]/2)+jWin.scrollLeft(), "margin-top": -Math.floor(sizes[2]/2)+jWin.scrollTop()});

		$('body').append($('<div id="jquery-overlay">').css({background:"#000",opacity:0.92,width:pageSize[0],height:pageSize[1]}).fadeIn(function(){

			$("body").append(div);

			// embed normal swf
			if (isSWF) {
				swfobject.embedSWF(url, "fullscreen-flvplayer", sizes[1], sizes[2], "9.0.0", pathToSwfs+"expressInstall.swf", {autostart:'true'}, {}, {});
			}

			else {
				var flashvars = {
					"file": url,
                    autostart:'true'//,
					//"image": "video/Dynafit_Intro.jpg"
				};
				var params = {};
				var attributes = {};

				swfobject.embedSWF(pathToSwfs+"player.swf", "fullscreen-flvplayer", sizes[1], sizes[2], "9.0.0", pathToSwfs+"expressInstall.swf", flashvars, params, attributes);
			}



			var bg = $(this);
			bg.add("#fullscreen-close").click(function() {
				div.remove();
				bg.fadeOut(function() {
					$(this).remove();
				});
			});

		}));










		return false;
	});


	// nur ausführen, wenn lightbox wirklich eingebunden
	if ($.fn.lightBox) {
		//absolutePath = window.location.protocol == "file:" ? "" : "";
		// lightbox für gallery binden
		$(".imagegallery a, .lightbox").lightBox({
			overlayOpacity:0.92,
			imageLoading:pathToImages+'lightbox/ico-loading.gif',
			imageBtnPrev:pathToImages+'lightbox/btn-prev.gif',
			imageBtnNext:pathToImages+'lightbox/btn-next.gif',
			imageBtnClose:pathToImages+'lightbox/btn-close.gif',
			imageBlank:pathToImages+'lightbox/blank.gif',
			containerBorderSize:0
		});
	}









	// links mit highlight binden
    /*
	var selectors = ["bg-light", "bg-dark", "bg-emphasis"];
	for (var i = 0, selector; selector = selectors[i]; i++) {
		$("."+selector).not(".no-hover").each(function() {
			var thisContainer = $(this),
				theClass = selector;
			$("a", this).hover(function() {
				thisContainer.addClass(theClass+"-hover").removeClass(theClass);
			}, function() {
				thisContainer.addClass(theClass).removeClass(theClass+"-hover");
			});
		});
	}
    */

	$("a img, .embedFlashDirect").not(".no-hover").hover(function() {
			if ($(this).attr('class').indexOf('reverse') != -1) {
					$(this).css("opacity", 1);
			} else {
					$(this).css("opacity", 0.86);
			}
	}, function() {
			if ($(this).attr('class').indexOf('reverse') != -1) {
					$(this).css("opacity", 0.86);
			} else {
					$(this).css("opacity", 1);
			}
	});

	$("a img").each(function (i){
			if ($(this).attr('class').indexOf('reverse') != -1) {
					$(this).css("opacity", 0.86);
			}
	});
/*
	$("a img").not(".no-hover").hover(function() {
		$(this).css("opacity", 0.8);
	}, function() {
		$(this).css("opacity", 1);
	});
*/



	// füge zentrierung für centerimage hinzu
	$("img.centerimage").each(function() {
		var thisImage = $(this);

		replaceWith = $('<div></div>').css({
			"max-width": thisImage.width(),
			//"overflow": "hidden",
			//"position": "relative"
			"background-position": "center center",
			"background-repeat": "no-repeat",
			"background-image": "url("+this.src+")"
			}).height(thisImage.height());

		if (thisImage.not(".no-hover").closest("a").get(0) != undefined) {
			replaceWith.hover(function() {
				$(this).css("opacity", 0.8);
			}, function() {
				$(this).css("opacity", 1);
			});
		}

		thisImage.replaceWith(replaceWith);
	});








	// die Inhaltsboxen an das Grid anpassen
	var gridBoxes = $("div.gridheight-1, div.gridheight-2, div.gridheight-3"),
		gridHeight = window.gridHeight || 143,
		//gridHeight = 72,
		gridPadding = 2;

	function onResizeGrid() {
		gridBoxes.each(function() {
			thisDiv = $(this);

			this.originalMinHeight = this.originalMinHeight || thisDiv.css("min-height");

			thisDiv.css("min-height", this.originalMinHeight);
			//thisDiv.height("auto");
			thisHeight = thisDiv.height();
			nrOfCells = Math.ceil((thisHeight-gridHeight)/(gridHeight+gridPadding)) + 1;

			//console.log(thisHeight + " => " + nrOfCells);
			//thisDiv.height(nrOfCells*gridHeight + (nrOfCells-1)*gridPadding);
			thisDiv.css("min-height", nrOfCells*gridHeight + (nrOfCells-1)*gridPadding);
		});
	}
	onResizeGrid();
	$(window).bind("resize", onResizeGrid);




	var fillers = $("div.fillheight");
	function onResizeFiller() {
		fillers.each(function() {
			var h = Math.max(0, 715-this.offsetTop);
			if (!h) $(this).hide();
			else $(this).height(h).show();
			// position on page
			//console.log(this.offsetTop)
			//console.log(this.offsetParent.offsetTop)
		});
	}
	onResizeFiller();
	$(window).bind("resize", onResizeFiller);

});

function swapImages (id) {

	var arrOfId = id.split('_');
	$('.' + arrOfId[0]).hide();
	$('#' + id).show();

}

function printPage () {

    var langId = $("#langid").val();
    if (langId == "") {
        langId = 0;
    }

	window.open("/index.php?id=" +$("#pageid").val() +"&L=" +parseInt(langId, 10) +"&type=98");

}
