/* MikeFilsaime.com, Inc. */
/* copyright MikeFilsaime.com, Inc. not for any other use*/
var _timer;
/* Gallery */
jQuery.fn.gallSlide = function(_options){
	// defaults options	
	var _options = jQuery.extend({
		duration: 700,
		autoSlide: 10000
	},_options);
	
	
	return this.each(function(){
		var _hold = $(this);
		var _speed = _options.duration;
		_timer = _options.autoSlide;
		var _wrap = _hold.find('ul.inform-area-holder');
		var _el = _hold.find('ul.inform-area-holder > li');
		var _count = _el.index(_el.filter(':last'));
		var _w = _el.outerWidth();
		var _next = _hold.find('a.btn-next');
		var _prev = _hold.find('a.btn-previous');
		var _btn = _hold.find('ul.point-area');
		_btn = _btn.find('a');
		var _a = _el.index(_el.filter('.active:eq(0)'));
		if(_a == -1) _a = 0;
		var _wrapHolderW = Math.ceil(_wrap.parent().width()/_w);
		var _t;
		var _active = _a;
		_btn.eq(_active).parent('li').addClass('active');
		
		function scrollEl(){
			_wrap.eq(0).animate({
				marginLeft: -(_w * _active) + "px"
			}, {queue:false, duration: _speed});
		}
		function runTimer(){
			if(_t) clearTimeout(_t);
			_t = setInterval(function(){
				_active++;
				if (_active > (_count - _wrapHolderW + 1)) _active = 0;
				scrollEl();
				_btn.parent('li').removeClass('active');
				_btn.eq(_active).parent('li').addClass('active');
			}, _timer);
		}
		runTimer();
		_hold.hover(function(){
			if(_t) clearTimeout(_t);
		}, function(){
			runTimer();
		});
		
		_next.click(function(){
			_active++;
			if(_t) clearTimeout(_t);
			if (_active > (_count - _wrapHolderW + 1)) _active = 0;
			scrollEl();
			runTimer();
			_btn.parent('li').removeClass('active');
			_btn.eq(_active).parent('li').addClass('active');
			return false;
		});
		_prev.click(function(){
			_active--;
			if(_t) clearTimeout(_t);
			if (_active < 0) _active = _count - _wrapHolderW + 1;
			scrollEl();
			runTimer();
			_btn.parent('li').removeClass('active');
			_btn.eq(_active).parent('li').addClass('active');
			return false;
		});
		
		_btn.click(function(){
			_active = _btn.index($(this));
			if (_active > (_count - _wrapHolderW + 1)) _active = 0;
			scrollEl();
			_btn.parent('li').removeClass('active');
			_btn.eq(_active).parent('li').addClass('active');
			return false;
		});
	});
}
function initTabs(){
	$('div.nav-area').each(function(){
		var hold = $(this);
		var links = hold.find('a.tab');
		var linksGall = hold.find('ul.point-area > li > a');
		var _tabH = [];
		var tabs = $('div.tab');
		var current2 = $('div.inform-area-wrapper');
		var _gallH = current2.outerHeight(true);
		var speed = 700;
		var _active;
		
		links.parent().removeClass('active');
		links.each(function() {
			_tabH.push($('.'+ $(this).attr('href')).outerHeight(true));
			$('.'+ $(this).attr('href')).css('height', 0);
		});
		links.click(function(){
			links.parent().removeClass('active');
			$(this).parent().addClass('active');
			linksGall.parent().removeClass('active');
			if (_timer) _timer = 10000000;
			var current = $('.'+ $(this).attr('href'));
			var _i = links.index($(this));
			tabs.animate({
				height:0
			}, {queue:false, duration: speed});
			current.animate({
				height: _tabH[_i]
			}, {queue:false, duration: speed})
			return false;
		});
		linksGall.click(function(){
			links.parent().removeClass('active');
			_timer = 4000;
			tabs.animate({
				height:0
			}, {queue:false, duration: speed});
			current2.animate({
				height: _gallH
			}, {queue:false, duration: speed})
			return false;
		});
	});
}

$(document).ready(function(){
	$('div#main').gallSlide({
		duration: 1000
	});
	initTabs();
});

function clearText(field){
          if (field.defaultValue == field.value) field.value = '';
          else if (field.value == '') field.value = field.defaultValue;
      }




