var SLIDE_SPEED = 500


function jeval(str){return eval('(' +  str + ');'); }


  
//tog
function tog(clicker, toggler, callback, speed){
  if (speed == undefined)
    speed = SLIDE_SPEED;
  if (callback)
    jQuery(clicker).click(function(){jQuery(toggler).slideToggle(speed, callback); return false;});
  else
    jQuery(clicker).click(function(){jQuery(toggler).slideToggle(speed); return false;});
}
function togger(j, callback, speed){
  if (speed == undefined)
    speed = SLIDE_SPEED;
  if(callback)
  jq(j).slideToggle(speed, callback); 
  else 
  jq(j).slideToggle(speed); 
}
//tog










//message
function async_message(m, d){message(m, d);}
function messages(m, d){message(m, d);}
function message(message, duration){
    if (duration == undefined){
        duration = 3000;
    }
    if (jq.browser.msie) { jq("#message").css({position: 'absolute'}); }
    jq("#message").text(message).fadeIn(1000);
    setTimeout('jq("#message").fadeOut(2000)',duration);
    return false;
}
//message


function debug(m){if (typeof console != 'undefined'){console.log(m);}}
function puts(m){debug(m);}


function thickbox(id, title, height, width){
//    location.href = '/photos/' + id;
//    return;
    if (height == undefined){ height = 300}
    if (width == undefined){ width = 400}
    tb_show(title, '#TB_inline?height='+ height +'&amp;width='+ width +'&amp;inlineId='+ id +'', false);
    return false;
}





function truncate(str, len){
    if (len == undefined){len = 9}
    
    if (str.length <= len+3){return str;}
    
    return str.substring(0, len) + '...'
}












function tog_login_element() {
	jq('.login_element, .checkout_element').toggle();
}



//start up
jq(function(){
  	//waiter
  	jQuery("#waiter").ajaxStart(function(){jq(this).show();}).ajaxStop(function(){jq(this).hide();}).ajaxError(function(){jq(this).hide();});

	jq('.jstruncate').truncate({max_length: 50});
	
	jq('#search_q').bind('focus.search_query_field', function(){
		if(jq(this).val()=='Search for Friends'){
			jq(this).val('');
		}
	});
	
	jq('#search_q').bind('blur.search_query_field', function(){
		if(jq(this).val()==''){
			jq(this).val('Search for Friends');
		}
	});
	
});
//start up






function toggleComments(comment_id)
{
	jq('#comment_'+comment_id+'_short, #comment_'+comment_id+'_complete').toggleClass('hidden');
  
	jq('#comment_'+comment_id+'_toggle_link').html(
    	jq('#comment_'+comment_id+'_toggle_link').html() == "(more)" ? "(less)" : "(more)"
	); 
}


function toggleProfileBox(box_id, link) {
  if(jq(link).html() == 'Hide') {
    hideProfileBox(box_id, link)
  } else {
    showProfileBox(box_id, link)
  }
  return false;
}

function showProfileBox(box_id, link) {
  jq(link).html('Hide').attr('title','Hide').removeClass('hidden').addClass('visible')
  jq('#'+box_id+" ul").slideDown('dev');
}

function hideProfileBox(box_id, link) {
  jq(link).html('Show').attr('title','Show').removeClass('visible').addClass('hidden')
  jq('#'+box_id+" ul").slideUp('dev');
}

// status updates
jq(function(){
  	jq('#update-status').click(function(){
  	    jq('#name-status form').fadeIn();
  	    jq('#name-status form #text').focus()
  	    jq('#name-status form #text').html('is ')
  	    return false;
  	});
  	jq('#name-status form a').click(function(){
  	    jq('#name-status form').fadeOut();
  	    return false;
  	});
  	jq('#update-button').click(function(){
  	  if (jq('#name-status form #text').val() == 'is ' || jq('#name-status form #text').val() == 'is' || jq('#name-status form #text').val().blank()) {
  	    alert("Don't you want to say something?")
  	    return false;
  	  }
  	})
    jq('#name-status form').submit(function(){
      jq('#update-button').attr('disabled', 'disabled');
      jq('#status').html(jq('#name-status form #text').val());
      jq('#default-status .timestamp').html('updated 0 minutes ago');
      jq('#name-status form').fadeOut();
    })
});

// uploads
jq(function(){
  jq('.thickbox-form form button[type="submit"]').click(function(){
    jq('.thickbox-form').fadeOut('fast', function(){
      jq('.uploading').fadeIn('dev')});
  });
});

// toggles profile progress actiionable items
jq(function(){
  jq("#profile-progress .toggle").toggle(
    function () {
      jq('#profile-progress #accomplish-more').slideDown().removeClass('hidden').addClass('visible');
      jq(this).html('Get 100% and you can call yourself a TRUE NASCAR fan');
      return false;
    },
    function () {
      jq('#profile-progress #accomplish-more').slideUp().removeClass('visible').addClass('hidden');
      jq(this).html('What else am I missing?');
      return false;
    }
  );
});

// Toggles login tab via the login link on the community homepage
jq(function(){
  jq("#secondary-login a").toggle(
      function () { 
          jq("#login-overlay").animate({top: "0px"}, 400);
          jq(".down").addClass("up");
      }, 
      function () { 
          jq("#login-overlay").animate({top: "-323px"}, 400);
          jq(".down").removeClass("up");
      } 
	);
});
	
// removes fancy overlay HTML
jq(function(){
  jq('#fancy_wrap').remove();
  jq('#fancy_overlay').remove();
});