Cufon.replace('h1, h2');

var qtip_style = {
	position: {
		corner: {
			target: 'bottomMiddle',
			tooltip: 'topLeft'
		}
	},
	style: { 
		width: 220,
		padding: 5,
		background: '#fff',
		color: 'black',
		textAlign: 'left',
		border: {
			width: 2,
			radius: 3,
			color: '#fff'
		},
		tip: 'topLeft',
		name: 'dark' // Inherit the rest of the attributes from the preset dark style
	}
};


$(document).ready(function(){

	$('#login').magicPanel({ link: '.login_link' });
	$('#flash_panel').magicPanel();
	
	$('#search_panel').magicPanel({
		link: '.search_link',
		after_show: function() { $(this).find("input[type=text]").focus(); },
		after_close: function() { $(this).find("input[type=text]").blur(); }
	});
	$(document).bind('keydown', function(e) {
		// if ($(e.target).attr('type') !== 'undefined') return true; // its an input
		// Base.log(e.target);
		if ( $(e.target)[0] != $('html')[0] ) return true;
		if (e.keyCode == 191) { // -> /
			$('.search_link:eq(0)').click();
			return false; // firefox shows search on /, but then we focus on the search field
		}
	});
	

	$('.rater').rater({
		url: function(rating_number, beer_id) {
			return "/beers/" + beer_id + "/rate/" + rating_number + ".js";
		}
	});

	for(var key in Base.tips) {
		$("#" + key).qtip($.extend({}, qtip_style, { content: Base.tips[key] }));
	}

	$('#search_panel input[name=q]').sexySearch({
		onselect: function(e, result) {
			document.location = result.path;
		}
	});
});