$(document).ready(function(){
	
	// ajax slide **************************************************************
	var _tabsArea = $('div.tabs-area');
	$('ul.visual-tabs',_tabsArea).empty();
	var _tabs = $('ul.tabs a', _tabsArea);
	
	_tabs.eq(Math.floor(Math.random()*_tabs.length)).addClass('active').find('span.corner').fadeIn(250);
	
	_tabsArea.ajaxTabSlide({
		tabs: 'ul.tabs a',
		holder: 'ul.visual-tabs',
		scrollEl: 'li',
		duration: 1600,
		tabLoadCallback : function(_loading){
			var _p = _loading.find('a.pause');
			if (_p.length == 1) _p.parent().parent().hide();
			$(_loading).slideShow({		
				slideEl:'ul.sub-slides li',		
				linkPause:'a.pause',		
				numElement:'ul.swicher li a',		
				duration:800,		
				autoSlideShow:true,		
				switchTime:6000,
				hideBeforeShow: false,
				hoverStopGallery:false,
				switchLastSlide:function(){
					var _index = _tabs.index(_tabs.filter('.active'));
					_index++;
					if (_index >= _tabs.length) _index = 0;
					_tabs.eq(_index).trigger('click');
				}
			});	
		},
		tabSlideCallback : function(_tab,_hideTab){
			var _pause = _tab.find('ul.swicher li a');
			_pause.filter(':first').trigger('switchSlide');
			var _pauseHide = _hideTab.find('ul.swicher li.active a');
			if (!_pause.hasClass('play')) _pause.filter(':first').trigger('mouseup');
			if (_pauseHide.hasClass('play')) _pauseHide.trigger('mouseup');
		}
	});
	
	
	$("#clientLoginBox").autocomplete({
		source: "/offices.php",
		minLength: 3,
		select: function(event, ui) {
			var loginUrl = ui.item ? 'https://'+ui.item.id+'.emanager.house.gov' : "#";
			$('#clientLoginForm').attr('action', loginUrl);
		}
	});

});
