;(function($){
	$.bgStretch = {
		container: null,
		img: null,

		options: {
			imgW: 0,
			imgH: 0,
			containerID: "#"
		},

		init: function(opt) {
			$.extend(this.options,opt);

			this.container = $(this.options.containerID);
			this.img = this.container.find("img");
			if(this.options.imgW == 0) {
				this.options.imgW = this.img.width();
				this.options.imgH = this.img.height();
			}
			return this;
		},

resize: function() {
            if($("#bodywrap").length > 0) {
                var wh = $(window).height();
                var ww = $(window).width();
                //var marg = (wh - $("#logo").outerHeight() - $("#navi-container").outerHeight() );
                //$("#inhalt").css("margin-top",marg+"px");

		var marg = 0;
		/*
		var marg = parseInt(this.container.css('margin-top')) + parseInt(this.container.css('margin-bottom')) + parseInt(this.container.css('padding-top')) + parseInt(this.container.css('padding-bottom'));
		marg = marg + parseInt(this.img.css('margin-top')) + parseInt(this.img.css('margin-bottom')) + parseInt(this.img.css('padding-top')) + parseInt(this.img.css('padding-bottom'));
		*/

		//if(document.getElementById('spalte1')) {
		if(document.body.id == 'violin_detail') {
		  var s = $('#spalte1');
		  marg = marg + parseInt(s.css('margin-top')) + parseInt(s.css('margin-bottom')) + parseInt(s.css('padding-top')) + parseInt(s.css('padding-bottom'));
		  var h = $('.heading');
		  var top = h.height() + parseInt(h.css('padding-top')) + parseInt(h.css('padding-bottom'));
		  var imgRatio = this.options.imgW / this.options.imgH;
		  var cw = this.container.width();
		  var ch = this.container.height();
		  var contRatio = cw / ch;
		  if(ch != wh) {
		    var imgH = wh - (top + marg + 4);
		    var imgW = imgH * imgRatio;
		    //this.container.css({width:imgW + "px",height:imgH + "px"});
		    //this.img.css({width:imgW + "px",height:imgH + "px"});
		    this.img.css('width', imgW + 'px');
		    this.img.css('height', imgH + 'px');
		    //var top = (ch - this.img.height() + 10) / 2;
		    //this.img.css({"margin-top":0}); //top+"px" war aus hf, weil dort noch Text über dem Bild war; ich weiss nicht, wie ich diese Abfrage wegkriege...
		  }
		  else {
		    //this.img.css({width:"auto",height:ch+"px","margin-top":0});
		  }
	       
		} else {
		  var imgRatio = this.options.imgH / this.options.imgW;
		  var altImgRatio = this.options.imgW / this.options.imgH;
		  var cw = this.container.width();
		  var ch = this.container.height();
		  
		  var contRatio = ch / cw;
		  var imgW = ww;
		  var imgH = ww * imgRatio;
		  if(imgH < wh) {
		    var imgH = wh;
		    var imgW = wh * altImgRatio;
		  }
		  //this.container.css({width:imgW + "px",height:imgH + "px"});
		  this.img.css({width:imgW + "px",height:imgH + "px"});
		  //var top = (ch - this.img.height() + 10) / 2;
		  //this.img.css({"margin-top":0}); //top+"px" war aus hf, weil dort noch Text über dem Bild war; ich weiss nicht, wie ich diese Abfrage wegkriege...

		}
	    
            }
            else {
	      //var imgRatio = this.options.imgH / this.options.imgW;
	      var imgRatio = this.options.imgW / this.options.imgH;
                var cw = this.container.width();
                var ch = this.container.height();

	      var imgW = cw;
	      var imgH = cw * imgRatio;
                this.img.attr({
                    width: imgW,
                    height: imgH
                })
            }
	    
            return this;
	    
        } 
	}
})(jQuery);

$(document).ready(function(){
	$.bgStretch.init({
		containerID: "#banner"
	}).resize().resize();
	$(window).bind("resize", function(e) {
		$.bgStretch.resize();
	})
});

