function initTabs() {
	$('ul.tabset').each(function(){
		var _list = $(this);
		var _links = _list.find('a.tab');

		_links.each(function() {
			var _link = $(this);
			var _href = _link.attr('href');
			var _tab = $(_href);

			if(_link.hasClass('active')) _tab.show();
			else _tab.hide();

			_link.click(function(){
				_links.filter('.active').each(function(){
					$($(this).removeClass('active').attr('href')).hide();
				});
				_link.addClass('active');
				_tab.show();
				return false;
			});
		});
	});
}

function initPopups(){
	var _holder = $('.img-nav');
	var _items = $('li', _holder);
	var _allPopup = $('.pop-up');

	_items.click(function(){
		_allPopup.css('display','none');
		var _this = $(this);
		var pos = _this.position();
		_holder.css('z-index','1');
		_this.parent().css('z-index','5');
		_this._popup  = $('.pop-up', _this);
		_this._link = $("a", _this);
		_this._close = $("a.close", _this._popup);
		if ((_this.parent().innerWidth(true) - pos.left - _this._popup.width()) < 0) pos.left = pos.left - _this._popup.width() - 50;
		if ((_this.parent().innerHeight(true) - pos.top - _this._popup.height()) < 0) pos.top = pos.top + (_this.parent().innerHeight(true) - pos.top - _this._popup.height()) + 40;
		_this._popup.css({
			display:'block',
			top: pos.top+5+"px",
			left: pos.left+45+"px"
		});
		_this._close.click(function(){
			_this._popup.css('display','none');
			return false;
		});
		_this._link.click(function(){ if (!$(this).hasClass("close") && !$(this).hasClass("border")) window.open($(this).attr("href"), "our-community");})
		return false;
	})
};

$(document).ready(function(){
	if ($('ul.tabset').length) initTabs();
	if ($('.img-nav').length) initPopups();
});