$(document).ready(function() {
	var last = 12;
	var num = 5;
	$(document).pngFix();
	$("a.fancybox").fancybox({
		'zoomOpacity': true,
		'overlayShow': false,
		'titlePosition': 'over',
		'transitionIn': 'elastic',
		'transitionOut': 'elastic',
		'easingIn': 'easeOutBack',
		'easingOut': 'easeInBack'
	});
	$("a#gamercard").fancybox({
		'overlayShow': false,
		'titlePosition': 'inside'
	});
	$("a#commentwall").fancybox({
		'zoomOpacity': true,
		'overlayShow': false,
		'frameWidth': 480,
		'frameHeight': 320,
		'zoomSpeedIn': 500,
		'zoomSpeedOut': 50,
		'callbackOnShow': function() {
			$("span.commentsCount").removeClass('alert');
		}
	});
	$("a#more").click(function() {
		$.ajax({
			url: 'includes/more.php?last=' + last + '&num=' + num,
			type: 'GET',
			dataType: 'html',
			timeout: 5000,
			error: function(){
				alert('Error requesting more. Try again.');
			},
			success: function(html){
				last = last + num;
				$("div#activityList").append(html);
				$.scrollTo('div#footer', {speed:1000});
			}
		});
		return false;
	});
	$("a.activityItem").live("click", function() {
		var anchorId = $(this).attr("id");
		var anchorIdData = anchorId.split("-");
		var anchorHref = $(this).attr("href");
		$.ajax({
			url: 'includes/click.php',
			type: 'POST',
			dataType: 'html',
			data: 'id=' + anchorIdData[1],
			timeout: 1000,
			success: function(html){
				window.location = anchorHref;
			}
		});
		return false;
	});
	$("a#backToTop").click(function() {
		$.scrollTo({top: 0, left: 0}, {speed:500});
		return false;
	});
});

// standart string replace functionality
function str_replace(haystack, needle, replacement) {
	var temp = haystack.split(needle);
	return temp.join(replacement);
}