
var amountheadslide = 0;
var curhead = 0;
var slideinterval;

var aktuellaktuell = 1;

function doresize() {
	
	var pageheight = parseInt(jQuery(window).height());
	var headerheight = parseInt(jQuery("#headarea").height());
	var mainheight = parseInt(jQuery("#contaround").height());
	var fullheight = headerheight + mainheight;
	
	if (fullheight < pageheight) {
		var difference = pageheight - headerheight;
		jQuery("#main").css("height", String(difference) +"px");
	} else {
		var difference = jQuery("#contaround").height() + 100;
		jQuery("#main").css("height", String(difference) +"px");
	}
	
}

function aktuellmove(direction) {
	var amountaktuell = jQuery("#aktuelltable table tr").length;
	var newpos = aktuellaktuell;
	
	if (newpos > 1 && direction < 0) {
		newpos -= 1;
	}
	
	if (newpos < amountaktuell && direction > 0) {
		newpos += 1;
	}
	
	if (newpos == 1) {
		if (jQuery("#slidereturn").hasClass("switchon"))
		jQuery("#slidereturn").removeClass("switchon");
	} else {
		if (!jQuery("#slidereturn").hasClass("switchon"))
		jQuery("#slidereturn").addClass("switchon");
	}
	
	if (newpos == amountaktuell) {
		if (jQuery("#slidecontinue").hasClass("switchon"))
		jQuery("#slidecontinue").removeClass("switchon");
	} else {
		if (!jQuery("#slidecontinue").hasClass("switchon"))
		jQuery("#slidecontinue").addClass("switchon");
	}
	
	var getimage_html = "";
	var gettext_html = "";
	
	jQuery("#aktuelltable table tr:nth-child("+ String(newpos) +")").each(function () {
		/*
		var gimagecode = "";
		var gtextcode = "";
		jQuery(this).children("td").children(".alignleft").each(function () {
			if (jQuery(this).parent("a").length > 0) {
				var link_href = jQuery(this).parent("a").attr("href");
				gimagecode += '<a href="'+ link_href +'" target="_blank">' + jQuery(this).parent("a").html() + '</a>';
			} else {
				//gimagecode += jQuery(this).html();
			}
		});
		getimage_html = gimagecode;
		
		jQuery(this).children("td").children("p").each(function () {
			gtextcode += '<p>'+ jQuery(this).html() +'</p>';
		});
		
		gettext_html = gtextcode;
		*/
		gettext_html = jQuery(this).children("td").html();
	});
	
	//var outputhtml = '<div id="aktuellimage">'+ getimage_html +'</div><div id="aktuelltext">'+ gettext_html +'</div><div class="fix"></div>';
	
	var outputhtml = gettext_html;
	
	if (newpos == aktuellaktuell) {
		jQuery("#aktuellcontent").html(outputhtml);
		return true;
	}
	
	jQuery("#aktuellcontent:animated").stop();
	
	jQuery("#aktuellcontent").fadeOut(300, function () {
		jQuery(this).html(outputhtml);
		jQuery("#aktuellcontent").fadeIn(300, function () {
			jQuery(this).css('opacity','1');
			doresize();
		});
	});
	
	//jQuery("#aktuellcontent").html(outputhtml);
	
	aktuellaktuell = newpos;
}

function slide_head() {
	var lastone = curhead;
	var nextone = (lastone == amountheadslide) ? 1 : lastone + 1;
	//alert("Sliding: From:"+ curhead + " To:"+ nextone);
	
	if (lastone > 0)
		jQuery(".slideelement").children("img:nth-child("+ lastone +")").fadeOut(1000);
	
	jQuery(".slideelement").children("img:nth-child("+ nextone +")").fadeIn(1000, function () {
		jQuery(this).parent().css('backgroundImage','none');
	});
	
	curhead = nextone;
}

function restoreorgnavhigh() {
	jQuery(".highlight").removeClass("highlight");
	jQuery(".orgnavhigh").addClass("highlight");
}

jQuery(window).resize(function () { doresize(); });

jQuery(document).ready(function () {
	//markcontent();
	window.setTimeout("doresize()", 500);
	
	jQuery("#contenttext table tr").each(function () {
		var full = 100;
		var amount = jQuery(this).children("td").length;
		var size = Math.round(full/amount,2);
		
		jQuery(this).children("td").each(function () {
			jQuery(this).css('width',String(size) + '%');
		});
		
		jQuery(this).children("td").children(".box").each(function () {
			var parenthight = jQuery(this).parent("td").height();
			parenthight -= 9;
			jQuery(this).css('height',String(parenthight) +'px');
		});
	});
	
	jQuery("#navigation div").children("ul").children("li").children("a").each(function () {
		//var ttitle = jQuery(this).attr("title");
		var ttitle = jQuery(this).html();
		//ttitle = ttitle.toLowerCase();
		jQuery(this).html('<img src="'+ ptheme + 'button' + ttitle +'.gif" alt="'+ ttitle +'" />');
	});
	
	jQuery("#navigation .current_page_item, #navigation .current_page_ancestor").addClass("orgnavhigh");
	
	restoreorgnavhigh();
	
	if (jQuery(".slideelement").length > 0) {
		amountheadslide = jQuery(".slideelement").children("img").length;
		
		slide_head();
		slideinterval = window.setInterval("slide_head()", 6000);
	}
	
	jQuery("#navigation div").children("ul").children("li").mouseenter(function () {
		jQuery(".highlight").removeClass("highlight");
		jQuery(this).addClass("highlight");
	});
	
	jQuery("#navigation div").children("ul").mouseleave(function () {
		restoreorgnavhigh();
	});
	
	jQuery(".entry-content").children("p").addClass("directp");
	
	if (jQuery("#aktuelltable").length > 0) {
		aktuellmove(0);
		jQuery("#slidereturn").click(function () {
			aktuellmove(-1);
		});
		
		jQuery("#slidecontinue").click(function () {
			aktuellmove(1);
		});
	}
	
	if (jQuery(".katalogbild").length > 0) {
		jQuery("#container").after('<div id="bigpic"></div>');
		
		jQuery(".katalogbild a").each(function () {
			var tlink = jQuery(this).attr("href");
			jQuery(this).attr("href","#");
			jQuery(this).mouseenter(function () {
				var timage = jQuery(this).children("img").attr("alt");
				var tthml = '<img src="'+ tlink +'" alt="'+ timage +'" />';
				jQuery("#bigpic").html(tthml);
				jQuery("#bigpic").show();
			});
		});
		
		jQuery(".katalogbild a").mousemove(function (event) {
			var use_x = event.pageX + 20;
			var use_y = event.pageY + 20;
			
			jQuery("#bigpic").css({
				'top': use_y + 'px',
				'left': use_x + 'px'
			});
		});
		
		jQuery(".katalogbild a").mouseleave(function () {
			jQuery("#bigpic").hide();
		});
	}
	
});

