function showHideScrollerArrows(imminentOffset){
	var currentLeftMargin = parseInt(jQuery('#categoriesScroller').css('margin-left'));
	var maximumLeftMargin = Math.max(0, parseInt(jQuery('#categoriesScroller').css('width')) - parseInt(jQuery('#scroller').css('width')));
	var offset = typeof(imminentOffset) != 'undefined' ? imminentOffset : 0;
	if (currentLeftMargin + offset == 0){
		jQuery("#left").stop().animate({opacity:"0.0"}, 250);
	} else {
		jQuery("#left").stop().animate({opacity:"1"}, 250);
	}
	if (currentLeftMargin + offset == -maximumLeftMargin){
		jQuery("#right").stop().animate({opacity:"0.0"}, 250);
	} else {
		jQuery("#right").stop().animate({opacity:"1"}, 250);
	}
}

jQuery(document).ready(function(){
	jQuery('a[rel*=external]').attr('target', '_blank');
	jQuery('hr').wrap('<div class="hr"></div>');
	jQuery('#mainWrapper a, #mainWrapper img').removeAttr('title');

	// Mid Menu Scroller starts
	var easingDistance = 50;
	var easingPeriod = 800;
	var slidingDistance = 5;
	var slidingPeriod = 20;
	showHideScrollerArrows();

	jQuery("#rightButton, #leftButton").css({opacity:"0.3"});
	var Scrolling = "none";
	jQuery("#right").hover(function(){
		Scrolling = "left";
		jQuery('#rightButton').stop().animate({opacity:"0.8"}, 250);
		var currentLeftMargin = parseInt(jQuery('#categoriesScroller').css('margin-left'));
		var maximumLeftMargin = Math.max(0, parseInt(jQuery('#categoriesScroller').css('width')) - parseInt(jQuery('#scroller').css('width')));
		var actualOffset = Math.min(easingDistance, maximumLeftMargin+currentLeftMargin);
		jQuery('#categoriesScroller').stop().animate({marginLeft:"-="+actualOffset+"px"}, easingPeriod, "easeInSine", scrollingLeft);
		showHideScrollerArrows(-actualOffset);
	}, function() {
		Scrolling = "none";
		jQuery('#rightButton').stop().animate({opacity:"0.3"}, 1000);
		var currentLeftMargin = parseInt(jQuery('#categoriesScroller').css('margin-left'));
		var maximumLeftMargin = Math.max(0, parseInt(jQuery('#categoriesScroller').css('width')) - parseInt(jQuery('#scroller').css('width')));
		var actualOffset = Math.min(easingDistance, maximumLeftMargin+currentLeftMargin);
		jQuery('#categoriesScroller').stop().animate({marginLeft:"-="+actualOffset+"px"}, easingPeriod, "easeOutSine");
		showHideScrollerArrows(-actualOffset);
	});
	function scrollingLeft(){
		if (Scrolling == "left"){
			var currentLeftMargin = parseInt(jQuery('#categoriesScroller').css('margin-left'));
			var maximumLeftMargin = Math.max(0, parseInt(jQuery('#categoriesScroller').css('width')) - parseInt(jQuery('#scroller').css('width')));
			var actualOffset = Math.min(slidingDistance, maximumLeftMargin+currentLeftMargin);
			jQuery('#categoriesScroller').animate({marginLeft:"-="+actualOffset+"px"}, slidingPeriod, "linear", scrollingLeft);
		};
		showHideScrollerArrows();
	};

	jQuery("#left").hover(function(){
		Scrolling = "right";
		jQuery('#leftButton').stop().animate({opacity:"0.8"}, 250);
		var currentLeftMargin = parseInt(jQuery('#categoriesScroller').css('margin-left'));
		var actualOffset = Math.min(easingDistance, -currentLeftMargin);
		jQuery('#categoriesScroller').stop().animate({marginLeft:"+="+actualOffset+"px"}, easingPeriod, "easeInSine", scrollingRight);
		showHideScrollerArrows(actualOffset);
	}, function() {
		Scrolling = "none";
		jQuery('#leftButton').stop().animate({opacity:"0.3"}, 1000);
		var currentLeftMargin = parseInt(jQuery('#categoriesScroller').css('margin-left'));
		var actualOffset = Math.min(easingDistance, -currentLeftMargin);
		jQuery('#categoriesScroller').stop().animate({marginLeft:"+="+actualOffset+"px"}, easingPeriod, "easeOutSine", scrollingRight);
		showHideScrollerArrows(actualOffset);
	});
	function scrollingRight(){
		if (Scrolling == "right"){
			var currentLeftMargin = parseInt(jQuery('#categoriesScroller').css('margin-left'));
			var actualOffset = Math.min(slidingDistance, -currentLeftMargin);
			jQuery('#categoriesScroller').animate({marginLeft:"+="+actualOffset+"px"}, slidingPeriod, "linear", scrollingRight);
		};
		showHideScrollerArrows();
	};
	// Mid Menu Scroller Ends
	jQuery("#midMenu li a").css({opacity:"0.6"});
	jQuery("#midMenu li a").hover(function(){
		jQuery(this).stop().animate({opacity:"1"}, 250);
	}, function() {
		jQuery(this).stop().animate({opacity:"0.6"}, 1000);
	});
	jQuery(".postContent a:has(.size-full)").css({opacity:"0.6"});
	jQuery(".postContent a:has(.size-full)").hover(function(){
		jQuery(this).stop().animate({opacity:"1"}, 400);
	}, function() {
		jQuery(this).stop().animate({opacity:"0.6"}, 1600);
	});

	// Hide Comments text when not looking	
	jQuery(".postMetaData span.comments").css({opacity: "0"});
	jQuery(".posts").hover(function() {
		jQuery(this).find("span.comments").stop().animate({opacity: "1"}, 500);
	}, function () {
		jQuery(this).find("span.comments").stop().animate({opacity: "0"}, 1000);
	});
});