if (navigator.userAgent.match(/iPad/i)) {
	document.write('<meta name="viewport" content="width=1024" />');
	document.getElementsByTagName('html')[0].className = 'view-ipad';
}

jQuery(document).ready(function($){
	if ($(".fadehauptbild").length) {
		$.getScript("fileadmin/templates/js/jquery/cycle/jquery.cycle.all.min.js", function(){
			$(".fadehauptbild").eq(0).parent("div").cycle({
				fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
			});
		});
	};
	if ($("body.tv-template_5").length) {
		if ($("body.page_startseite").length==0) $("#stage_inner2").css( "min-height", parseInt ($(window).height() - 30 - $("#head").outerHeight() - $("#foot").outerHeight() - ( $("#page_wrap").outerHeight()-$("#page_wrap").innerHeight() ) ) );
		$("#page_wrap").css( "min-height", parseInt ($(window).height() - 30 - ( $("#page_wrap").outerHeight()-$("#page_wrap").innerHeight() ) ) );
		$(window).resize(function() {
			if ($("body.page_startseite").length==0) $("#stage_inner2").css( "min-height", parseInt ($(window).height() - 30 - $("#head").outerHeight() - $("#foot").outerHeight() - ( $("#page_wrap").outerHeight()-$("#page_wrap").innerHeight() ) ) );
			$("#page_wrap").css( "min-height", parseInt ($(window).height() - 30 - ( $("#page_wrap").outerHeight()-$("#page_wrap").innerHeight() ) ) );
		});
	}
	function fixMenupositions() {
		var _wL = 0;
		$("body.tv-template_5 #menu_container ul#headmenu > li[class!='']").each(function(index){
			_wL =  _wL + parseInt($(this).width());
			if ($("body.tv-template_5 #menu_container ul#headmenu > li[class!='']").length == (index+1)) {
				_dWi = parseInt($("body.tv-template_5 #menu_container ul#headmenu").width()) - _wL;
				if (_dWi > 0) {
					if ($.browser.msie && parseInt($.browser.version) > 8) _dWi = _dWi-1;
					$("body.tv-template_5 #menu_container ul#headmenu > li[class!='']").last().find("a").css('border-right','none').css(
						'min-width',
						parseInt($("body.tv-template_5 #menu_container ul#headmenu > li[class!='']").last().find("a").eq(0).width() + _dWi + 2) + 'px'
					);
				}
			}
		});		
		$("body.tv-template_5 #menu_container ul#headmenu li ul").each(function(index){
			$(this).css({'visibility':'hidden', 'display':'block'});
			if ($(this).offset().left + $(this).outerWidth() > $(window).width()) {
				_dW = ( $(this).offset().left + $(this).outerWidth() ) - $(window).width();
				$(this).css('left', ($(this).position().left - _dW - 0) + 'px');
			}
			if ($("body.tv-template_5 #menu_container ul#headmenu li ul").length == (index+1)) {
				window.setTimeout(function(){
					$("body.tv-template_5 #menu_container ul#headmenu li ul").css({'visibility':'visible', 'display':'none'});
				},500);
			}
		});
	}
	if ($("body.tv-template_5").length) {
		fixMenupositions();
		$(window).resize(function() {
			fixMenupositions();
		});
	}
	
	if ($("body.tv-template_13 #headslider ul li").length > 1) {
		$.getScript("/fileadmin/templates/js/jquery/anythingslider/jquery.easing.1.2.js", function(){
			$.getScript("/fileadmin/templates/js/jquery/anythingslider/jquery.anythingslider.js", function(){
				$("#headslider").anythingSlider({
					easing: "easeInOutExpo",     	 // Anything other than "linear" or "swing" requires the easing plugin
					autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
					delay: 6000,                    // How long between slide transitions in AutoPlay mode
					startStopped: false,            // If autoPlay is on, this can force it to start stopped
					animationTime: 700,             // How long the slide transition takes
					hashTags: true,                 // Should links change the hashtag in the URL?
					buildNavigation: false,          // If true, builds and list of anchor links to link to each slide
					pauseOnHover: false,             // If true, and autoPlay is enabled, the show will pause on hover
					forwardText: "",                // Start text
					backText: "",               // Stop text
					navigationFormatter: null	 // Details at the top of the file on this use (advanced use)
				});
			});
		});
	}
	if ($("body.tv-template_13").length) {
		$("a:contains('mehr')").each(function(){
			$(this).addClass("boxpfeil").text($(this).text().replace(/»/,'').replace(/&raquo;/,'').replace(/&nbsp;/,''));
		});
		$.getScript("/fileadmin/templates/js/jquery/jScrollPane/jquery.mousewheel.js", function(){
			$.getScript("/fileadmin/templates/js/jquery/jScrollPane/jquery.jscrollpane.min.js", function(){
				$('#inhalt_container .news-latest-container').jScrollPane();
			});
		});
		
		$("#inhalt_container .csc-textpic-border .csc-textpic-imagewrap").each(function(){
			if (!$(this).find(".csc-textpic-imagerow").length) {
				var galObj = this;
				$(galObj).addClass("js-imagewrap-gallery");
				var galLiWidth = 0;
				$(this).find("ul li").each(function() {
				    galLiWidth += parseInt($(this).width(), 10);
				});
				//alert(galLiWidth);
				if (galLiWidth>472) {
					$.getScript("/fileadmin/templates/js/jquery/jcarousel/jquery.jcarousel_0.2.7_burg-webkit-fix.js", function(){
						window.setTimeout(function(){
							$(galObj).jcarousel({
								scroll: 1,
								easing: 'swing',
								animation: 'fast',
								initCallback: function() {
									$(".jcarousel-container .jcarousel-prev, .jcarousel-container .jcarousel-next").each(function(){
										$(this).height( $(this).parent("div").eq(0).find(".jcarousel-clip").height() );
									})
								}
							});
						}, 50);
					});
				}				
			}
		});
		
		$("body.page_startseite .csc-frame-indent6633 a.internal-link").click(function(){
			$("#inhalt_container a[rel^='lightbox']").eq(0).click();
			return false;
		});
		
		/*
		if (navigator.userAgent.match(/iPad/i)) {
			$("head").append('<meta name="viewport" content="width=1024" />');
			$("body").addClass("view-ipad");
		}
		*/
		
	}
	
	$(".tt-products .csc-textpic-imagewrap a.lightbox").each(function(){
		$(this).attr('rel','lightbox[presentlb'+$(this).parents(".csc-textpic-imagewrap").eq(0).attr("id")+']');
	});
	
});

