//Default value plugin
jQuery.fn.DefaultValue = function(text){
    return this.each(function(){
		//Make sure we're dealing with text-based form fields
		if(this.type != 'text' && this.type != 'password' && this.type != 'textarea')
			return;
		
		//Store field reference
		var fld_current=this;
		
		//Set value initially if none are specified
        if(this.value=='') {
			this.value=text;
		} else {
			//Other value exists - ignore
			return;
		}
		
		//Remove values on focus
		$(this).focus(function() {
			if(this.value==text || this.value=='')
				this.value='';
		});
		
		//Place values back on blur
		$(this).blur(function() {
			if(this.value==text || this.value=='')
				this.value=text;
		});
		
		//Capture parent form submission
		//Remove field values that are still default
		$(this).parents("form").each(function() {
			//Bind parent form submit
			$(this).submit(function() {
				if(fld_current.value==text) {
					fld_current.value='';
				}
			});
		});
    });
};

$(document).ready(function() {
	$('.voting') 
    .livequery(function() { 
		$('.voting').hide();
    }); 

	// show and hide voting module
	$('#content li:not(.pun-info)')
    .livequery(function(){ 
    	var voter = $(this).children(".stats").children().children(".voting");
		$(this).hover(
		  function () {
			$(voter).show("fast");
			//$(this).children('p').animate({ color: "#B9CE38" }, "fast");
			$(this).children('p').css("color", "#676767");
		  },
		  function () {
			$(voter).hide("fast");
			//$(this).children('p').animate({ color: "#949494" }, "fast");
			$(this).children('p').css("color", "#949494");
		  }
		);
    }); 
    
	//submit form jquery
	$('#submitPun').hide();
	
	$('.toggleSubmit').click(function() {
		$('#submitPun').slideToggle("fast");
		//$('#punField').focus();
		return false;
	});
	
	$('#close').click(function() {
		$('#submitPun').slideToggle("fast");
		return false;
	});
	
	
	//hide long posts
	  var slicePoint = 300;
  	  var widow = 4;
  	  var descriptor = "more";
  $('#content li p').each(function() {
    var allText = $(this).html();
    var startText = allText.slice(0,slicePoint).replace(/\w+$/,'');
    var endText = allText.slice(startText.length);
    if ( endText.replace(/\s+$/,'').split(' ').length> widow ) {
      $(this).html([
        startText,
        '<span class="details">',
          endText,
        '</span> ',
        '<a href="#" class="read-more"> show '+ descriptor + '&hellip;</a>'
        ].join('')
      );
    }
  });
 
  // *** hide details until read-more link is clicked;
  // then hide link and show details.
  $('span.details').hide();
  $('a.read-more').click(function() {
	  if (descriptor == "more") {
			descriptor = "less";
		} else {
			descriptor = "more";
		}
    $(this).html('<a href="#" class="read-more"> show '+ descriptor + '&hellip;</a>')
    .prev('span.details').toggle();
    return false;
  });
	
	//end hiding posts
	
});