// Skin Specific JS goes here. The jQuery library has already been loaded by the core templates. So if you use jQuery, you are ready to go.

$(function() {
// get some elements
	var mLoPageWrap = $("#mLoPageWrap");
	var feature = mLoPageWrap.find("#feature");	
	var mLoHeader = mLoPageWrap.find("#mLoHeader");	
	var footerWrap = $("#footerWrap");

	// add pflichtext modalbox
	footerWrap.find(".user-klproductsclient-pi2-mandatoryblockblock").pflichttextmodal();

// menu animations
	var globalMenuLis = mLoHeader.find("ul#globalMenu li ul");
// 	var subMenu = mLoHeader.children("ul#globalMenuSub");
// 	var originalSub = subMenu.html();
// 	var timer = false;
// 	var timerHover = false;
// 	var speedAni = 250;
// 	var speedTimer = 1500;
// 	var speedHoverTimer = 250;
// 	// triggers 
// 	globalMenuLis.parent("li").hover(
// 		function(){
// 			window.clearTimeout(timer);
// 			var el = $(this);
// 			timerHover = window.setTimeout(function() {
// 				subMenu.fadeOut(speedAni, function(){
// 					subMenu.html(el.children("ul").html())
// 					subMenu.fadeIn(speedAni);
// 				});		
// 			}, speedHoverTimer);	
// 		},
// 		function(){
// 			fadeToNothing();
// 		}
// 	);
// 	// do not change sub menu when users hovers
// // 	subMenu.hover(
// // 		function(){
// // 			window.clearTimeout(timer);
// // 			window.clearTimeout(timerHover);
// // 		},
// // 		function(){				
// // 			fadeToNothing();
// // 		}
// // 	);
// 	// show oiginal submenu with delay
// 	function fadeToNothing() {
// 		window.clearTimeout(timer);
// 		timer = window.setTimeout(function() {
// 			subMenu.fadeOut(speedAni);		
// 		}, speedTimer);	
// 	}
// slider
// 	var slider = mLoPageWrap.find("#contentBlock-2 #slide");	
// 	var headerHeight = mLoHeader.find("#mLoLogo").outerHeight();	
// 	// set events		
// 	$(window).scroll(function() {
// 		slider.dequeue(); 
// 		var pos = $(this).scrollTop() + headerHeight + 41;
// 			slider.animate({ top: pos + "px"}, 800, 'swing');
// 	});
	
// passive accordion (ex active)
	mLoPageWrap.find(".accordion").each(function(){
		$(this).children("div.csc-default").each(function(i, csc) {
			var el = $(csc).find("h1, h2").first();
			var link = "http://" + location.host + location.pathname + "#" + $(csc).attr("id");
			$(csc).before(el.wrapInner('<a href="' + link + '" />'));			
		});			
	})
	.accordion({
		navigation: false,
		autoHeight: false,
		collapsible: true,
		active: false
	});
	
// Klosterfrau Group Extended Footer
	// selectmenu for unordered list
	var uList = footerWrap.find('div#footerApoBlockBottom div#footerApoBlockBottomQuickfind ul');
	var header = uList.prev("h5").remove();
	var lis = '<option class="ui-state-disabled" value="">' + header.text() + '</option>';
	uList.children("li").each(function(index2) {
		lis += '<option class="pdf2" value="' + $(this).find("a").attr("href") + '">' + $(this).text() + '</option>';
	});		
	var select = $('<select/>', {
		// id: uList.attr("id"),
		id: uList.attr("class"),
		name: uList.attr("id"),
		html: lis
	});		
	uList.replaceWith(select);
	select.selectmenu({
		maxHeight: 150,
		change: function(event, data) {
				if (data.value != "") window.location.href = data.value;
			},
		icons: [
			{find: '.pdf2', icon: 'ui-icon-document'}
		]
	});	
	
	
// makes quick searchbar more quick to use :-)
	var quickSearch = mLoHeader.find("form#searchform input.quicksearch_searchfield");
	var quickSearchValue = quickSearch.val();
	quickSearch.bind("focus blur", function() {
		if ($(this).val() == quickSearchValue) $(this).val("");
		else if ($(this).val() == "") $(this).val(quickSearchValue);
	});	
});

