(function($) {
  $.fn.fixOverlap = function() {
 	if ($('body').hasClass('max726')){
			height = 726;
	} else if ($('body').hasClass('max780')){
			height = 780;
	} else if ($('body').hasClass('max846')){
			height = 846;
	} else if ($('body').hasClass('max1075')){
			height = 1075;
	} else {
		height = 626;
	}
	var boxBottom = {};
		boxBottom.e = $('.boxBottom');
	var boxRight = {};
		boxRight.e = $('.boxRight');
	var win = {};
		win.e = $(window);

	function getSize() {
		win.x = win.e.width();
		win.y = win.e.height();
		
		boxBottom.e.each(function(){
			var bb = jQuery(this);
			bb.y = bb.outerHeight(true);

			var diff = {};
		    diff.y = height - bb.y;

			if (win.y > height) {
		        bb.css({
		          'bottom' : 0,
		          'top' : 'auto'
		        });
	      	} else {
		        bb.css({
		          'bottom' : 'auto',
		          'top' : diff.y
		        }); 
		    }
		});

		boxRight.e.each(function() {
			var br = jQuery(this);
			br.x = br.outerWidth(true);

			var diff = {};
		    diff.x = 1044 - br.x;

			if (win.x > 1044) {
		        br.css({
		          'right' : 0,
		          'left' : 'auto'
		        });
	      	} else {
		        br.css({
		          'right' : 'auto',
		          'left' : diff.x
		        });
		    }
		});

	}
    getSize();
    win.e.bind('resize', getSize);
  };

})(jQuery);


$(document).ready(function(){
	$('#collectionsLP, #storeLP, #studioStoreLP, #aboutPg, #customPg, #sidebarRight').fixOverlap();
});

