/**
* Delay plugin inspired by learningjquery.com/2007/01/effect-delay-trick
* @author : Jp Siffert
* @param : delay interval, if not given default to 1000ms
* @return : jquery chain object
**/

$.fn.delay = function(delay){
if(typeof delay==="undefined") delay = 1000;
return this.animate({"void":0}, delay);
}

function show_overlay() {
	hide_overlay();
	$('body').prepend('<div id="overlay">&nbsp;</div>');
	setup_overlay_height();
}
function hide_overlay() {$('#overlay').remove();}
function setup_overlay_height() {
	body_height = $(document).height();
	$('#overlay').css('height', body_height);
}
function center_popup(popup) {
	body_width = parseInt($('body').width());
	popup_width = parseInt($(popup).css('width'));
	left_position = parseInt((body_width/2) - (popup_width/2));
	$(popup).css('left', left_position);
}

$(document).ready( function(){
	// when you trigger the login box to appear, do this
	$('.login-link').click( function() {
		$('.login-top').load("http://www.passthequilt.org/includes/login_form/");
		show_overlay();
		$('#login-wrap').show();
		center_popup('#login-wrap');
		return false;
	});
	// this has to be a 'live' event because the cancel link doesn't exist when the page loads.
	$('.login-cancel').live("click", function() {
		$('#login-wrap').hide();
		hide_overlay();
		return false;
	});

	$('.flag-link').click( function() {
		// Look for the 'a' in this span, then get its href, then load that into 'this' (i.e. this span)
		$(this).next().load( $(this).attr('href') );
		$('.flag-link').hide();
		return false;
	});
	$('.flag-cancel').live("click", function() {
		// destroy the HTML of .flag-span
		$('.flag-span').html('');
		// show the flag link again
		$('.flag-link').show();
		return false;
	});

	$('.like-link').click( function() {
		// Load the result template into the next span
		like_change = 1;
		$('.like_results').html('');
		$('.like_results').load( $(this).attr('href') );
		$(this).hide();
		$('.like-link-delete').show();
		return false;
	});
	$('.like-link-delete').click( function() {
		// Load the result template into the next span
		like_change = -1;
		$('.like_results').html('');
		$('.like_results').load( $(this).attr('href') );
		$(this).hide();
		$('.like-link').show();
		return false;
	});



});

// this script allows us to blank each text field on the page only once.
var blanked = new Array();
function blank(textfield) {
  if (blanked[textfield.name] != true)
  {
    blanked[textfield.name] = true;
    textfield.value = "";
  }
}



