jQuery(function(){
	initCufon();
	initGrid();
	initScroll();
});

// init cufon
function initCufon() {
	Cufon.replace('.sections-info', { fontFamily: 'Dispatch_Light' });
	Cufon.replace('.events > h2', { fontFamily: 'Dispatch_Light' });
	Cufon.replace('.autor-info > h2', { fontFamily: 'Dispatch_Light' });
	Cufon.replace('.shop > h2', { fontFamily: 'Dispatch_Light' });
	Cufon.replace('.intro > .holder > h2', { fontFamily: 'Dispatch_Light' });
	Cufon.replace('.twitter > span', { fontFamily: 'Dispatch_Light' });
	Cufon.replace('.wide-text', { fontFamily: 'Dispatch_Light' });
}

// init grid
function initGrid() {
	addClass({
		tagName:'a',
		tagClass:'btn-greed',
		classAdd:'greed-activ',
		addToParent:true
	})
}

function addClass (_options) {
	var _tagName = _options.tagName;
	var _tagClass = _options.tagClass;
	var _classAdd = _options.classAdd;
	var _addToParent = false || _options.addToParent;
	var _el = document.getElementsByTagName(_tagName);
	if (_el) {
		for (var i=0; i < _el.length; i++) {
			if (_el[i].className.indexOf(_tagClass) != -1) {
				_el[i].onclick = function() {
					if (_addToParent) {
						if (this.parentNode.className.indexOf(_classAdd) == -1) {
							this.parentNode.className += ' '+_classAdd;
						} else {
							this.parentNode.className = this.parentNode.className.replace(_classAdd,'');
						}
					} else {
						if (this.className.indexOf(_classAdd) == -1) {
							this.className += ' '+_classAdd;
						} else {
							this.className = this.className.replace(_classAdd,'');
						}
					}
					return false;
				}
			}
		}
	}
}

// init scroll
function initScroll(){
	var dur = 750;
	var hold = jQuery('#header');
	var links = jQuery('#nav > li > a, ul.footer-nav a, a.more, .logo a');
	var h = hold.height();
	
	links.click(function(){
		var link = jQuery(this);
		var href = link.attr('href');
		if(href=="#book"){
			var box = $($(this).attr('href')).offset().top -h;
		} else {
			var box = $($(this).attr('href')).offset().top -h+13;
		}
		if(!$.browser.opera) $('body').stop().animate({scrollTop: box }, {queue:false, duration:dur});
		$('html').stop().animate({scrollTop: box }, {queue:false, duration:dur});
		return false;
	});
}
