$(document).ready(function()
{	
	
	$.sideAd = {
		elAd: false,
		scrollScale: false,
		
		elSwf: false,
		intAddHeight: 0,
		
		init: function()
		{
			$.sideAd.elAd = $('#add');
			
			$.sideAd.scrollScale = ( $(window).height() / $(document).height() ) * 100;
			
			$.sideAd.intAddHeight = $.sideAd.elAd.height();
			
			$(window).scroll(function()
			{
				var intHeight = $.sideAd.setHeight();
				$.sideAd.getFlash('advertisement').onScroll( intHeight );
			});
		},
		
		getFlash: function(strId)
		{
			return (navigator.appName.indexOf("Microsoft") != -1) ? window[strId] : document[strId];
		},
		
		setHeight: function()
		{
			var intHeight 		= Math.round(( $.sideAd.scrollScale * ($(window).height() - 40)) / 100);
			var intPerc 		= ($(window).scrollTop() / ($(document).height() - $(window).height())) * 100;

			var intY			= Math.round(20 + (intPerc * ($(window).height() - intHeight - 40)) / 100);
			var targetY			= intY + (intHeight / 2);
			
			if ($.browser.msie && $.browser.version.substr(0,1) < 7)
			{
				$.sideAd.elAd.css({ top: targetY + $(window).scrollTop() - 100 });
			}
			else
			{
				if ((($(window).scrollTop() + $(window).height()) + 200) < $(document).height())
				{
					$.sideAd.elAd.css({ top: targetY - 40 });
				}
			}
			
			return targetY;
		}
	}
	
	$.sideAd.init();
	
});