var Cms = new function(){
	//全局
	this.init = function(){
		var index = 0;
		var url = window.location.pathname;
		if(url.indexOf('about')==1){
			index = 1;
		}
		else if(url.indexOf('industry')==1){
			index = 2;
		}
		else if(url.indexOf('news')==1){
			index = 3;
		}
		else if(url.indexOf('culture')==1){
			index = 4;
		}
		else if(url.indexOf('talent')==1 || url.indexOf('job')==1){
			index = 5;
		}
		else if(url.indexOf('contact')==1){
			index = 6;
		}
		//菜单
		$('#mainNav').slide({ type:"menu",  titCell:".m", targetCell:".sub", effect:"slideDown", delayTime:200, triggerTime:100,returnDefault:true,defaultIndex:index});
		//链接跳转
		$('#jumpMenu').change(function(){
			var url = $(this).val();
			if(url!=''){
				window.location.href=url;
			}
		});
	};
	//首页
	this.index  = function(){
		$('#banner').slide({ mainCell:".bd ul", effect:"top", delayTime:300, autoPlay:true });
	}
	//播放器
	this.ckplayer = function(url, img, width, height){
		var flashvars={
			f:url,
			c:0,
			p:2,
			i:img
		};
		var params={bgcolor:'#FFF',allowFullScreen:true,allowScriptAccess:'always',wmode:'transparent'};
		var video=[url + '->video/mp4'];
		CKobject.embed('/scripts/ckplayer/ckplayer.swf','video','ckplayer_video',width, height, true,flashvars,video,params);
	};
	//联系我们
	this.contact = function(){
	};
	//关于我们
	this.about = function(){
	};
	//人才
	this.talent = function(){
	};
	//招聘
	this.job = function(){
	};
	this.apply = function(){
		
		$('#ApplyForm').submit(function(){
			//表单
			var name,dd = {},$this=$(this);
			$this.find('input,select,textarea').each(function(){
				name = $(this).attr('name');
				if(name!=undefined){
					dd[name] = $(this).val();
				}
			});
			//提交到数据库
			$.ajax({
				url: $this.attr('action'),
				type: "POST",
				dataType: 'json',
				data: dd,
				success: function(data){
					if(data.status==1){
						alert(data.msg);
					}else{
						alert(data.msg);
						if(data.field != undefined){
							$this.find('input[name="'+data.field+'"]').focus();
						}
					}
					$this.find('.code').trigger('click');
				}
			});
			return false;
		});
	};
	//业务领域
	this.industry = function(){
	};
	//新闻
	this.news = function(id){
		Cms.tree('#treNav');
		//统计
		if(id!=undefined && id!=''){
			//点击事件
			$.post("/tools/submit_ajax.ashx?action=view_article_click",{id:id,click:1,hide:1},function(result){
			});
		}
	};
	//自动视频
	this.video = function(){
		if($('#video').length>0){
			var url = $('#video').html();
			$('#video').html('<p style="text-align: center;"><video class="edui-upload-video  vjs-default-skin   video-js" controls="" preload="/images/video.png" width="600" height="450" src="'+url+'" data-setup="{}"></video></p>');
		}
	};
	//企业文化
	this.culture = function(id){
		Cms.tree('#treNav');
		//统计
		if(id!=undefined && id!=''){
			//点击事件
			$.post("/tools/submit_ajax.ashx?action=view_article_click",{id:id,click:1,hide:1},function(result){
			});
		}
	};
	//搜索
	this.search = function(key){
		if(key!=''){
			$('input[name="keyword"]').val(key);
		}
	};
	//菜单
	this.tree = function(obj){
		//是否展开
		if($(obj).find('.sub').find('.on').length>0){
			$(obj).find('.sub').find('.on').parent().show();
		}
		//绑定事件
		$(obj).find('a').click(function(){
			if($(this).next('.sub').length>0){
				$(this).next('.sub').slideToggle();
				return false;
			}
		});
	};
	//自动调用CK视频插件
	this.checkVideo = function(obj){
		if($(obj).find('embed').length>0){
			var $this = $(obj).find('embed'),
				url = $this.attr('src'),
				width = $this.attr('width'),
				height = $this.attr('height');
			if(url.indexOf('.swf')>0){
				$(obj).find('embed').hide().parent().append('<div style="margin: 0 auto;border: none;"><iframe style="border: none;background-color: transparent;" src="'+url+'" width="'+width+'" height="'+height+'" scrolling="no"></div>');
				
			}else{
				//计算最小宽度
				if(width < 720){
					height = height*(720/width);
					width = 720;
				}
				//插入显示区域
				$(obj).find('embed').hide().parent().append('<div id="video" style="margin: 0 auto;"></div>');
				var params={bgcolor:'#FFF',allowFullScreen:true,allowScriptAccess:'always',wmode:'transparent'};
				CKobject.embed('/scripts/ckplayer/ckplayer.swf','video','ckplayer_video',width, height, true, {f:url, c:0, p:1, i:''}, [url + '->video/mp4'], params);
			}
			$(obj).find('embed').remove();
		}
	};
}();
$(function(){
	//初始化
	Cms.init();
});
//切换验证码
function ToggleCode(obj, codeurl) {
	$(obj).children("img").eq(0).attr("src", codeurl + "?time=" + Math.random());
	return false;
}