jQuery(document).ready(function(){
    var $Scroller = {
	scrollElement : "#PlayNowButtonType",
	scrollSpeed : 400,
	getDocumentScrollHeight: function(){
	    var h = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;
	    return h ? h : 0;
	},
	getScrollHeight : function(){
	    var h = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
	    return h ? h : 0;
	},
	animateScroll : function(){
	    var self = $Scroller,
		documentHeight = self.getDocumentScrollHeight(),
		adjustPosition = ((documentHeight + self.getScrollHeight()) - jQuery(self.scrollElement).height()) - 7;

	    jQuery(self.scrollElement).stop().animate({
		'top': adjustPosition + 'px'
	    },self.scrollSpeed);
	},
	init : function(){
	    var self = $Scroller;

	    function jsondatatest(){
			var test = -1;
			try {
				if(typeof(buttonscroll.promotions) == 'object'){
					 if(typeof(buttonscroll.imageURL) != 'undefined'){
						test = buttonscroll.imageURL.indexOf('.jpg') < 0 ? -1 : 1;
						test = test > 0 ? 1 : buttonscroll.imageURL.indexOf('.jpeg') < 0 ? -1 : 1;
						test = test > 0 ? 1 : buttonscroll.imageURL.indexOf('.gif') < 0 ? -1 : 1;
						test = test > 0 ? 1 : buttonscroll.imageURL.indexOf('.png') < 0 ? -1 : 1;
						test = test > 0 ? 1 : buttonscroll.imageURL.indexOf('.bmp') < 0 ? -1 : 1;
						if(typeof(buttonscroll.outclickURL) != 'undefined'){
							 return test;
						}
					 }
					 return test;
				}
			}
			catch(e) {
			}
		return test;
		}

	    if(typeof($(self.scrollElement)) == 'object' && jsondatatest() > 0 ){

		var documentHeight = self.getDocumentScrollHeight(),
		    topPosition = ((documentHeight + self.getScrollHeight()) - jQuery(self.scrollElement).height()) - 7;

		jQuery(self.scrollElement).css({
		    'top': topPosition  + 'px',
		    'display': 'block'
		});

		jQuery(window).scroll(function(){
		    self.animateScroll();
		});

		jQuery(window).resize(function(){
		    self.animateScroll();
		});
	    } else { return false; }
	}
    };

    $Scroller.init();
});