jQuery.noConflict();

/*Scale background image to show complete photos, not part of them.*/
var pph_background = {
	'left': null,
	'right': null,
	'fill': function() {
		var hi = jQuery(this).height();
		var hw = jQuery(window).height();
		if(hi < hw)
		{
			var s = ~~(hw/hi+1);
			for(var i =0; i < s; ++i)
			{
				jQuery(this).parent().append(jQuery(this).clone());
			}
		}
	},
	'draw': function(context) {
		if(this.left)
		{
			jQuery(this.left).remove();
		}
		if(this.right)
		{
			jQuery(this.right).remove();
		}
		var diffX = jQuery(document.body).width()-jQuery("#contener").width();
		diffX = ~~(diffX / 2);
		jQuery(document.body).css("background", "none");
		if(diffX > 100)
		{
			var imgLeft;
			var imgRight;
			var divLeft;
			var divRight;
			
			this.left = jQuery('<div></div>')
				.css("position", "fixed")
				.css("top", "0")
				.css("left", "0")
				.css("width", diffX)
			;
			
			this.right = jQuery('<div></div>')
				.css("position", "fixed")
				.css("top", "0")
				.css("right", "0")
				.css("width", diffX)
			;
			
			jQuery(document.body).height()
			imgLeft = jQuery("<img src=\"../site/img/bodyBgLeft.jpg\" style=\"width: 100%\">");
			divLeft = jQuery('<div></div>')
				.css("width", "100%")
				.css("max-width", "364px")
				.css("overflow", "hidden")
				.css("height", jQuery(document.body).height())
				.css("text-align", "right")
				.css("margin-left", "auto")
				.append(imgLeft)
			;
			imgRight = jQuery("<img src=\"../site/img/bodyBgRight.jpg\" style=\"width: 100%\">");
			divRight = jQuery('<div></div>')
				.css("width", "100%")
				.css("max-width", "364px")
				.css("overflow", "hidden")
				.css("height", jQuery(document.body).height())
				.append(imgRight)
			;

			this.right.append(divRight);
			this.left.append(divLeft);
			
			jQuery(imgLeft).load(this.fill);
			
			jQuery(imgRight).load(this.fill);
			
			jQuery(document.body).append(this.left);
			jQuery(document.body).append(this.right);
			
		}
	},
	
	"init": function() {	
		jQuery(window).resize({'ctx': this}, function(e) {
			e.data.ctx.draw();
		});
		this.draw();
	}
};

jQuery(document).ready(function() {
		pph_background.init();
});

