function getOffset(elem) {
	if (elem==null) return;
    if (elem.getBoundingClientRect) {
        return getOffsetRect(elem)
    } else {
        return getOffsetSum(elem)
    }
}

function getOffsetSum(elem) {
    var top=0;
    while(elem) {
        top = top + parseInt(elem.offsetTop)
        elem = elem.offsetParent
    }
    return top;
}

function getOffsetRect(elem) {
    var box = elem.getBoundingClientRect()
    var body = document.body
    var docElem = document.documentElement
    var scrollTop = window.pageYOffset || docElem.scrollTop || body.scrollTop
	var clientTop = docElem.clientTop || body.clientTop || 0
    var top  = box.top +  scrollTop - clientTop
    return Math.round(top);
}

function positionRightBanner() {
		positionScreen = jQuery(window).scrollTop();
		rightBlockHeight = $("#rightFrame").height() + getOffset(document.getElementById("rightFrame"));
		if (rightBlockHeight < positionScreen) {
			$(".fixedBanner").css("position", "fixed");
			$(".fixedBanner").css("top", "10px");
		} else {
			$(".fixedBanner").css("position", "relative");
		}
}

$(document).ready(function() {
	positionRightBanner();
});

$(window).resize(function() {
	positionRightBanner()				
});	

$(window).scroll(function() {
	positionRightBanner()				
});
	
