function initCufon() {
	Cufon.replace('ul#nav a,.text-holder p span,.carousel div ul li .date span,.carousel div ul li .tickets span', { fontFamily: 'CaeciliaLTStd-HeavyItalic', hover: true });
	Cufon.replace('div.bar ul.social li a,.bar .title,#content h1,.text-holder p strong,.text-holder a.btn-buy span,.text-holder em,.bar .all,.month_name strong,.prev-month span,.next-month span,.carousel strong,.text-holder .visit a,.twitter-box h3,.section h3,.article .head .head-text strong,.article h3,.btn-area .prev span,.btn-area .next span,.lightbox .btn-close span,.lightbox .btn-close em,.lightbox .frame .text strong', { fontFamily: 'CaeciliaLTStd-Heavy', hover: true });
	Cufon.replace('#content h2,.month_name span,.article .head .head-text span,.lightbox .frame .text span', { fontFamily: 'CaeciliaLTStd-light', hover: true });
}
jQuery.fn.gallFade = function(_options){
	// defaults options	
	var _options = jQuery.extend({
		duration: 700
	},_options);

	return this.each(function(){
		var _hold = $(this);
		var _speed = $.browser.msie ? 0 : _options.duration;
		var _wrap = _hold.find('div.hold-calendar-ui');
		var _next = _hold.find('div.btn > a.next-month');
		var _prev = _hold.find('div.btn > a.prev-month');
		var _count = _wrap.index(_wrap.filter(':last'));
		var _t;
		var _active = _wrap.index(_wrap.filter('.hold-calendar-active:eq(0)'));
		if (_active < 0) _active = 0;
		var _last = _active;
		
		_wrap.css({opacity:0}).eq(_active).css({opacity:1}).css({opacity:'auto'});
		_wrap.removeClass('active').eq(_active).addClass('hold-calendar-active');
		function fadeEl(){
			_wrap.eq(_last).animate({
				opacity:0
			}, {queue:false, duration: _speed});
			_wrap.eq(_active).animate({
				opacity:1
			}, {queue:false, duration: _speed, complete: function(){
				$(this).css('opacity','auto');
			}});
			
			_wrap.removeClass('hold-calendar-active').eq(_active).addClass('hold-calendar-active');
			_last = _active;
		}
		_next.click(function(){
			_active++;
			if (_active > _count) {
				_active = _count;
			}
			else {
				fadeEl()
			}
			return false;
		});
		_prev.click(function(){
			_active--;
			if (_active < 0) {
				_active = 0;
			}
			else {
				fadeEl()
			}
			return false;
		});
	});
}
jQuery.fn.gallSlide = function(_options){
	// defaults options	
	var _options = jQuery.extend({
		duration: 700,
		autoSlide: 5000
	},_options);

	return this.each(function(){
		var _hold = $(this);
		var _speed = _options.duration;
		var _timer = _options.autoSlide;
		var _wrap = _hold.find('> div >ul');
		var _el = _hold.find('> div > ul > li');
		var _switch = _hold.find('> ul.swicher > li');
		var _count = _el.index(_el.filter(':last'));
		var _w = _el.outerWidth(true);
		var _wrapHolderW = Math.ceil(_wrap.parent().width()/_w);
		var _t;
		var _active = _switch.index(_switch.filter('.active:eq(0)'))*_wrapHolderW;
		if (_active < 0) _active = 0;
		
		_wrap.eq(0).css({
			marginLeft: -(_w * _active) + "px"
		});
		function scrollEl(){
			_wrap.eq(0).animate({
				marginLeft: -(_w * _active) + "px"
			}, {queue:false, duration: _speed});
			_switch.removeClass('active').eq(_active/_wrapHolderW).addClass('active');
		}
		function runTimer(){
			_t = setInterval(function(){
				//if (_active > (_count - _wrapHolderW + 1)) _active = -_wrapHolderW;
				if (_active > (_count - _wrapHolderW)) _active = -_wrapHolderW;
				_active += _wrapHolderW;
				scrollEl();
			}, _timer);
		}
		runTimer();
		_switch.click(function(){
			_active = _switch.index($(this)) * _wrapHolderW;
			if(_t) clearTimeout(_t);
			scrollEl();
			runTimer();
			return false;
		});
	});
}
function initLightBox(){
	$('table.dbem-calendar-table td:has("a.event")').each(function(_i){
		var hold = $(this);
		var links = hold.find('a.event');
		links.attr('rel',_i);
	});
	$('table.dbem-calendar-table a.event[href!="#"]').fancybox({
		'showCloseButton'	: false,
		'showNavArrows'		: false,
		'scrolling'			: 'no',
		onComplete: function(){
			$('#fancybox-inner a.btn-close').click(function(){
				$.fancybox.close();
				return false;
			});
			$('#fancybox-inner a.link-prev').click(function(){
				$.fancybox.prev();
				return false;
			});
			$('#fancybox-inner a.link-next').click(function(){
				$.fancybox.next();
				return false;
			});
		}
	});
	
}
$(document).ready(function(){
	$('div.gallery-calendar').gallFade({
		duration: 1000
	});
	$('div.carousel').gallSlide({
		duration: 1000,
		autoSlide: 10000
	});
	initCufon();
	initLightBox();
});