$(function(){

        // Scroll to top on pagination click
        $('.pagination').each(function()
        {
            $(this).click(function()
            {
                $('html, body').animate({scrollTop:0}, 'normal');
            });
        });

		$('.album-list .item-buy').unbind();
		$('.album-list .song-add').unbind();
		
		$('.album-list .item-buy').one('click',function ( event ){
			event.preventDefault();
			var self = $(event.target);
			Gogo.addToCart($(event.target).attr('id').split('_').pop(), 
				function(){ self.removeClass('item-buy').addClass('song-busy'); },
				function(){ self.removeClass('song-busy').addClass('item-cart'); self.attr('href','#') }
			);
		});

		$('.album-list .song-add').click(function ( event ){
			event.preventDefault();
			var self = $(event.target);
			Gogo.addAlbumToPlaylist($(event.target).attr('id').split('_').pop(),
				function(){ self.removeClass('song-add').addClass('song-busy'); },
				function(){ self.removeClass('song-busy').addClass('song-checked'); self.attr('href','#') }
			);
		});

        // When pagination is clicked...
	$(".magic-page").click(function() {
        if (/webkit/.test( navigator.userAgent.toLowerCase()) == false)
        {
            // Put the deep linking URI in the address bar
            top.document.location.replace(top.document.location.protocol + "//" +
                                              top.document.location.host + "#" +
                                              $(this).attr('href'));

            // This is a very, very ugly hack. For some reason the pollDeepLinkedHash() function in the deeplinking-header.js file is reverting you back to the earlier page
            // Probably because of the fucking gogotabs using the __toString magic. Fucking magic functions.
            doRunAddressPoll = false;


            //Ad magic for pagination
            getAdvertisments();




        }
    });

});