var App = {
	initLinks: function(el, font) {
		var me = App,
			// Get all links
			$elements = $(el),
			last;

		// Replace all links to cufon
		me.replaceTo($elements, font);
	
		// Bind mouseover & moseout events
		$elements
			.mouseover(function(){
			    if (this.className.indexOf('hover') == -1) {
					this.className += ' hover';
					last = this;
					me.replaceTo(this, font);
				}
				
			})
			.mouseout(function(){
				if (last) {
					last.className = last.className.substr(0, last.className.length - 6);
					me.replaceTo(this, font);
				}
			});
	},
	initBreuerText: function() {
		var me = App,
			$elements = $('.breuer-text, .article .body h2');
			
		me.replaceToBreuer($elements);
	},
	replaceTo: function(el, font) {
		if (font) {
			Cufon.replace(el, { fontFamily: font });
		}
	}
}; // eo App

$(function(){
	App.initLinks('#nav > ul > li > a, #langs a', 'KozGoPr6N-Bold');
	
	App.replaceTo('#quick-links h2', 'KozGoPr6N-Regular');
	App.initLinks('#article .sidebar a', false);

	var $elements = $('#nav > ul > li > ul a'),
		last;

	// Replace all links to cufon
	App.replaceTo($elements, 'KozGoPr6N-Regular');

	// Bind mouseover & moseout events
	$elements
		.mouseover(function(){
		    if (this.className.indexOf('hover') == -1) {
				this.className += ' hover';
				last = this;
				App.replaceTo(this, 'KozGoPr6N-Bold');
			}
			
		})
		.mouseout(function(){
			if (last) {
				last.className = last.className.substr(0, last.className.length - 6);
				App.replaceTo(this, 'KozGoPr6N-Regular');
			}
		});
});
