$(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()) - $(self.scrollElement).height()) - 7;

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

	    function jsondatatest(){
		var test = -1;
		if(typeof(buttonscroll) == 'object'){
		    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;
	    }

	    if(
		(typeof($(self.scrollElement)) == 'object' && jsondatatest() > 0 )){
		var documentHeight = self.getDocumentScrollHeight(),
		    topPosition = ((documentHeight + self.getScrollHeight()) - $(self.scrollElement).height()) - 7;

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

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

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

    $Scroller.init();
});
