jQuery.fn.preventDoubleSubmit = function() {
  jQuery(this).submit(function() {
    if (this.beenSubmitted)
      return false;
    else
      this.beenSubmitted = true;
  });
};

jQuery.fn.fadeToggle = function(speed, easing, callback) {
   return this.animate({opacity: 'toggle'}, speed, easing, callback);
}; 

function togglePopup(selector, preventMove){
	// hide all other popups if open
	jQuery(".popup:not("+selector+")").hide();
	// show the one we want
	jQuery(selector).fadeToggle();
	// move popup to centerish of screen
	if(!preventMove) jQuery(selector).css("top", jQuery(window).scrollTop() + 200);
}

$j(document).ready(function(){
	// nav
	$j(".nav li").each(function(){
		var name = $j(this).attr("id");
		var destname = name.substr(name.lastIndexOf('_')+1);
		if(destname == segment){
			$j("a", this).addClass("selected");
		}
	});
	
	// lightbox
	if(jQuery(this).lightBox){
		jQuery("a[rel*='lightbox']").lightBox({
			containerResizeSpeed: 350
		});
	}
	
	// grunge buttons
	jQuery(".grunge a").hover(
		function(){
			var src =  jQuery("img", this).attr("src");
			jQuery("img", this).attr("src", src.replace("_off", "_on"));
		},
		function(){
			var src =  jQuery("img", this).attr("src");
			jQuery("img", this).attr("src", src.replace("_on", "_off"));
		}
	);
		
});