if (window.location.toString().match(/localhost/gim)) {
	var disqus_developer = 1; 
}

if(window.location.toString().match(/fsck/gim)) {
    var disqus_developer = 1;
}

if(window.location.toString().match(/8888/gim)) {
    var disqus_developer = 1;
}

var $ = jQuery;


$(document).ready(function() {
    // Stuff to do as soon as the DOM is ready;
    
	if(jQuery.browser.msie && parseInt(jQuery.browser.version) == 6 && !window["XMLHttpRequest"]) {
	    alert('ie6 png fix');
		$(document).pngFix();
	}

    
    
    $('li.share-this').each(function(i,j){
        var self = $(j),
            n = i;
        self.hover( function(e) { show(n,e); } ,
                    function(e) { outCountdown(n,e); } );
        self.click(function(e){
            e.preventDefault();
            hide();
        })
    });
    
    
    $('#blog-posts').after('<ul id="recent-popular"><li class="active"><a id = "pop" class="popular" href="#">Popular Posts</a></li><li><a id = "rec" class="recent" href="#">Recent Posts</a></li></ul>');
    
    $('ul#recent-popular li a').click(function(e){
        e.preventDefault();
        $(this).parent().addClass('active');
        $(this).parent().siblings('li').removeClass('active');

       $('ul.popular, ul.recent').hide(); 
       
       $('ul.'+this.className).show()
    });
    
    var searchVal = $('form#cse-search-box div input[type=text]');
    
    searchVal[0].defaultValue = searchVal.val();
    searchVal.focus(function(){
        if (this.defaultValue == $(this).val()) 
            $(this).val('');
    }).blur(function(){
        if ($(this).val().match(/^\s*$/gim))
            $(this).val(this.defaultValue)
    });
    
    
    var timer;

    var hide = function(n,e){
        $('li.share-services').fadeOut();
        
        
	}
	var show = function(n,e){
		stopCountdown()
        $('li.share-services:eq('+n+') ul').css("margin-bottom","-20px");
        $('li.share-services:eq('+n+')').fadeIn();
	}
	// On mouseout, wait a second before hiding it, to be spaz-forgiving
	var outCountdown = function(n,e){
		timer = setTimeout(function(){
		    hide(n,e);
		}, 10000)
		
	}
	var stopCountdown = function(){
		clearTimeout(timer)
	}
	
    
        $('a.dsq-comment-count').each(function(){
        var item = $(this);
        item.text(item.text().replace(/\s?comment\(?s?\)?\s*(and \d+ Reactions?)?/gim, '')).addClass('speech-bubble');
    })
    
    
    if(table = $('#sidebar #events .gigpress-table'), table.size()) {
        var events = $('#sidebar #events .gigpress-table .vevent');
        events.each(function(i,tem){
           var kore = $(tem),
               div = $('<div class="event-unit"></div>').insertBefore(table),
               ul = $('<ul></ul>').appendTo(div),
               venue = kore.find('.gigpress-venue').text(),
               city = kore.find('.gigpress-city').text(),
               date = kore.find('.gigpress-date').text(),
               url = kore.find('.gigpress-info-item:last a').attr('href');
           ul.append('<li>'+venue+' | '+city+' | '+date+'</li>');
           ul.append('<li><a href="'+url+'" class="event-details">Event Details</a>');
        });
        table.remove();
    }
    
    if($('#content .gigpress-table').size()) {
        table = $('#content .gigpress-table:first');
        events = table.find('.vevent');
        con = $('<div class="event_archive"></div>').insertBefore(table);
        events.each(function(i,tem){
           var kore = $(tem),

               div = $('<div class="event-unit"></div>').appendTo(con),
               ul = $('<ul></ul>').appendTo(div),
               venue = kore.find('.gigpress-venue').text(),
               city = kore.find('.gigpress-city').text(),
               date = kore.find('.gigpress-date').text(),
               url = kore.find('.gigpress-info-item:last a').attr('href');
           ul.append('<li><ul><li>'+date+'</li></ul></li>');
           ul.append('<li><ul><li>'+city+'</li><li>'+venue+'</li></ul></li>');
           ul.append('<li><ul><li><a href="'+url+'" class="event-details">Event Details</a></li></ul></li>');
        });
        table.remove();
    }
    
  
});

