function initCufon() {
	Cufon.replace('.info-box h1', { fontFamily: 'Avenir-lt', hover: true});
	Cufon.replace('.info-box a.visit', { fontFamily: 'Avenir-md'});
	Cufon.replace('.sub-box h1',  { fontFamily: 'Avenir-bk'});
	Cufon.replace('.add-nav > li > a, .footer-holder > ul > li > a, .tabset > li > a', { fontFamily: 'Avenir-md', hover: true});
	Cufon.replace('#footer span.learn-more', { fontFamily: 'Avenir-md' });
	Cufon.replace('.info-box',   { fontFamily: 'Avenir-bk'});





}
/*--- popup function ---*/
function initPopup(){
	if($('#fader').length == 0) $('body').append('<div id="fader"></div>');
	var _fader = $('#fader');
	_fader.hide();
	var _popup = -1;
	
	$('a.with-popup').each(function(){
		var _el = this;
		if(_el.hash && _el.hash.length > 1){
			_el._popup = $(_el.hash);
			if(_el._popup.length){
				_el.onclick = function(){
					if(_el._popup){
						_this = $(this);
						_this.addClass('active');
						_el._popup.hide();
						_popup = _el._popup;
						showPopup();
					}
					return false;
				}
				_el._popup.find('.close').click(function(){
					_this.removeClass('active');
					Cufon.refresh('.add-nav > li > a, .footer-holder > ul > li > a, .tabset > li > a');
					if($.browser.msie){
						_popup.hide();
						_fader.fadeOut(200);
						_popup = -1;
						if($.browser.version < 7) $('#wrapper select:not(".outtaHere")').css('visibility', 'visible');
					}
					else{
						_popup.fadeOut(400, function(){
							_fader.fadeOut(200);
							 _popup = -1;
						});
					}
					return false;
				});
			}
		}
	});
	_fader.click(function(){
		if(_popup != -1){
			_this.removeClass('active');
			Cufon.refresh('.add-nav > li > a, .footer-holder > ul > li > a, .tabset > li > a');
			if($.browser.msie){
				_popup.hide();
				_fader.fadeOut(200);
				_popup = -1;
				if($.browser.version < 7) $('#wrapper select:not(".outtaHere")').css('visibility', 'visible');
			}
			else{
				_popup.fadeOut(400, function(){
					_fader.fadeOut(200);
					_popup = -1;
				});
			}
		}
		return false;
	});
	$(document).keydown(function(e){
		if(!e)evt = window.event;
		if(e.keyCode == 27 && _popup != -1){
			_this.removeClass('active');
			Cufon.refresh('.add-nav > li > a, .footer-holder > ul > li > a, .tabset > li > a');
			if($.browser.msie){
				_popup.hide();
				_fader.fadeOut(200);
				_popup = -1;
				if($.browser.version < 7) $('#wrapper select:not(".outtaHere")').css('visibility', 'visible');
			}
			else{
				_popup.fadeOut(400, function(){
					_fader.fadeOut(200);
					_popup = -1;
				});
			}
		}
	});
	function showPopup(){
		_fader.css({
			opacity: 0,
			height: initH(),
			display:'block'
		});
		_popup.css({
			height: initH_lightbox()
		});
		_popup.css({top: $(window).scrollTop()});
		if($.browser.msie && $.browser.version < 7) if($.browser.version < 7) $('#wrapper select:not(".outtaHere")').css('visibility', 'hidden');
		_fader.fadeTo(400, 0.5, function(){
			if(_popup != -1){
				if($.browser.msie) _popup.show();
				else _popup.fadeIn(200, function(){
					if(initH() < _popup.outerHeight()+_popup.offset().top) _fader.height(_popup.outerHeight()+_popup.offset().top);
				});
				_popup.css({top: $(window).scrollTop()+ ($(window).height() - _popup.outerHeight())/2});
				if(initH() < _popup.outerHeight()+_popup.offset().top) _fader.height(_popup.outerHeight()+_popup.offset().top);
 				Cufon.replace('.popup h2', { fontFamily: 'Avenir-lt', hover: true});
			}
		});
	}
	function initH(){
		var _h = $('#wrapper').outerHeight();
		if(_h < $(window).height()) _h = $(window).height();
		if(_h < $('body').height()) _h = $('body').height();
		return _h;
	}
	function initH_lightbox(){
		var _h_popup = _popup.height();
		if (_h_popup > $(window).height()) {
			_popup.css('overflow' , 'auto');
			_h_popup = $(window).height() - 80;
		}
		if (_h_popup > $('body').height()) {
			_popup.css('overflow' , 'auto');
			_h_popup = $('body').height() - 80;
		}
		return _h_popup;
	}
}
/*--- initSlide ---*/
function iniSlide(){
	$('div#footer').each(function(){
		var _wrapper = $('div.sub-box');
		_wrapper.css('display', 'block');
		var speed =  700;
		var hold = $(this);
		var links = hold.find('ul a');
		var _box = $('div.sub-box div.c');
		var _box_h = _box.outerHeight(true);
		
		var tab_h = 0;
		var tabs_h = 0;
		var tab_inner_h = 0;
		var tabs_inner_h = 0;
		$('div.tabs-wrapper-all > div >div').each(function(){
			tab_h = $(this).height();
			$(this).find('> div').each(function(){
				tab_inner_h = $(this).outerHeight(true);
				if(tabs_inner_h < tab_inner_h) tabs_inner_h = tab_inner_h;
			});
			if(tabs_h < tab_h) tabs_h = tab_h;
		});
		var margin_bottom = -(tabs_h + tabs_inner_h);
		$('div.tabs-wrapper-all > div >div>div').css('height', tabs_inner_h + 114);
		_box.css('marginBottom', margin_bottom);
		var _hide = $('div.hide');
		
		links.click(function(){
			_box.animate({
				marginBottom: 0
			}, {duration: speed, queue: false, complete: function(){
			}});
			_hide.css('display', 'none');
		});
		/*
hold.mouseleave(function(){
			_box.animate({
				marginBottom: margin_bottom
			}, {
				duration: speed,
				queue: false
			});
		});
		
*/
	});
}
$(document).ready(function(){
	initCufon();
	initPopup();
	iniSlide();
});
