$( function() {
    
	/* Popup
	-----------------------------------------------------------*/
	$('.popup').click(function() 
	{
		var page = $(this).attr('href');
		window.open(page);
		return false;
	});
	
    /* Replace submit buttons
	-----------------------------------------------------------*/
    // Replace all pretty-submit buttons with a link
    $('input.image-submit').each( function() {
        var new_tag = '<a id="' + $(this).attr('id') + '" href="submit" class="' + $(this).attr('class') + '">' + this.value + '</a>';
        $(this).after(new_tag).remove();
    });
    // Now attach the submit behavior to these links
    $('a.image-submit').click( function() {
        $(this).parents('form').submit();
        return false;
    });
    
    /* Add 'stripe' class to even rows of any table with class 'striped'
    -----------------------------------------------------------*/
    $('table.striped tr:nth-child(even)').addClass('stripe');
    
    
    /* Add 'hot-row' class to :hover'ed rows of any table with class 'hot-rows'
    -----------------------------------------------------------*/
    $('table.hot-rows tr:not(#no-results-row):has(td)').mouseover(function () { $(this).addClass('hot-row'); }).
    mouseout(function () { $(this).removeClass('hot-row'); });
    
    
    /* Make hot-rows clickable, redirect to the href of the link in first cell in this row
    -----------------------------------------------------------*/
    $('table.hot-rows tr:not(#no-results-row):has(td)').click( function() {
        window.location = $(this).find(':first-child a').attr('href');
    });
    
    
    /* Auto focus
    -----------------------------------------------------------*/
    $( function() {
        $('form .focus').focus();
    });
});