function toNumber(x){
	if(x){
		return parseInt(x);
	}else{
		return 0;
	}
}
$.fn.bgImage = function(options){
	var data = $.extend({
		img:'/static/img/bgBlockcontent.png',
		css:$.extend((options?options.css:null),{marginTop:10,marginLeft:15,marginRight:15})
	},options)
	this.each(function(){
		var obj = $(this);
		var objWidth = obj.outerWidth();
		var objHeight = obj.outerHeight();
		obj.css({textAlign:"left"})
		
		if(data.css.margin){
			data.css.marginRight = data.css.margin;
			data.css.marginLeft = data.css.margin;
			data.css.marginTop = data.css.margin;
			data.css.marginBottom = data.css.marginBottom;
		}
		
		var win = $(window);
		this.img = $("<img src='"+data.img+"' class='bg_image'/>").css({
			width:objWidth,
			height:objHeight, 
			marginBottom:-objHeight,
			marginRight:-objWidth,
			position:"relative",
			zIndex:1
		})
		
		this.content = $("<div class=\"content_inner\"></div>").css($.extend({
			width:(objWidth -(toNumber(data.css.marginRight) + toNumber(data.css.marginLeft))),
			height:objHeight - (toNumber(data.css.marginTop)+toNumber(data.css.marginBottom)),
			cursor:"default",
			background:"transparent",
			position:"relative",
			zIndex:2
		},data.css))
	
		this.content.append(obj.html());
		obj.html(this.img)
		this.img.after(this.content)		   
	})
		
	
	return this;
}
