
$(document).ready(function(){
	
	$(".Fixed img").css("top",458);
	$(".Fixed img").css("right",20);
	
	$(window).scroll(function() {
		if(parseInt($(".Fixed img").css("top")) < $(document).height() - ($("#Footer").height() + 300))
		{
			if($(window).scrollTop() + (($(window).height() / 2)) <  parseInt($('.Sidebox').eq(0).offset().top) + parseInt($('.Sidebox').eq(0).height()) + 30 )
			{
				$(".Fixed img").css("top",  parseInt($('.Sidebox').eq(0).offset().top) + parseInt($('.Sidebox').eq(0).height()) + 30 );
			}
			else if($(window).scrollTop() + (($(window).height() / 2)) < $(document).height() - ($("#Footer").height() + 300))
			{
				$(".Fixed img").css("top",$(window).scrollTop() + (($(window).height() / 2)));
			}
		}		
		else
		{
			if($(document).height() - ($("#Footer").height() + 301) > parseInt($('.Sidebox').eq(0).offset().top) + parseInt($('.Sidebox').eq(0).height()))
				$(".Fixed img").css("top",$(document).height() - ($("#Footer").height() + 301))
			else
				$(".Fixed img").css("top",parseInt($('.Sidebox').eq(0).offset().top) + parseInt($('.Sidebox').eq(0).height()) + 20)
		}
	})
});
