﻿(function($){
	$.fn.swftable=function()
	{
		$(this).each(function(){
	 		var jTable = $(this).addClass("SWF-Table").attr({cellpadding:0,cellspacing:0});
	 		var jHead = jTable.children("thead");
	 		var jBody = jTable.children("tbody");
	 		if(jHead.length == 0)
	 		{
		 		var colspan = 0;
	 			jBody.find("tr:first td").each(function(i){
	  			colspan += this.colSpan;
	 			});
	 			jTable.prepend('<thead><tr><td colspan="'+ colspan +'" class="SWF-CornersTop">'+$.fn.swftable.htmlCornerTop+'</td></tr></tr></thead>');
	 			jHead = jTable.children("thead");
	 			jHead.append(jBody.children("tr:first").children("td:first").addClass("SWF-CornersLeft").siblings("td:last").addClass("SWF-CornersRight").parent());
	 			jBody.children("tr:last").addClass("SWF-TableLastRow");
	 			jBody.children("tr:even").addClass("SWF-Odd");
	 			jBody.find("tr>td:last-child").addClass("SWF-TableLastCol");
	 			jBody.find("tr>td").each(function()	{	if($(this).text()=='') $(this).html("&nbsp;"); });
	 		}
 		});
	}
	$.fn.swftable.htmlCornerTop = '<table cellspacing="0" cellpadding="0" class="SWF-CornersTop"><tbody><tr><td class="SWF-BordersLeft"></td><td class="SWF-BordersMiddle">&nbsp;</td><td class="SWF-BordersRight"></td></tr></tbody></table>';
})($itacs.$);
(function($){
	$.fn.swfsearch=function(options)
	{
		var opts = $.extend({}, $.fn.swfsearch.defaults, options);
		var jInput = $(this).find(".tnInput");
		jInput.data("swfsearch",opts);
		//hover for SearchBtn
		var jBtn = $(this).find(".tnSearchBtn")
		.hover(function(){$itacs.$("li.tnSearch").addClass("tnSearchHover");},function(){$itacs.$("li.tnSearchHover").removeClass("tnSearchHover");})
		.click(function(evt){evt.preventDefault();fire(jInput);});
		jInput.keypress(function(evt){
			if(evt.keyCode == '13'){
				evt.preventDefault();
				fire(jInput);
			}
		});
 		var match = $.fn.swfsearch.regK.exec(window.location.search);
 		if(match){	 		
 			var k = match[3];
 			jInput.val(k);
 		}
	}
	function fire(jInput){
		var result = jInput.data("swfsearch").result;
		//if(window.location.search == "" || window.location.pathname != result){
			window.location = result +"?k="+jInput.val()+window.location.hash; 
		/*} else{ var match = $.fn.swfsearch.regK.exec(window.location.search); if(match){ window.location = result+match[1]+match[2]+"k="+jInput.val()+match[4]+match[5]+window.location.hash; } else { window.location = result+window.location.search+"&k="+jInput.val()+window.location.hash; } }*/
	} 
	$.fn.swfsearch.regK = /(.*?)(\?|&)k=([^&#]*?)(&|$|#)(.*)$/;
	$.fn.swfsearch.defaults={result:'/Seiten/Suche.aspx'};
})($itacs.$);
(function($){		
	$.fn.adjustHeight=function(options)
	{
		var opts = $.extend({}, $.fn.adjustHeight.defaults, options);
		var	jSibling = $(opts.sibling);
		if(jSibling.length == 1)
		{
			var jThis = $(this);		
			var thisHeight = jThis.outerHeight();
			var siblingHeight = jSibling .outerHeight();
			if(siblingHeight > thisHeight)
			{
				jThis.height(siblingHeight);
			}
		}
	}
	$.fn.adjustHeight.defaults={sibling:''};
})($itacs.$);
$itacs.$(function() {
	//add round corners
	$itacs.$("div.SWF-TableArea:not(div.ms-formfieldvaluecontainer) table:not([class],[id]):visible").swftable();
	//position HeaderImage
	$itacs.$("div.SWF-HeaderImage").css("top",$itacs.$("span.SP-PubConsole").outerHeight());	
	//search functions
	$itacs.$(".tnSearch").swfsearch();
	//Page-image auto width in article pages
	$itacs.$("div.SWF-PageImage>table,div.SWF-PageImage td[id^='MSOZoneCell']>table").css({width:'auto'});
	//adjust right gray border height
	$itacs.$("div.SWF-ContentAreaOuter").adjustHeight({sibling:'.SWF-ContentRight'});
	//remove link Image from As with Image
	$itacs.$(".SWF-Text a:has(img),.SWF-Teaser a:has(img)").css({'background-image':'none','padding-left':'0'});
});
