jQuery.noConflict();

jQuery(document).ready(function($) {

	// superfish main dropdown menu --------------------
	$('#nav .hlist > ul').addClass('sf-menu');
	$('#nav li').addClass('sfHover');
	$('ul.sf-menu').superfish({
            delay:       500,                            // one second delay on mouseout 
            animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation 
            speed:       'fast',                          // faster animation speed 
            autoArrows:  false,                           // disable generation of arrow mark-up 
            dropShadows: false                            // disable drop shadows 
	});
	// eo superfish ------------------------------------


	// mitgliederliste ---------------------------------
	// uses prototype.js; breaks jquery, so use $ -> jQuery
	// fixed with http://docs.jquery.com/Using_jQuery_with_Other_Libraries
	mbrpage = $("#body-67").size();
	if (mbrpage) {
		// add tooltips to abbreviated th
		// jq too soon; need to wait for ajax...
		//ermaessigt = jQuery("th:contains('Erm.')");
		//if (ermaessigt) ermaessigt.attr("title", "Erm&auml;&slig;igt");
		
	}
	// eo mitgliederliste ------------------------------


	// literaturdatenbank ------------------------------
	litpage = $("#body-40").size();
	if (litpage) {
		// jump to form if page > 1
		ispage1 = $("div.longlist_pages").find("p:contains('Seite 1 von')").size();
		// jump to form if search value
		hassearch = $("div.tx-caglonglists-pi1 #searchfield").val();
		if (hassearch) hassearch = hassearch.length;
		// jump to form if sorted
		hassort = $("div.longlist_result tr.addresshead th span.sort-icon").size();
		if (!ispage1 || hassearch || hassort) document.location.hash='c290';
		
		// copy page nav buttons to top of form
		pagenav = $("div.longlist_pages p").clone();
		pagenav.addClass("litdb-pagenav-top");
		pagenav.insertBefore("div.longlist_result");
	}
	// eo literaturdatenbank ---------------------------
	

	// YOXVIEW -----------------------------------------
	// http://yoxigen.com/yoxview/usage.aspx
	
	// pages without yoxview
	var pages_no_yoxview = {
		// page id : 1 (1 = yox off, 0 = yox on)
		76 : 1	// straus - pflanzen
	};

	// "body-76" -> 76
	var page_id = parseInt($('body').attr('id').match(/\d+/)[0]);
	var do_yoxview = (pages_no_yoxview[page_id] == undefined);
	
	if ( do_yoxview ) {

		var yoxviewOptions = {
			lang : 'de',
			playDelay : 6000,
			titleDisplayDuration : 4500,
			controlsInitialDisplayTime : 4500,
			renderInfoPin : true
		};

		// create custom :image selector
		// http://jquery-howto.blogspot.com/2009/06/find-select-all-external-links-with.html
		$.expr[':'].imagejpg = function(obj) {
			return obj.href.match(/.*\.jpg$/i);
		};
		
		// copy img alt to title if empty...
		$('a > img').attr('title', function(){ return $(this).parent().attr('title'); });

		// enable yoxview for teaser
		$("#teaser p.gallery-single").addClass("yoxview");

		// begin : enable yoxview for content ---------------------
		
		// get links to images in content
		var imgLinks = $("#col3_content a:imagejpg");

		// list linked jpg images in order on page
		var imgList = new Array();
		imgLinks.each(function(index, a) {
			// add image only if anchor wraps jpg image
			//if ( $(this).children("img").attr("src").match(/.*\.jpg$/i) )
			var img_src = $(this).children("img").attr("src");
			//if ( ( page_id == 76) || (img_src && (img_src.match(/.*\.jpg$/i))) ) 
			if ( img_src && (img_src.match(/.*\.jpg$/i)) ) 
				imgList.push( { media: { src: a.href, title: a.title } } );
		});
		
		// attach image list to parent of each image link
		imgLinks.each(function(index) {
			var imgLink = $(this);
			// list2 = list + list
			var list2 = imgList.concat(imgList);
			
			// find linked image in list -> #
			var imgPath = imgLink.attr("href");
			var imgNum = -1;
			for ( i=0; i < imgList.length; i++ ) {
				if ( imgList[i].media.src.lastIndexOf(imgPath) > -1 ) {
					// imgPath found at end of src
					imgNum = i;
					break;
				}
			}
			
			if ( imgNum == -1 ) return false;
			
			// get slice of list2: start at #+1, take length - 1 items
			var imgListSlice = list2.slice(imgNum + 1, imgNum + imgList.length);
			
			// attach slice to parent of link
			imgLink.parent().yoxview( $.extend(yoxviewOptions, { images: imgListSlice }) );

		});
		// end : enable yoxview for content ---------------------

		// run yoxview on classes
		$(".yoxview").yoxview( yoxviewOptions );
	
	}
	
	// eo YOXVIEW --------------------------------------
	
	
	// totop link --------------------------------------
	//
	// insert totop link
	var location_nohash = location.href.split('#')[0];
	$('body').append('<div id="totop"><a href="' + location_nohash + '#' + '" title="Zum Seitenanfang (Taste: Pos1)"></a></div>');

	// on load, hide "to top" link
	$('#totop').fadeOut(0);
  var totop_visible = false;
	      
  var const_showatfraction = 0.5;
  var const_fadetime = 1000;
	      
	// show "to top" link when content is scrolled
	$(window).scroll(function () {
      
    var winheight = $(window).height();
    var scrolltop = $(window).scrollTop();
    
    if (scrolltop > winheight*const_showatfraction) {
      if (!totop_visible) $('#totop').fadeIn(const_fadetime );
      totop_visible = true;
    } else {
      if (totop_visible) $('#totop').fadeOut(const_fadetime );
      totop_visible = false;
    }
      
  });
  
  // invoke sroll event just in case
	$(window).scroll();
	
	// eo totop link -----------------------------------
	
	
	// table row rollover ------------------------------
	
	$('table.hover-hilite tbody tr').hover(
		function() { $(this).addClass('hilite'); },			// mouse-in
		function() { $(this).removeClass('hilite'); }		// mouse-out
	);
	
	// eo table row rollover ---------------------------

	
});

