jQuery(function($) {
	 
function initExpand(){
	var _duration = 300;
	$('.expand-box > li').each(function(){
		var _hold = $(this);
		var _btn = _hold.find('.close .expand-btn');
		var _box = _hold.find('.hidden-box');
		if(_hold.hasClass('opened')) _box.show();
		else _box.hide();
		_btn.click(function(){
			if(!_box.is(':animated')){
				if(_hold.hasClass('opened')){
					_box.slideUp(_duration, function(){
						_hold.removeClass('opened');
					});
				}
				else{
					_hold.addClass('opened');
					_box.slideDown(_duration);
				}
			}
			return false;
		});
	});
}
function initTabs(){
	var _duration = 200;
	$('.tab-holder').each(function(){
		var _a = 0;
		var _ind;
		var _hold = $(this);
		var _btn = _hold.find('.tabs a').each(function(_i){
			this._ind = _i;
			if($(this).hasClass('active')) _a = _i;
		});
		var box_hold = _hold.find('.tab-content-hold');
		var _loader = $('<div class="load-icon">load...</div>');
		box_hold.append(_loader);
		$.ajax({
			url: _btn.eq(_a).attr('href'),
			cache: false,
			dataType: 'html',
			success: function(_html) {
				var _el = $(_html);
				box_hold.append(_el);
				_btn[_a]._box = _el;
			}
		});
		var _f = true;
		_btn.click(function() {
			var _ind = this._ind;
			if(_ind != _a && _f) {
				_f = false;
				if(this._box) {
					box_hold.height(box_hold.height());
					_btn[_a]._box.fadeOut(_duration, function(){
						box_hold.animate({height: _btn[_ind]._box.outerHeight()}, _duration);
						_btn[_ind]._box.fadeIn(_duration, function(){
							box_hold.height('auto');
							_btn.eq(_a).removeClass('active');
							_btn.eq(_ind).addClass('active');
							_a = _ind;
							_f = true;
						});
					});
				}
				else {
					box_hold.height(box_hold.height());
					_btn[_a]._box.fadeOut(_duration, function() {
						_loader.css('top', box_hold.height()/2).fadeIn(_duration/2, function() {
							$.ajax({
								url: _btn.eq(_ind).attr('href'),
								cache: false,
								dataType: 'html',
								success: function(_html) {
									var _el = $(_html);
									_btn[_ind]._box = _el;
									box_hold.append(_el);
									_el.hide();
									box_hold.animate({height: _el.outerHeight()}, _duration);
									_loader.fadeOut(_duration, function(){
										_el.fadeIn(_duration, function(){
											box_hold.height('auto');
											_btn.removeClass('active');
											_btn.eq(_ind).addClass('active');
											_a = _ind;
											_f = true;
										});
									});
								}
							});
						});
					});
				}
			}
			return false;
		});
	});
}

	initExpand();
	initTabs();
});