$(document).ready(function(){
	// tooltip
	var _x = 0;
	var _y = 0;
	$('.mem-list li').mousemove(function(e){
		var offset = $(this).offset();
		_x = e.pageX - offset.left - 60;
		_y = e.pageY - offset.top;
		if ($('div.tooltip:visible').get(0)) {
			$('div.tooltip:visible').css({left:_x,top:_y})
		}
	});
	$('.mem-list li').hover (function() {
		$(this).addClass('show-pop');
	}, function() {
		$(this).removeClass('show-pop');
	});
	// gallery
	$('div.gallery-holder div').cycle({ 
		speed:       		200, 
		timeout:     		3000, 
		next:		   	'#promo .gallery-holder li.prev',
		prev:		   	'#promo .gallery-holder li.next',
		pager:      		null, 
		pagerEvent: 		'mouseover',
		pauseOnPagerHover:	true, 
		pause:		   	true
	});
	// tabs
	$('.tabset').find('a.tab').each(function(){
		if($(this).is('.active')){
			$($(this).attr('href')).show();
			tab_page_fetch($($(this).attr('href'))[0]); // display currently active tab
		} else {
			$($(this).attr('href')).hide();
		}
	});
	$('.tabset').find('a.tab').click(function(){
		$(this).parent().parent().find('a.tab').each(function(){
			$(this).removeClass('active');
			$($(this).attr('href')).hide();
		});
		$(this).addClass('active');
		$($(this).attr('href')).show();
		tab_page_fetch($($(this).attr('href'))[0]); // display newly active tab
		return false;
	});
});

var ajax;
function get_ajax()
{
	try { return new XMLHttpRequest(); } catch (e) {}
	try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {}
	try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
	return null;
}

function tab_page_fetch(obj)
{
	if (typeof(obj) == 'string')
	{
		obj = document.getElementById(obj);
	}
	if (typeof(obj) == 'object' && jQuery.trim(obj.innerHTML) == '' && (ajax = get_ajax()))
	{
		ajax.onreadystatechange = function() { if (ajax.readyState == 4) { tab_page_response(obj); } };
		ajax.open("GET", obj.id + '.php', true);
		ajax.send(null);
	}
	return false;
}

function tab_page_response(obj)
{
	if (ajax.responseText)
	{
		obj.innerHTML = ajax.responseText;
	}
}
