


function replaceAllInstances( str, searchTerm, replaceWith, ignoreCase ) {
    var regex = "/"+searchTerm+"/g";
    if( ignoreCase ) regex += "i";
    return str.replace( eval(regex), replaceWith );
}

function callserver() {
 var remoteURL = '/ajax/keepalive';
 $.get(remoteURL, function(data) { setTimeout("callserver()",10000); });
}
    
$(document).ready(function() {
 
 	setTimeout("callserver()",10000); 
    
    $.fn.jump = function() {
      $('#verticalsidebar').removeClass('greetmode').addClass('normal');
    };
    
    /*
    $.fn.delay = function(time, callback){
     jQuery.fx.step.delay = function(){};
     return this.animate({delay:1}, time, callback);
    }

    $('#greetbox').delay(8000, function() {
     $.cookie("hidegreet", "1", { expires: 7 });
     $(this).fadeOut().jump();
    });
    */
    
    $('.closegreet').click(function() {
        $.cookie("hidegreet", "1", { expires: 7 });
        $('#greetbox').hide().jump();
        return false;
    });
    


   
    $('a.toc').attr('href','javascript:void(0);');
    $('a.toc').click(function () {
        $(window)._scrollable();        
        $(window).scrollTo( '#_'+this.id, 1000, {easing:'easeInOutCirc'});
    });


    $("a.discussionlinks").each(function(){
    
         if($(this).attr("title").match('sociologically.net')===null )	{
                        $(this).addClass('external');
			$(this).after(' <img alt="Link outside of Sociologically.net" src="/graphics/link-outside.gif" />');
			$(this).fancybox({'hideOnContentClick': false});                        
         } else {
			$(this).after(' <img alt="Link inside of Sociologically.net" src="/graphics/link-inside.gif" />');
                        $(this).attr("href",$(this).attr("title"));
			
         }
    });
    
	 $('a.discussionlinks').qtip({
	  content: {
	     text: false 
	  },
	  style: {
	     name:'dark', border: {width:2, radius:6}, tip:true
	  },
	  position: {
corner: {
         target: 'topMiddle',
         tooltip: 'bottomLeft'
      }
	   
	  }
	 });	     
    
    $('a.closefancy').live('click', function (e) {
        $(this).attr('href','javascript:void(0);');
        parent.$.fn.fancybox.close();
        return false;
    });
    
	$(".sharebox img").mouseover(function(){
		$(".sharemessage").text(this.title);
	}).mouseout(function(){
		$(".sharemessage").text("");
	});
        
    $('a.sociopedia').cluetip({sticky: true, closePosition: 'bottom', activation: 'click', closeText: 'Close this box', showtitle: false, dropShadow: false, fx:{open: 'fadeIn'}});
 	
    $('.obfuscated').each(deObfuscateEmail);
		function deObfuscateEmail(i) {
		var content = $(this).text().replace(' AT ', '@').replace(' DOT ', '.');
		$(this).replaceWith($('<a href="mailto:'+content+'" title="Click to send an email to '+content+'">'+content+'</a>'));
	}    
    
    

    

    $("a#feedback").attr('href','/feedback/pop');
    $('a#feedback').fancybox({
            'hideOnContentClick': true
    });	
    
    $('#byline').hide();
    $('#byline').fadeIn('slow');

    $('img.userimg').qtip({
	  content: {
	     text:false
	  },
	  style: {
	     name:'dark', border: {width:2, radius:6}, tip:true, width: { min: 180 }
	  },
	  position: {
corner: {
         target: 'bottomMiddle',
         tooltip: 'topLeft'
      }
	   
	  }
	 });	     
    
    

 $(function(){
	$('input').keydown(function(e){
	 if (e.keyCode == 13) {
		$(this).parents('form').submit();
		return false;
	 }
	});
 });

 $("#loginform_sidebar").validate({
	errorClass: "frontinputerror"
 });

 $("#searchform_sidebar").validate({
	errorClass: "frontinputerror"
 });


    



});