jQuery.fn.labelOver = function(v) {
	return this.each(function(){
		var label = jQuery(this);
		var f = label.attr('for');
		var input = jQuery('#' + f);
				this.hide = function() {
					if(v=='v1') {
						label.animate({"left": "-600px"}, 250);
					};
					if(v=='v2') {
						label.animate({"opacity": "0"}, {queue:false, duration:250}).animate({"left": "+=100px"}, {queue:false, duration:250});
					};
				};
				this.show = function() {
					if (input.val() == '' && v=='v1' && input.is("input:not('#commenter_comment')")) {
						label.animate({"left": "-301px"}, 250);
					};
					if (input.val() == '' && v=='v1' && input.is("#commenter_comment")) {
						label.animate({"left": "-401px"}, 250);
					};
					if (input.val() == '' && v=='v2') {
						label.animate({"opacity": "100"}, {queue:false, duration:250}).animate({"left": "0px"}, {queue:false, duration:250});
					};
				};
			input.focus(this.hide);
			input.blur(this.show);
		   label.click,label.mousedown(function(){ input.focus() });
			if (input.val() != '') {input.focus()}; 
	});
};

 
$(document).ready(function(){
									
	//show the poll button hidden with .hasJS vanilla JS and css
	$('#pollForm .pollButton').css({visibility:"visible"});
									
	//IE speedier hover changes:
	try {document.execCommand('BackgroundImageCache', false, true);} catch(e) {}
	
	//overlabels
	$('#comments label').labelOver('v1');
	$('#topMostDiv form label').labelOver('v2');
	
	//fixing pseudo elements for IE:
	$('input[type=text]').focus(function() {$(this).addClass("focus");});
	$('input').blur(function() {$(this).removeClass("focus");});
	
	//fixing img padding for IE quirks mode:
	$('#mainContent img.RFloat').wrap("<span class='ieImgHackR'></span>");
	$('#mainContent img.LFloat').wrap("<span class='ieImgHackL'></span>");

	//sidenav animation
	$("#sideNav li:not('.youAreHere') a").hover(function(){
		$(this).stop().animate({
			left:"10px"
			},100);
	}, function(){
		$(this).stop().animate({
			left:"20px"					  
			},200);
	});
	
	//scrolly anchor links:
  $('a[href*=#]').click(function() {
	if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
	&& location.hostname == this.hostname) {
	  var $target = $(this.hash);
	  $target = $target.length && $target
	  || $('[name=' + this.hash.slice(1) +']');
	  if ($target.length) {
		var targetOffset = $target.offset().top;
		$('html,body')
		.animate({scrollTop: targetOffset}, 1000, 'easeInOutExpo');
	   return false;
	  }
	}
  });

	//for polls that have already been completed (based on cookie value) (animateResults is contained in-page):
	animateResults();
	
});
