// 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");	

	// add pflichtext modalbox
	mLoPageWrap.find("#footerWrap .footerApoBlock .user-klproductsclient-pi2-mandatoryblockblock").pflichttextmodal();

// Klosterfrau Products	
	/*
	var klproduct = feature.find(".user-klproductsclient-pi1");  
	if (klproduct.length) {
		
		// tooltip for mantadory text
		klproduct.find("a.tooltip").tooltip({
			tooltipClass: "product"
		});
		
		// slide contents
		var headline = klproduct.find(".user-klproductsclient-pi1-detailview-L h2.accordion").css("cursor", "pointer");    
		var div = headline.next("div");
		div.hide();    
		headline.click(function () {
			div.slideToggle('slow');
		});
	}
	*/
	
// active accordion
	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: true,
		autoHeight: false,
		collapsible: true,
		active: false
	});

// Klosterfrau Group Extended Footer
	// selectmenu for unordered list
	var uList = mLoPageWrap.find('div#footerApoWrap 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'}
			// {find: '.pdf'} // für eigenes icon
		]
	});	
	
	
// 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);
	});	
});

