// create print page link on the fly if key items are supported
var PRINT_TEXT = 'Diese Seite drucken';
var hasPrintFeature = (window.print) ? true : false;

if (hasPrintFeature && (document.createElementNS || document.createElement) && document.createTextNode && document.insertBefore && document.appendChild) {
    var a = document.createElement('a');
    a.setAttribute('href', '#');
    a.onclick = function() {
        window.print();
        return false;
    }
    var img = document.createElement('img');
    a.setAttribute('title', PRINT_TEXT);
    img.setAttribute('title', PRINT_TEXT);
    img.setAttribute('src', '/images/insm/drucker_icon.gif')
    a.appendChild(img);
    a.appendChild(document.createTextNode(PRINT_TEXT));
    var refNode = document.getElementById('toolbar');
    if (refNode) {
        refNode.appendChild(a);
    }
}

var agt = navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_ie    = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie5   = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_ie5_5 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
var is_ie6   = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );

$.fn.extend({
	createLinkButton: function(s){
		s = $.extend({
			hiddenClass: 'aural',
			focusClass: 'focused'
		}, s);
		return this.each(function(){
			var $this = $(this);
			var id = $this.attr('id');
			var $label = $('label[for=' + id + ']:first');
			var labelVal = $label.html();
			var classnames = this.className;
			$label.html('<span><span><span><span>' + labelVal + '</span></span></span></span>');
			if ($this.is('[type=radio]')) {
				$this.addClass(s.hiddenClass).focus(function(){
					$label.addClass(s.focusClass);
				}).blur(function(){
					$label.removeClass(s.focusClass);
				});
				$label.click(function(){
					var $this = $(this);
					var iID = $this.attr('for');
					$('#' + iID).attr({
						checked: 'checked'
					});
					$(this).parents('form:first').trigger('submit');
					return false;
				}).addClass(classnames);
			} else {
				var val = $this.val();
				id = (id) ? 'id=' + id : '';
				var link = $this.after('<a href="#" ' + id + ' class="' + classnames + '"><span><span>' + val + '</span></span></a>').next('a');
				link.click(function(){
					$(this).parents('form:first')[0].submit();
					return false;
				}).end().remove();
			}

		});
	}
});


$(document).ready(function() {
	var height = 0;
	$('input.button').createLinkButton();
	$('div.answer-box:first')
		.find('.answer')
			.each(function() {
				height = height < this.offsetHeight ? this.offsetHeight : height;
			})
			.each(function(i) { 
				$('div.answer-box:first .answer:eq('+i+')').css('height',height);
			});
	})

