// MSIE 6 Erkennung
if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
	var ieversion=new Number(RegExp.$1);
	if (ieversion<7 && ieversion>=6)
		var msie6 = 1;
	else
		var msie6 = 0;
}

// Fußzeile im IE 6 positionieren
function libNEWPOS() {
	newpos = setTimeout(function() {
		jQuery('#end').css('position','absolute');
		var p = jQuery("#footer");
		var position = p.position();
		jQuery('#end').css('top',position.top + 60 + 'px');
		libNEWPOS();
	}, 1000);
}

//jQuery.noConflict();

function get_dimensions() {
	var fensterbreite = jQuery(window).width();
	var fensterhoehe = jQuery(window).height();
	var calcfsh = fensterhoehe-100;
	var calcfsb = calcfsh * 1.2;
	
	jQuery('.scribd a').each (function(){
		var alter_link = jQuery(this).attr('href');
		jQuery(this).attr('href', jQuery(this).attr('href')+"&height="+calcfsh+"&width="+calcfsb+"");
	});
	
	jQuery('.scribd').hover(
		function() {
			jQuery(this).css({'filter' : 'alpha(opacity=60)', '-moz-opacity' : '.60', 'opacity' : '.60'});
		},
		function() {
			jQuery(this).css({'filter' : 'alpha(opacity=99)', '-moz-opacity' : '.99', 'opacity' : '.99'});
		}
	);
}

function libPATH() {
	jQuery('#path').addClass('js-on');
	jQuery('#pathmenu').addClass('js-on');

	jQuery('#pathmenu > ul > li > ul > li').each(
		function() {
			if (jQuery(this).children().length <= 1) {
				jQuery(this).addClass('nosub');
			}
		}	
	);
	
	jQuery('#pathmenu ul li ul li').hover(
		function() {
			jQuery(this).find('ul:first').show();
		},
		function() {
			jQuery(this).find('ul:first').hide();
		}
	);
}

function libLANG() {
	jQuery('#lang ul li').hover(
		function() {
			jQuery(this).find('ul:first').slideDown('fast');
		},
		function() {
			jQuery(this).find('ul:first').slideUp(1);
		}
	);
}

function libMEDIA() {
	jQuery('#media').cycle(
		{
			fx:     'fade',
			timeout: 3000,
			speed:   1250,
			random:  1
		}
	);
}

function libPRODUCTS() {
	if(jQuery('#col1 > .content_element > .csc-textpic > .csc-textpic-imagewrap > div').length > 1) {
		jQuery('#col1 > .content_element > .csc-textpic > .csc-textpic-imagewrap').after('<span id="prev">«</span><span id="next">»</span>');
	}
	jQuery('#col1 > .content_element > .csc-textpic > .csc-textpic-imagewrap > dl').each(
		function() {
			jQuery(this).find('dd').css('background-image','url(/fileadmin/content_tilo/produkte/icons/' + jQuery(this).find('dt > img').attr("title") + ')');
		}
	);
	jQuery('#col1 > .content_element > .csc-textpic > .csc-textpic-imagewrap').cycle(
		{
			fx:      'scrollHorz',
			timeout:  3500,
			speed:    250, 
			prev:    '#prev',
			next:    '#next',
			prevNextClick: function() {
				jQuery('#col1 > .content_element > .csc-textpic > .csc-textpic-imagewrap').cycle('pause');
			},
			pause:    1
		}
	);
}

function libPRODUCTSTOGGLE() {
	// Alle Elemente bis auf das erste schließen
	jQuery('#col2 h3').next('div').hide();
	jQuery('#col2 h3').next('div').next('div.more').hide();
	jQuery('#col2 h3:first').next('div').show();
	
	jQuery('#col2 h3:gt(0)').toggle(
		function() {
			jQuery(this).next('div').slideDown('fast');
			jQuery(this).next('div').next('div.more').slideDown('fast');
		},
		function() {
			jQuery(this).next('div').slideUp('fast');
			jQuery(this).next('div').next('div.more').slideUp('fast');
		}
	);
	
	jQuery('#col2 h3:first').toggle(
		function() {
			jQuery(this).next('div').slideUp('fast');
			jQuery(this).next('div').next('div.more').slideUp('fast');
		},
		function() {
			jQuery(this).next('div').slideDown('fast');
			jQuery(this).next('div').next('div.more').slideDown('fast');
		}
	);
}

