function formattables(inhalt){
	var table=$(inhalt).find("table");
	table.css("table-layout","fixed");
	table.find("td").each(function(){
		// get any child width
		var widthelem=$(this).find("[width]:first");
		if(widthelem.attr("width")){
			$(this).attr("width",widthelem.attr("width"));
		}
		
		//set minwidth
		if($(this).attr("width")){
			$(this).css("min-width",$(this).attr("width")+"px");
		}
	});
};

function insertPlayer(inhalt){
	try {
		var baseurl=window.location.href;
		var firsthash=baseurl.indexOf('#');
		if(firsthash>0){
			baseurl=baseurl.substring(0,firsthash);
		}
		
		/*jwplayer("jwplayer").setup({
			flashplayer: "jwplayer.swf",
			controlbar: 'bottom',
			autostart: 'true',
			repeat: 'always',
			netstreambasepath: baseurl,
			wmode: 'transparent'
		});*/
		
		var p=inhalt.find("#jwplayer:first");
		var flashvars = { 
			file:p.attr('src'),
			autostart:'true',
			repeat: 'always',
			netstreambasepath: baseurl
		};
  		var params = { 
			controlbar: 'bottom',
			allowfullscreen:'true'
		};
  		var attributes = {};

 		swfobject.embedSWF (
			'jwplayer.swf',
			'jwplayer',
			p.attr('width'),p.attr('height'),'9.0.115','false',
			flashvars, params, attributes);
		
	} catch (e){};
}

function rotate13(s) {
	var b = [],c,i = s.length,a = 'a'.charCodeAt(),z = a + 26,A = 'A'.charCodeAt(),Z = A + 26;
	while (i--) {
		c = s.charCodeAt(i);
		if (c >= a && c < z) { b[i] = String.fromCharCode(((c - a + 13) % (26)) + a); }
		else if (c >= A && c < Z) { b[i] = String.fromCharCode(((c - A + 13) % (26)) + A); }
		else { b[i] = s.charAt(i); }
	}
	return b.join('');
};

function insertMail(inhalt){
	var mailtext=rotate13('znvy@wnaubrsg.qr');
	var t=inhalt.find(".linkmail");
	if(t.length>0){
		t.attr("href","mailto:"+mailtext);
	}
	var t=inhalt.find(".insertmail");
	if(t.length>0){
		t.text(mailtext);
	}
};

$(document).ready(function(){
	var i=$('.inhalt');
	if(i.length==0 ){
		i=$('body');
	}
	formattables(i);
	insertPlayer(i);
	insertMail(i);
});
