jQuery.createXMLDocument = function(string){
	// removing whitespace
	var regExp = />\s+</g;
	string = string.replace(regExp , '><');

	var browserName = navigator.appName;
	var doc;
	if (browserName == 'Microsoft Internet Explorer'){
		var loader = new ActiveXObject('Microsoft.XMLDOM');
		loader.async = 'false'
		loader.loadXML(string);
		// Special dirty hack for XML2Object compatibility, thx Bill !
		doc = {};
		doc.childNodes = [];
		doc.childNodes[0] = loader.documentElement;
	} else {
		doc = (new DOMParser()).parseFromString(string, 'text/xml');
	}
	return doc;
};


jQuery.fn.centerX = function () {
    this.css("position","absolute");
    this.css("left", ( jQuery(window).width() - this.width() ) / 2+jQuery(window).scrollLeft() + "px");
    return this;
};



jQuery.fn.centerY = function () {
    this.css("position","absolute");
    this.css("top", ( jQuery(window).height() - this.height() ) / 2+jQuery(window).scrollTop() + "px");
    return this;
};


jQuery.fn.fitToScreen = function(){
	var refWidth = jQuery(window).width();
	var refHeight = jQuery(window).height();
	
	var ratio = this.height() / this.width();
	var newWidth = refWidth ;
	var newHeight = Math.round(newWidth * ratio);
	if (newHeight < refHeight) {
		newHeight = refHeight;
		newWidth = Math.round(newHeight / ratio);
	}
	this.width(newWidth);
	//this.height(newHeight);
	this.css("left",  Math.round((refWidth - this.width()) * .5));
	this.css("top", Math.round((refHeight - this.height()) * .5));
};




jQuery.fn.backgroundImageUrl = function(options) {
	if (options){
		return this.each(function(){
			$(this).css('backgroundImage','url:('+options+')');
		});
	}else {
		var pattern = /url\(|\)|"|'/g;
		return $(this).css('backgroundImage').replace(pattern,"");
	}
};

