jQuery(document).ready(function(){
	
	//image hover effect
	jQuery(".imageborder").hover(
		function(){
			jQuery("img", this).animate({
				opacity: 0.80
			}, 250);
		},
		function(){
			jQuery("img", this).animate({
				opacity: 1	
			}, 250);
		}
	);
	
	//stickysidebar
	var elementheight = 281;
	var current = "top";
	if(!jQuery.browser.msie){		
		jQuery(window).bind('scrollstop', function(e){
			if(jQuery(document).scrollTop() >= (parseInt(jQuery("#blogwrapper").height()) - parseInt(jQuery("#blogsidebar-absolute").height()))+elementheight){
				if(current != "bottom"){
					jQuery("#blogsidebar-absolute").stop(true, false).animate({
						opacity: 0.25
					}, 250,
					function(){
						jQuery(this).animate({
							top: (parseInt(jQuery("#blogwrapper").outerHeight()) - parseInt(jQuery(this).height())) + "px",
							opacity: 1
						}, 500)
					});
					current = "bottom";
				}
			}else if(jQuery(document).scrollTop() >= elementheight){
				jQuery("#blogsidebar-absolute").stop(true, false).animate({
					opacity: 0.25
				}, 250,
				function(){
					jQuery(this).animate({
						top: jQuery(document).scrollTop() - elementheight + "px",
						opacity: 1
					}, 500)
				});
				current = "middle";
			}else if(current != "top"){
				jQuery("#blogsidebar-absolute").stop(true, false).animate({
					opacity: 0.25
				}, 250,
				function(){
					jQuery(this).animate({
						top: "0px",
						opacity: 1
					}, 500)
				});
				current = "top";
			}
		});
	}else{
		jQuery(window).bind('scrollstop', function(e){
			if(jQuery(document).scrollTop() >= (parseInt(jQuery("#blogwrapper").height()) - parseInt(jQuery("#blogsidebar-absolute").height()))+elementheight){
				if(current != "bottom"){
					jQuery("#blogsidebar-absolute").stop(true, false).animate({
						top: (parseInt(jQuery("#blogwrapper").outerHeight()) - parseInt(jQuery(this).height())) + "px"
					}, 500);
					current = "bottom";
				}
			}else if(jQuery(document).scrollTop() >= elementheight){
				jQuery("#blogsidebar-absolute").stop(true, false).animate({
					top: jQuery(document).scrollTop() - elementheight + "px"
				}, 500);
				current = "middle";
			}else if(current != "top"){
				jQuery("#blogsidebar-absolute").stop(true, false).animate({
					top: "0px"
				}, 500);
				current = "top";
			}
		});
	}
});
