(function($) {

	'use strict';



	$(function() {



		$(window).on('load', function() {

			$('#loading').fadeOut();



			if ($('.main-index').length > 0) {

				setTimeout(indexEvn.loaded, 300);

			}

		});



		if ($('.main-index').length > 0) {

			indexEvn.init();

		}





		if ($('.main-join').length > 0) {

			joinEvn.init();

		}



	});



	// 首页

	var indexEvn = {

		loaded: function() {

			var $mainIndex = $('.main-index');



			$mainIndex.addClass('main-loaded');

		},

		init: function() {

			var $header = $('.header'),

				$footer = $('.footer'),

				$container = $('.main-index .container'),

				indexHeight = $(window).height() - $header.height() - $footer.height();



			$container.height(indexHeight);

		}

	};





	// 招聘信息

	var joinEvn = {

		// 招聘信息提交

		formUpload: function() {
			var $mainJoin = $('.main-join');
			// 照片上传预览
			var $fileUpload = $mainJoin.find('.file-upload');
			$fileUpload.on('change', 'input[type="file"]', function() {
				selectImage($(this)[0]);
			});
			function selectImage(file) {
				if (!file.files || !file.files[0]) {
					$fileUpload.find('p').html('不支持预览');
//					$fileUpload.find('img').hide();
					return;
				}
				var reader = new FileReader();
				reader.onload = function(evt) {
					// document.getElementById('image').src = evt.target.result;
					var image = evt.target.result;
					$fileUpload.find('img').attr('src', image).show();
					$fileUpload.find('input[type=hidden]').attr('value', image);
				}
				reader.readAsDataURL(file.files[0]);
			}
			
		

			// 添加更多

			$mainJoin.on('click', '.container-form .add', function() {

				var addtype = $(this).attr('data-type'),

					html = [];

				var i = parseInt($(this).attr('data-length')) || 1;

				switch (addtype) {

					// 添加更多教育背景

					case 'jiaoyu':

						html.push('<tr>');

						html.push('    <td class="in"><input type="text" name="JiaoYuBeiJing[' + i + '][qizhishijian]"></td>');

						html.push('    <td class="in"><input type="text" name="JiaoYuBeiJing[' + i + '][xuexiao]"></td>');

						html.push('    <td class="in"><input type="text" name="JiaoYuBeiJing[' + i + '][xueyuan]"></td>');

						html.push('    <td class="in"><input type="text" name="JiaoYuBeiJing[' + i + '][zhuanye]"></td>');

						html.push('    <td class="in"><input type="text" name="JiaoYuBeiJing[' + i + '][xueli]"></td>');

						html.push('    <td class="in"><input type="text" name="JiaoYuBeiJing[' + i + '][zhuanyepaiming]"></td>');

						html.push('</tr>');

						break;

						// 添加更多项目经历

					case 'xiangmu':

						html.push('<tr>');

						html.push('    <td class="in"><input type="text" name="XiangMuJingLi[' + i + '][qizhishijian]"></td>');

						html.push('    <td class="in"><input type="text" name="XiangMuJingLi[' + i + '][zhize]"></td>');

						html.push('    <td class="in" colspan="4"><input type="text" name="XiangMuJingLi[' + i + '][jianshu]"></td>');

						html.push('</tr>');

						break;

						// 添加更多实习经历

					case 'shixi':

						html.push('<tr>');

						html.push('    <td class="in"><input type="text" name="ShiXiJingLi[' + i + '][qizhishijian]"></td>');

						html.push('    <td class="in"><input type="text" name="ShiXiJingLi[' + i + '][danwei]"></td>');

						html.push('    <td class="in"><input type="text" name="ShiXiJingLi[' + i + '][gangwei]"></td>');

						html.push('    <td class="in" colspan="3"><input type="text" name="ShiXiJingLi[' + i + '][zhize]"></td>');

						html.push('</tr>');

						break;

					default:

						break;

				}



				$(this).attr('data-length', i + 1);

				$(this).parents('dd').find('table tbody').append(html.join(''));

			});

		},

		init: function() {

			var $mainJoin = $('.main-join');



			$mainJoin.on('click', '.tab-nav a', function() {

				var Idx = $(this).index();



				$(this).addClass('active').siblings().removeClass('active');

				$(this).parents('.job-tab').find('.tab-box').eq(Idx).addClass('active').siblings().removeClass('active');

			});





			joinEvn.formUpload();

		}

	};











}(jQuery));