function limitChars(textid, minimumCharacters)
{
	var text = $('#'+textid).val(); 
	var textlength = text.length;
	
	if(textlength < minimumCharacters) 
	{
 		$('#' + infodiv).html('Your domain must be larger than '+minimumCharacters+' characters').css({'color' : 'red'});;
		$('#'+textid).val(text.substr(0,minimumCharacters));
		return false;
 	}
	else
	{	
	$('#' + infodiv).html((minimumCharacters - textlength)).css({'color' : 'gray'});;
	}
}

//function to flash red text when domain not available
jQuery.fn.flash = function( color, duration )
{
 
    var current = this.css( 'color' );
 
    this.animate( { color: 'rgb(' + color + ')' }, duration / 3 );
    this.animate( { color: current }, duration / .5 );
}

$(document).ready(function() {



//reset the form on refresh
$("form")[ 0 ].reset();

// input focus for domain search
  $("#search form input#name").focus(function() {
     if ( $(this).val() == "Your Name"){
          $(this).attr("value","");
          $(this).css("color","black");
          if ($.browser.msie && $.browser.version.substring(0,1) === '6') {}
          else {
            $('#search').removeClass('up').addClass('dn');
          };
     } // end if
      
  });
  

  $("#search form input#name").blur(function() {
     if ( $(this).val() == ""){
          $(this).attr("value","Your Name");
          $(this).css("color","#a7a5a6");
          $('#search').removeClass('dn').addClass('up');
          $("#search-text").html("Claim your FREE domain to get started:");
     } // end if
      
  });
  

// LOGIN WIDGET  
  
  $(".login .left form .email").focus(function() {
          $(this).attr("value","");
          $(this).css("color","black");
  });
  
  $(".login .left form .pw").focus(function() {
          $(this).attr("value","");
          $(this).css("color","black");
  });  
  
  $(".login .left form .email").blur(function() {
     if ( $(this).val() == ""){
          $(this).attr("value","Email Address");
          $(this).css("color","#a7a5a6");
     } // end if
 
 });
     
     $(".login .left form .pw").blur(function() {
        if ( $(this).val() == ""){
             $(this).attr("value","Password");
             $(this).css("color","#a7a5a6");
        } // end if
      
  });
  
  
  // input feedback
		$('#search form input#name').keyup(function(){
      
      //auto escape spaces
      var txt = $(this);
      txt.val(txt.val().replace(/\s/g, ''));

      var charLength; 
      charLength = $("#search form input#name").val().length; 
      
      if (charLength < 4) 
      {
          $("#search-text").html("Must be 4 or more characters:");
          $("#search .submit").css("opacity",".3");
     	}
     	else
     	{
     	  $("#search-text").html("Click the GO button to check availability");
     	  $("#search .submit").css("opacity","1");
     	}
    	
		});



//ajax form domain check
$("#checkDomain").submit(function(){
  pageTracker._trackPageview("/checked_domain_availability");
  $("#search-text").html("Checking availability...");
  $("form .submit").hide();
  $("form .spinner").show();

  $.post("/signup/check_domain2", $(this).serialize(), function(data){
    if (data == 'not_available') {
      $("#search-text").html("Not Available. Try another domain.").flash( '164,0,0', 1000 );
      $("form #name").focus();
      $("form .submit").show();
      $("form .spinner").hide();
      }
    else if (data == 'service_not_available') {
      $("#search-text").html("Service not available. Try again soon!").flash( '164,0,0', 1000 );
      $("form #name").focus();
      $("form .submit").show();
      $("form .spinner").hide();
      }
    else
    $("#search").html(data);
  });

  return false;
}); //end ajax form




// TAB ROLLOVERS

// swap from active to inactive on rollover
$("ul.rollover-tabs li").mouseover(function(){
    $("ul.rollover-tabs li").removeClass("active");
    $("ul.rollover-tabs li").find("span").remove();    
    $(".example").show();
    $(".left").show();      
    $(this).addClass("active");
    $(this).prepend("<span></span>"); 
    
    //hide right column when you rollover reviews tab
    if ($(this).hasClass("reviews-tab")) {
      $(".example").hide();
      $(".left").hide();
      $("#reviews").show();
    }
    
    else {
      
    $(".content-block .section").css("display","none");   
    //get the value of the rel attribute
    var getvalue = $(this).find('a').attr('rel');
    
    // use that value to display the proper content
    $(".content-block #" + getvalue).css("display","block");

    } //end if
    
});


// press article swapper

$('.press .rightarrow').click(function(){
  if ($('.carousel div:last').hasClass('current')){
    $('.carousel div').css('display','none').removeClass('current');
    $('.carousel div:first').css('display', 'block').addClass('current');
  }
  else {
    $('.carousel').find('div.current').css('display','none').removeClass('current').next().css('display', 'block').addClass('current');
  }
});


$('.press .leftarrow').click(function(){
  if ($('.carousel div:first').hasClass('current')){
    $('.carousel div').css('display','none').removeClass('current');
    $('.carousel div:last').css('display', 'block').addClass('current');
  }
  else {
    $('.carousel').find('div.current').css('display','none').removeClass('current').prev().css('display', 'block').addClass('current');
  }
});


// SAMPLE SITE
// figure out what to do when you click the big orange button
$('.sample-content .right .button').click(function(){
  if ($('.sample-content .left  .exampleimage:last').hasClass('current')){
    $('.sample-content .left  .exampleimage').removeClass('current');
    $('.sample-content .left  .exampleimage:first').addClass('current');
    $('.sample-content .right  .description .example-section').removeClass('current');
    $('.sample-content .right  .description .example-section:first').addClass('current');
    $('.sample-content .right  .button').removeClass('current');
    $('.sample-content .right  .button:first').addClass('current');
  }
  else {
    $('.sample-content .left').find('img.current').removeClass('current').next().addClass('current');
    $('.sample-content .right .description').find('div.current').removeClass('current').next().addClass('current');
    $(this).removeClass('current').next().addClass('current');
  }
});


// TEAM BIOS
$("a.tooltiper").tooltip({position: 'top center', offset:[-50, 10]});

$('.error a').click(function(){
  $('.error').hide();
});

}); //end doc ready  

