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 initSlideshow(){
	if (typeof $('div.slideshow').slideShow =='function'){
		$('div.slideshow').slideShow({
			numElementLink:'div.footer li b',
			slideEl:'ul li',
			autoSlideShow:true,
			switchTime:5000,
			duration:700
		});
	}
}
function initSlideForm(){
	var _hold = $('.slideform');
	var _d = 300;
	_hold.each(function(){
		var _this = $(this);
		var _slideblock = $('.bottom-form', _this);
		var _f = true;
		_this.mouseenter(function(){
			_this.hover = true;
			if (_slideblock.is(':animated')) _slideblock.stop(true, true);
			_slideblock.slideDown(_d);
		}).mouseleave(function(){
			_this.hover = false;
			if (_f) _slideblock.slideUp(_d);
		});
		_hold.find('input').focus(function(){
			_f = false;
		}).blur(function(){
			if (!_this.hover) _f = true;
			if (_f) _slideblock.slideUp(_d);
		});
		_hold.find('textarea').focus(function(){
			_f = false;
		}).blur(function(){
			if (!_this.hover) _f = true;
			if (_f) _slideblock.slideUp(_d);
		})
	})
}

function initMenu(){
	var _menuItem = $('#nav li');
	_menuItem.each(function(){
		var _drop = $(this).find('.drop:eq(0)');
		var _dropcontent = _drop.children(':eq(0)');
		if (_drop.length) {
			_drop.css({width: _dropcontent.outerWidth(true)+'px'});
			var _width = 0;
			if (window.innerHeight) _width = window.innerWidth;
			else _width = document.documentElement.clientWidth;
			var _pos = $(this).offset();
			if (_pos.left + _drop.width() > _width) _drop.css({left: (_width-_pos.left-_drop.width() - 50)})
		}
	});
	$(window).resize(function(){
		_menuItem.each(function(){
			var _drop = $(this).find('.drop:eq(0)');
			if (_drop.length) {
				var _width = 0;
				if (window.innerHeight) _width = window.innerWidth;
				else _width = document.documentElement.clientWidth;
				var _pos = $(this).offset();
				_drop.css({left: '-1px'});
				if (_pos.left + _drop.width() > _width) {
					_drop.css({left: (_width-_pos.left-_drop.width() - 50)});
				}
			};
		});
	})
}

$(document).ready(function(){
	initTabs();
	initSlideshow();
	initSlideForm();
	initMenu();
});