function libPRODUCTMENU() {
	// Entsprechenden Abstand auf Oben hinzufügen, damit die Menüpunkte unten angeordnet sind
	jQuery("#productmenu>ul>li>ul>li>ul").each(
		function(i) {
//			jQuery(this).prepend('<li style="width: 126px; height: 75px; background: url(/fileadmin/content_tilo/productmenu/' + i + jQuery('html').attr('lang') + '.png) no-repeat top left"></li>');
			var padding_top = 482-jQuery(this).height();
			jQuery(this).css('padding-top', padding_top + 'px');
		}
	);

	var stopmenu = 0;
	jQuery('#productmenu>ul>li>ul>li').hover(
		function() {
			if (stopmenu == 0) {
				jQuery(this).addClass('hover');
				jQuery(this).find('ul:first').slideDown(600);
				jQuery('#media').cycle('pause');
				var index = jQuery('#productmenu>ul>li>ul>li').index(this);
				stopmenu = 1;
				setTimeout(function() {
					jQuery('#media :not(:eq(' + index + '))').css({'z-index' : '11'});
					jQuery('#media :eq(' + index + ')').css({'opacity' : '', 'z-index' : '10'});
					jQuery('#media :eq(' + index + ')').show();
					jQuery('#media :not(:eq(' + index + '))').fadeTo(400, 0.0);
					stopmenu = 0;
				}, 400);
			}
		},
		function() {
			jQuery(this).find('ul:first').slideUp(600);
			jQuery(this).removeClass('hover');
//			setTimeout(function() {
				jQuery('#media').cycle('resume');
//			}, 600);
		}
	);
}




function libBILDMENU () {
	/*EDITED 10-07-15, INNPULS - Sliderfunktion weg BIS ZEILE197 WEG!!!*/
	/*var stopmenu = 0;
	jQuery('#bildmenu li').hover(function(){
		if (stopmenu == 0) {
			jQuery(this).find('.bildmenutext').slideDown('slow');
			stopmenu = 1;
			setTimeout(function() {
				stopmenu = 0;
			}, 400);
		}
	},
	function(){
		jQuery(this).find('.bildmenutext').slideUp('slow');
	});*/
	

/* EDITED 20.07.2010, Innpuls, Philipp Seiler - Gesamtes Element mit Link wrappen */
	jQuery('#bildmenu li').hover(
		function() {
			aTagArr = jQuery(this).find('a')
			aTag = aTagArr[0]; // href des A-Tags
			aTagArrLen = aTagArr.length;
			
			if (aTagArrLen > 0) {
				jQuery('#bildmenu li').css({'cursor' : 'pointer'});
			}
			else {
				jQuery('#bildmenu li').css({'cursor' : 'default'});
			}
		}
	)
	
	jQuery('#bildmenu li').click(
		function() {
		// Ist ein A-Tag vorhanden, so wird dessen href als Link zur Verfügung gestellt
			if (aTagArrLen > 0) {
				document.location.href = aTag;
			}
			// Auf der PartnerNET Seite benötigen die Links "Anmelden" und "Passwort vergessen?" Anchors
			else {
				window.setTimeout('window.scrollTo(0, 520)',1);
			}
		}
	);
	
	
/*
	jQuery('#bildmenu li').hover(function(){
		jQuery(this).find('.bildmenutext').slideDown('slow');
	});
	jQuery('.bildmenutext').mouseleave(function(){
		jQuery(this).slideUp('slow');
	});
	jQuery('#bildmenu li').mouseleave(function(){
		jQuery(this).find('.bildmenutext').slideUp('slow');
	});
*/
}

function libSHOPPING() {
	jQuery("div.shopping_list").quickpaginate({ perpage: 16, pager : jQuery("#shopping_list_counter") });
	
	jQuery("li.showitems").click(function() {
		jQuery("#shopping_list_counter").html("");
		if (jQuery(this).attr("rel") == '') {
			var relText = "div.shopping_list";
		} else {
			var relText = "div." + jQuery(this).attr("rel");
		}
		jQuery("div.shopping_list").hide();
		jQuery("div.evenholz ul li").css({'background' : '#ffffff'});
		jQuery("div.even ul li").css({'background' : '#ebebeb'});
		jQuery(relText).show();
		jQuery(relText).quickpaginate({ perpage: 16, pager : jQuery("#shopping_list_counter") });
		clearTimeout(gruppeto);
		setTimeout(function() {
			jQuery("#gruppelist li ul").hide();
			if (msie6) {
				jQuery("#col2").show();
			}
		}, 500);
	});
	
	jQuery("li.showholzitems").click(function() {
		jQuery("#shopping_list_counter").html("");
		if (jQuery(this).attr("rel") == '') {
			var relText = "div.shopping_list";
		} else {
			var relText = "div." + jQuery(this).attr("rel");
		}
		jQuery("div.shopping_list").hide();
		jQuery("div.even ul li").css({'background' : '#ffffff'});
		jQuery("div.evenholz ul li").css({'background' : '#ebebeb'});
		jQuery(relText).show();
		jQuery(relText).quickpaginate({ perpage: 16, pager : jQuery("#shopping_list_counter") });
		clearTimeout(holzto);
		setTimeout(function() {
			jQuery("#holzlist li ul").hide();
			if (msie6) {
				jQuery("#col2").show();
			}
		}, 500);
	});
	
	jQuery('div.shopping_list li').toggle(
		function() {
			jQuery('div.shopping_list div.detail').hide();
			jQuery(this).parent().parent().find('.detail').css({'display' : 'inline-block'});
		},
		function() {
			jQuery(this).parent().parent().find('.detail').hide();
		}
	);
	
	jQuery('#gruppelist li').click(
		function() {
			jQuery("#gruppelist li ul").show();
			if (msie6) {
				jQuery("#col2").hide();
			}
			gruppeto = setTimeout(function() {
				jQuery("#gruppelist li ul").hide();
			}, 10000);
		}
	);
	
	jQuery('#holzlist li').click(
		function() {
			jQuery("#holzlist li ul").show();
			if (msie6) {
				jQuery("#col2").hide();
			}
			holzto = setTimeout(function() {
				jQuery("#holzlist li ul").hide();
			}, 10000);
		}
	);
}

