$(function () {
	$('input.self-labelling').focus(function () {
		var me = $(this);
		me.attr('value', '');
		me.unbind('focus');
		me.removeClass('self-labelling');
	    });

	$('textarea.self-labelling').focus(function () {
		var me = $(this);
		me.html('');
		me.unbind('focus');
		me.removeClass('self-labelling');
	    });

	$('#show-comments-link').click(function () {
		$('#show-comments').addClass('hidden');
		$('#comments-section').fadeIn(400);
		$('#comments-section').removeClass('hidden');
	    });

	$('#nav li a').each(set_current_loose);

	$('.subnav li a').each(set_current_exact);
	
	$('ul.for_lightbox').each(function() {
		$(this).find('a').lightBox();
	    });
	$('.show_details').click(function () {
		$(this).next('ul').find('a').eq(0).click();
		return false;
	    });
	$('a.for_lightbox').each(function () {
		$(this).lightBox();
        });
    
    $('#artist-switcher').change(function () {
        document.location = "/artists/" + $(this).attr('value') + '/';
        });
    $('#artist-switcher-form').css('display', 'block');
    $('#view-artist-list').hide();
    
    // $('a.fragment').click(ajax_lightbox_call);
    
});


function set_current_exact() {
    var me = $(this);
    if (me.attr('href') == document.location.pathname) {
	me.addClass('current');
    }
}


function set_current_loose() {
    var me = $(this);
    if (me.attr('href') == '/') {
	if (document.location.pathname == '/') {
	    me.addClass('current');
	    return true;
	} else {
	    return true;
	}
    }
    if (document.location.pathname.match(me.attr('href'))) {
	me.addClass('current');
	return true;
    }
    return true;
}

function ajax_lightbox_call() {
    var top = $(this).offset().top;
    jQuery.get($(this).attr('href'), function (data, textStatus) {
        $('body').append(data);        
        $('#vote-form-cancel-link').click(function () {
            $('.vote-form-bit').remove();
            return false;
        });
        $('#vote-form').css({'top': top});
    });
    return false;
}