function libZEBRA() {
	// Linie oberhalb der Zellen einfügen, außer der ersten
	jQuery("table.contenttable tr:gt(0)").find("td").addClass("bordertop");
	
	// Gerade und ungerade Zeilen farblich markieren
	/*
	jQuery("table.contenttable").find("tr:nth-child(even)").each(
		function(i) {
			if( 0 == jQuery(this).find("th").length ) {
				jQuery(this).addClass("even");
			}
		}
	);
	
	jQuery("table.contenttable").find("tr:nth-child(odd)").each(
		function(i) {
			if( 0 == jQuery(this).find("th").length ) {
				jQuery(this).addClass("odd");
			}
		}
	);
	*/
	
	// Hover Farben festlegen
	/*
	jQuery("table.contenttable tr:nth-child(odd)").hover(function(){
		jQuery(this).toggleClass("odd_over");
	},function(){
		jQuery(this).toggleClass("odd_over");
	});

	jQuery("table.contenttable tr:nth-child(even)").hover(function(){
		jQuery(this).toggleClass("even_over");
	},function(){
		jQuery(this).toggleClass("even_over");
	});
	*/
}

function libLEXIKON() {
	// Alle offenen Punkte im IE 6 schließen
	if (msie6) {
		jQuery("div.tx-wmcontact-pi1").slideUp('fast');
	}
	
	// Ersten Punkt immer geöffnet halten beim Start
	jQuery("div.tx-wmcontact-pi1:first p").show();
	jQuery("div.tx-wmcontact-pi1:first img").show();
	jQuery("div.tx-wmcontact-pi1:first").show();
	jQuery("div.lexikon:first p").show();
	jQuery("div.lexikon:first img").show();
	
	jQuery("div.lexikon h4").click(function() {
		// Überprüfen, ob aktueller Punkt sichtbar ist
		if (jQuery(this).parent().find("div.tx-wmcontact-pi1").is (":visible")) {
			// Aktuellen Punkt schließen
			jQuery(this).parent().find("p").slideUp('fast');
			jQuery(this).parent().find("img").slideUp('fast');
			jQuery(this).parent().find("div.tx-wmcontact-pi1").slideUp('fast');
		} else {
			// Alle offenen Punkte schließen
			jQuery("div.lexikon p").slideUp('fast');
			jQuery("div.lexikon img").slideUp('fast');
			jQuery("div.tx-wmcontact-pi1").slideUp('fast');
			
			// Aktuellen Punkt öffnen
			jQuery(this).parent().find("p").slideDown('fast');
			jQuery(this).parent().find("img").slideDown('fast');
			jQuery(this).parent().find("div.tx-wmcontact-pi1").slideDown('fast');
			
			// Fußzeile im IE 6 positionieren
			if (msie6) {
				newpos = setTimeout(function() {
					jQuery('#end').css('position','absolute');
					var p = jQuery("#footer");
					var position = p.position();
					jQuery('#end').css('top',position.top + 60 + 'px');
				}, 1000);
			}
		}
	});
	/*
	jQuery("div.lexikon h4").toggle(
		function() {
			// Alle offenen Punkte schließen
			jQuery("div.lexikon p").slideUp('fast');
			jQuery("div.lexikon img").slideUp('fast');
			jQuery("div.tx-wmcontact-pi1").slideUp('fast');
			
			// Aktuellen Punkt öffnen
			jQuery(this).parent().find("p").slideDown('fast');
			jQuery(this).parent().find("img").slideDown('fast');
			jQuery(this).parent().find("div.tx-wmcontact-pi1").slideDown('fast');
		},
		function() {
			// Aktuellen Punkt schließen
			jQuery(this).parent().find("p").slideUp('fast');
			jQuery(this).parent().find("img").slideUp('fast');
			jQuery(this).parent().find("div.tx-wmcontact-pi1").slideUp('fast');
		}
	);
	*/
}

function libTREE() {
	jQuery("ul.slidertree li:first").show();
}

function libSLIDER() {
	jQuery(window).bind("load", function() {
		jQuery("div#slider1").codaSlider()
	});
}

function libLOCATOR() {
	//if (document.getElementById("tx-locator_pi1_categories"))
		categorySelect('4');
}