﻿(function($) {
	$(page_load);
})(jQuery);

function page_load(){
	$('#cdqssmainnav a').attr('target', '_blank');
	$('input.text, .file').each(function(){
		$(this).bind('focus', function(){
			this.select();
			$(this).addClass('focus');
			$(this).attr('isfocus', 'true');
		});
		$(this).bind('blur', function(){
			$(this).removeClass('focus');
			$(this).attr('isfocus', 'false');
		});
	});
	if(jQuery.fn.combobox){
		$("select.select").combobox();
	}
	document.onkeyup = function(event){
		var e = window.event || event;
		if(e.keyCode == 27){
			JobSelector.hideall();
		}
	}
}

/*
 * 选择器
 */
var JobSelector = {
	// 说明: 选择器同一时间只能显示一个窗口, 只有一个遮罩层实例
	// 遮罩层句柄放在这里
	overlay: null,
	// 页面滚动状态
	overflowstatus: '',
	// 所有窗口的句柄存在这里
	wnd: [],
	// 模块数据存在这里
	data: {
		'jobfunc': {
			prevobj: null,
			items: []
		},
		'jobindustry': {
			prevobj: null,
			items: []
		},
		'jobarea':{
			prevobj: null,
			items: []
		},
		'jobautoreply':{
		}
	},
	// 功能: 所有用到的函数都存放在这里
	func: {
		// 职位模块
		'jobfunc':{
			// 显示三级列表
			'showsub': function(obj){
				var prevobj = JobSelector.data.jobfunc.prevobj;
				if(prevobj && prevobj !== obj){
					prevobj.hide();
				}
				var subitem = $(obj).children('.sub');
				subitem.show();
				$(obj).each(function(){
					JobSelector.outside(this, function(){subitem.hide();});
				});
				JobSelector.data.jobfunc.prevobj = subitem;
			},
			'checkid': function(objid){
				this.wnd['jobfunc'].find('#jf' + objid).trigger('click');
			},
			// 选中当前项
			'check': function(obj){
				$(obj).each(function(){
					// 如果当前选项未被禁用
					if(!this.disabled){
						$(obj).parent().parent().find('.all').each(function(){
							if(this.checked){
								this.checked = false;
								JobSelector.func.jobfunc.remove(this);
							}
						});
						if(this.checked){
							//this.checked = false;
							JobSelector.func.jobfunc.add(this);
						}else{
							//this.checked = true;
							JobSelector.func.jobfunc.remove(this);
						}
					}else{
						$(obj).parent().find('.all').each(function(){
							if(this.checked){
								JobSelector.func.jobfunc.add(this);
							}
						});
						//$(obj).parent().find('.one').attr('disabled', false);
						//this.checked = true;
						JobSelector.func.jobfunc.remove(this);
					}
				});
				JobSelector.func.jobfunc.refresh();
			},
			'reset': function(){
				this.data.jobfunc.items = [];
				this.data.jobfunc.prevobj = null;
				$('#jobfunctable input').attr('checked', false);
				$('#jobfunctable .resultlist').html('&nbsp;');
			},
			'uncheck': function(id){
				this.wnd['jobfunc'].find('#jf' + id).trigger('click');
			},
			// 选中二级项
			'checkone': function(obj){
				$(obj).each(function(){
					if(!this.checked){
						if(JobSelector.func.jobfunc.remove(this)){
							$(obj).parent().parent().find('.one').attr('checked', false);
						}
					}else{
						$(obj).parent().parent().find('.one').each(function(){
							if(this.checked){
								this.checked = false;
								JobSelector.func.jobfunc.remove(this);
							}
							//this.disabled = true;
						});
						//this.checked = true;
						JobSelector.func.jobfunc.add(this);
					}
				});
				JobSelector.func.jobfunc.refresh();
			},
			'add': function(info){
				if(JobSelector.data.jobfunc.items.length >= JobSelector.data.jobfunc.callback.selectmax){
					info.checked = false;
					$('#jobfunctable .infotip').html(JobSelector.data.jobfunc.callback.selectmaxmsg[JobSelector.data.jobfunc.lang]);
					$('#jobfunctable .infotip').css('background-color', '#ffc');
					return false;
				}else{
					$('#jobfunctable .infotip').html('&nbsp;');
					$('#jobfunctable .infotip').css('background-color', '');
					JobSelector.data.jobfunc.items.push({id:info.value, title:info.title});
					return true;
				}
			},
			'remove': function(info){
				var isfound = false;
				$('#jobfunctable .infotip').html('&nbsp;');
				$('#jobfunctable .infotip').css('background-color', '');
				for(var n=0; n<JobSelector.data.jobfunc.items.length; n++){
					if(JobSelector.data.jobfunc.items[n].id == info.value){
						JobSelector.data.jobfunc.items.splice(n, 1);
						isfound = true;
						break;
					}
				}
				if(isfound){
					return true;
				}else{
					return false;
				}
			},
			'refresh': function(){
				var resultlist = $('#jobfunctable .resultlist');
				var html = '';
				for(var n=0; n<JobSelector.data.jobfunc.items.length; n++){
					var obj = JobSelector.data.jobfunc.items[n];
					html += '<a href="#" onclick="JobSelector.callfunc(\'jobfunc\', \'uncheck\', ' + obj.id + '); return false;"><input type="checkbox" class="check" checked="true" value="' + obj.id + '" />' + obj.title + '</a>';
				}
				html += '&nbsp;';
				resultlist.html(html);
			}
		},
		// 行业模块
		'jobindustry':{
			'reset': function(){
				this.data.jobindustry.items = [];
				this.data.jobindustry.prevobj = null;
				$('#jobindustrytable input').attr('checked', false);
				$('#jobindustrytable .resultlist').html('&nbsp;');
			},
			'check': function(obj){
				$(obj).each(function(){
					if(this.checked){
						JobSelector.func.jobindustry.add(this);
					}else{
						JobSelector.func.jobindustry.remove(this);
					}
				});
				JobSelector.func.jobindustry.refresh();
			},
			'uncheck': function(id){
				$('#ji' + id).trigger('click');
			},
			'add': function(info){
				if(JobSelector.data.jobindustry.items.length >= JobSelector.data.jobindustry.callback.selectmax){
					info.checked = false;
					$('#jobindustrytable .infotip').html(JobSelector.data.jobindustry.callback.selectmaxmsg[JobSelector.data.jobindustry.lang]);
					$('#jobindustrytable .infotip').css('background-color', '#ffc');
					return false;
				}else{
					$('#jobindustrytable .infotip').html('&nbsp;');
					$('#jobindustrytable .infotip').css('background-color', '');
					JobSelector.data.jobindustry.items.push({id:info.value, title:info.title});
					return true;
				}
			},
			'remove': function(info){
				var isfound = false;
				$('#jobindustrytable .infotip').html('&nbsp;');
				$('#jobindustrytable .infotip').css('background-color', '');
				for(var n=0; n<JobSelector.data.jobindustry.items.length; n++){
					if(JobSelector.data.jobindustry.items[n].id == info.value){
						JobSelector.data.jobindustry.items.splice(n, 1);
						isfound = true;
						break;
					}
				}
				if(isfound){
					return true;
				}else{
					return false;
				}
			},
			'checkid': function(objid){
				$('#ji' + objid).trigger('click');
			},
			'refresh': function(){
				var resultlist = $('#jobindustrytable .resultlist');
				var html = '';
				for(var n=0; n<JobSelector.data.jobindustry.items.length; n++){
					var obj = JobSelector.data.jobindustry.items[n];
					html += '<a href="#" onclick="JobSelector.callfunc(\'jobindustry\', \'uncheck\', ' + obj.id + '); return false;"><input type="checkbox" class="check" checked="true" value="' + obj.id + '" />' + obj.title + '</a>';
				}
				html += '&nbsp;';
				resultlist.html(html);
			}
		},
		'jobarea':{
			'check': function(obj){
				$(obj).each(function(){
					if(this.checked){
						JobSelector.func.jobarea.add(this);
					}else{
						JobSelector.func.jobarea.remove(this);
					}
				});
				JobSelector.func.jobarea.refresh();
			},
			'add': function(info){
				if(JobSelector.data.jobarea.items.length >= JobSelector.data.jobarea.callback.selectmax){
					info.checked = false;
					$('#jobareatable .infotip').html(JobSelector.data.jobarea.callback.selectmaxmsg[JobSelector.data.jobarea.lang]);
					$('#jobareatable .infotip').css('background-color', '#ffc');
					return false;
				}else{
					$('#jobareatable .infotip').html('&nbsp;');
					$('#jobareatable .infotip').css('background-color', '');
					JobSelector.data.jobarea.items.push({id:info.value, title:info.title});
					return true;
				}
			},
			'remove': function(info){
				var isfound = false;
				$('#jobareatable .infotip').html('&nbsp;');
				$('#jobareatable .infotip').css('background-color', '');
				for(var n=0; n<JobSelector.data.jobarea.items.length; n++){
					if(JobSelector.data.jobarea.items[n].id == info.value){
						JobSelector.data.jobarea.items.splice(n, 1);
						isfound = true;
						break;
					}
				}
				if(isfound){
					return true;
				}else{
					return false;
				}
			},
			'reset': function(){
				this.data.jobarea.items = [];
				this.data.jobarea.prevobj = null;
				$('#jobareatable input').attr('checked', false);
				$('#jobareatable .resultlist').html('&nbsp;');
			},
			'showsub': function(obj){
				var prevobj = JobSelector.data.jobarea.prevobj;
				if(prevobj && prevobj !== obj){
					prevobj.hide();
				}
				var subitem = $(obj).children('.sub');
				subitem.show();
				$(obj).each(function(){
					JobSelector.outside(this, function(){subitem.hide();});
				});
				JobSelector.data.jobarea.prevobj = subitem;
			},
			'uncheck': function(id){
				$('#ja' + id).trigger('click');
			},
			'checkid': function(objid){
				$('#ja' + objid).trigger('click');
			},
			'refresh': function(){
				var resultlist = $('#jobareatable .resultlist');
				var html = '';
				for(var n=0; n<JobSelector.data.jobarea.items.length; n++){
					var obj = JobSelector.data.jobarea.items[n];
					html += '<a href="#" onclick="JobSelector.callfunc(\'jobarea\', \'uncheck\', ' + obj.id + '); return false;"><input type="checkbox" class="check" checked="true" value="' + obj.id + '" />' + obj.title + '</a>';
				}
				html += '&nbsp;';
				resultlist.html(html);
			}
		}
	},
	/*
	 * 通过callfunc调用功能模块
	 * ns1: 模块名
	 * method: 函数名
	 * arg: 参数
	 */
	callfunc: function(ns1, method, arg){
		if(this.func[ns1][method]){
			this.func[ns1][method].call(this, arg);
		}
	},
	/*
	 * 在method里存放产生不同模块的函数, 函数返回值将放到窗口内
	 */
	method: {
		// 职位模块
		'jobfunc': function(){
			lang = arguments[1] || 0;
			var rval = ['<table id="jobfunctable" class="jobfunctable' + (lang == 0 ? " cn" : " en") + '" width="700" cellspacing="0" cellpadding="3" style="table-layout:fixed;">'];
			rval.push('<tr><td class="l1" width="170" height="20">' + (lang == 0 ? "已选职能" : 'Function Selected') + '</td><td class="resultlist">&nbsp;</td></tr>');
			rval.push('<tr><td colspan="2" class="infotip" height="20">&nbsp;</td></tr>');
			for(var n in jobfunc_dict){
				rval.push('<tr><td class="l1" width="170">' + jobfunc_dict[n].info[lang] + '</td>');
				rval.push('<td><ul class="l2">');
				for(var m in jobfunc_dict[n].child){
					rval.push('<li onclick="JobSelector.callfunc(\'jobfunc\', \'showsub\', this);">');
					rval.push('<a title="' + jobfunc_dict[n].child[m].info[lang] + '" href="#" onclick="return false;">' + jobfunc_dict[n].child[m].info[lang] + '</a>');
					rval.push('<div class="sub">');
					var jfid = (parseInt(n)*10000 + parseInt(m)*100 + parseInt(0));
					var jftitle = jobfunc_dict[n].child[m].info[lang];
					rval.push('<div class="sub-item" onmouseover="$(this).addClass(\'over\')" onmouseout="$(this).removeClass(\'over\')"><input id="jf' + jfid + '" title="(' + (lang == 0 ? "全部" : "All") + ')' + jftitle + '" type="checkbox" class="all" value="' + jfid + '" onclick="JobSelector.callfunc(\'jobfunc\', \'checkone\', this);" /><label for="jf' + jfid + '"><strong>(' + (lang == 0 ? "全部" : "All") + ')' + jftitle + '</strong></label></div>');
					for(var i in jobfunc_dict[n].child[m].child){
						var jfsid = (parseInt(n)*10000 + parseInt(m)*100 + parseInt(i))
						var jfstitle = jobfunc_dict[n].child[m].child[i][lang];
						rval.push('<div class="sub-item" onmouseover="$(this).addClass(\'over\')" onmouseout="$(this).removeClass(\'over\')"><input id="jf' + jfsid + '" title="' + jfstitle + '" type="checkbox" class="one" value="' + jfsid + '" onclick="JobSelector.callfunc(\'jobfunc\', \'check\', this);" /><label for="jf' + jfsid + '">' + jfstitle + '</label></div>');
					}
					rval.push('</div></li>');
				}
				rval.push("</ul></td></tr>");
			}
			rval.push('</table>');
			return rval.join('\n');
		},
		// 行业模块
		'jobindustry': function(){
			lang = arguments[1] || 0;
			var rval = ['<table id="jobindustrytable" class="jobfunctable' + (lang == 0 ? " cn" : " en") + '" width="700" cellspacing="0" cellpadding="3" style="table-layout:fixed;">'];
			rval.push('<tr><td class="l1" width="170" height="20">' + (lang == 0 ? "已选行业" : 'Industry Selected') + '</td><td class="resultlist">&nbsp;</td></tr>');
			rval.push('<tr><td colspan="2" class="infotip" height="20">&nbsp;</td></tr>');
			for(var n in jobindustry_dict){
				rval.push('<tr><td class="l1" width="170">' + jobindustry_dict[n].info[lang] + '</td>');
				rval.push('<td><ul class="l2">');
				for(var m in jobindustry_dict[n].child){
					var jfid = (parseInt(n)*100 + parseInt(m));
					var jftitle = jobindustry_dict[n].child[m][lang];
					rval.push('<div class="sub-item" onmouseover="$(this).addClass(\'over\')" onmouseout="$(this).removeClass(\'over\')"><input id="ji' + jfid + '" title="' + jftitle + '" type="checkbox" class="one" value="' + jfid + '" onclick="JobSelector.callfunc(\'jobindustry\', \'check\', this);" /><label for="ji' + jfid + '">' + jobindustry_dict[n].child[m][lang] + '</label></div>');
				}
				rval.push("</ul></td></tr>");
			}
			rval.push('</table>');
			return rval.join('\n');
		},
		// 区域
		'jobarea': function(){
			lang = arguments[1] || 0;
			var rval = ['<table id="jobareatable" class="jobfunctable' + (lang == 0 ? " cn" : " en") + '" width="500" cellspacing="0" cellpadding="3" style="table-layout:fixed;">'];
			rval.push('<tr><td class="l1" width="170" height="20">' + (lang == 0 ? "已选地区" : 'City Selected') + '</td><td class="resultlist">&nbsp;</td></tr>');
			rval.push('<tr><td colspan="2" class="infotip" height="20">&nbsp;</td></tr>');
				rval.push('<tr><td colspan="2"><ul class="l2">');
				for(var n in area_dict){
					rval.push('<li onclick="JobSelector.callfunc(\'jobarea\', \'showsub\', this);">');
					rval.push('<a href="#" onclick="return false;">' + area_dict[n].info[lang] + '</a>');
					rval.push('<div class="sub">');
					for(var m in area_dict[n].child){
						var jfid = (parseInt(n)*100 + parseInt(m))
						var jftitle = area_dict[n].child[m][lang];
						rval.push('<div class="sub-item" onmouseover="$(this).addClass(\'over\')" onmouseout="$(this).removeClass(\'over\')"><input id="ja' + jfid + '" title="' + jftitle + '" type="checkbox" class="one" value="' + jfid + '" onclick="JobSelector.callfunc(\'jobarea\', \'check\', this);" /><label for="ja' + jfid + '">' + jftitle + '</label></div>');
					}
					rval.push('</div></li>');
				}
				rval.push("</ul></td></tr>");
			rval.push('</table>');
			return rval.join('');
		}
	},
	/*
	* 调用此方法显示选择器窗口
	*/
	show: function(id, lang, callback){
		if(document.readyState != 'complete' && $.browser.msie){return;}
		if(typeof this.method[id] !== 'function'){
			return;
		}
		// 隐藏其他窗口
		this.hideall();
		// 如果没有遮罩层则创建一个
		if(!this.overlay){
			// 遮罩层
			var overlay	= $('<div class="selector_overlay"></div>');
			overlay.bind('dblclick', function(){JobSelector.hideall();});
			$('body').append(overlay);
			$(window).bind('resize', function(){JobSelector.resize()});
			this.overlay = overlay;
		}
		// 将参数传入
		this.data[id]['callback']	= callback; 
		this.data[id]['lang']	= lang;
		//设置遮罩层的大小
		this.overlay.css('width', document.documentElement.offsetWidth + "px");
		this.overlay.css('height', document.documentElement.scrollHeight + "px");
		var thisobj = this;
		// 如果当前窗口已创建, 则销毁
		if(this.wnd[id]){
			this.wnd[id].remove();
		}
		// 取得窗口内容
			var content = this.method[id].apply(this, arguments);
			var w = $('<div class="selectwnd"></div>').append($('<div class="selectwndwrap"><div class="selectwndtitle">' + callback.wndtitle[lang] + '</div></div>').append('<div class="selectwndcontent">' + content + '</div>'));
			var btn = $('<input type="button" class="selectwndapply" value="' + callback.wndapply[lang] + '" />');
			btn.click(function(){
				callback.set(JobSelector.data[id].items);
				JobSelector.hideall();
			});
			w.append(btn);
			this.wnd[id] = w;
			$('body').append(this.wnd[id]);
		
		if(callback.type == 'dialog'){
			this.wnd[id].find('.selectwndapply').hide();
		}
		// 设置窗口位置
		var pos_top = document.documentElement.scrollTop + (document.documentElement.clientHeight - this.wnd[id].height())/2;
		var pos_left = document.documentElement.scrollLeft + (document.documentElement.clientWidth - this.wnd[id].width())/2;
		pos_top = pos_top < 0 ? 0 : pos_top;
		pos_left = pos_left < 0 ? 0 : pos_left;
		this.wnd[id].css('left', pos_left + 'px');
		this.wnd[id].css('top', pos_top + 'px');
		var existitems = callback.get();
		this.callfunc(id, 'reset');
		if(existitems){
			for(var n=0; n<existitems.length; n++){
				this.callfunc(id, 'checkid', existitems[n]);
			}
		}
		// 使窗口可拖动 
		//this.drag({o:this.wnd[id][0], h:this.wnd[id].find('.selectwndtitle')[0], r:[0, document.documentElement.offsetWidth - this.wnd[id].width() - 4, 0, document.documentElement.offsetHeight - this.wnd[id].height()]});
		// 隐藏select
		$('select').css('visibility', 'hidden');
		// 显示遮罩
		this.overlay.show();
		// 显示窗口
		this.wnd[id].show();
	},
	// 隐藏所有窗口和遮罩层
	hideall: function(){
		if(this.overlay){
			this.overlay.hide();
		}
		for(var n in this.wnd){
			this.wnd[n].hide();
		}
		$('select').css('visibility', 'visible');
	},
	// 拖动函数
	drag: function(arg){
		o = arg.o;
		h = arg.h || o;
		r = arg.r;
		h.onmousedown=function(a){
			var d=document;if(!a)a=window.event;
			var x = a.clientX - o.offsetLeft + document.documentElement.scrollLeft;
			var y = a.clientY - o.offsetTop + document.documentElement.scrollTop;
			if(o.setCapture){
				o.setCapture();
			}
			else if(window.captureEvents){
				window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
			}
	
			d.onmousemove=function(a){
				if(!a)a=window.event;
				var ispagex = true;
				if(!a.pageX){ispagex = false; a.pageX=a.clientX;}
				if(!a.pageY){a.pageY=a.clientY;}
				var tx=a.pageX-x,ty=a.pageY-y;
				o.style.left	= ((!ispagex ? document.documentElement.scrollLeft : 0) + (tx<r[0]?r[0]:tx>r[1]?r[1]:tx) + 'px');
				o.style.top		= ((!ispagex ? document.documentElement.scrollTop : 0) + (ty<r[2]?r[2]:ty>r[3]?r[3]:ty) + 'px');
			};
	
			d.onmouseup=function(){
				if(o.releaseCapture)
					o.releaseCapture();
				else if(window.captureEvents)
					window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
				d.onmousemove=null;
				d.onmouseup=null;
			};
		};
	},
	// 浏览器大小重置后调用这个函数调整选择器窗口大小
	resize: function(){
		if(this.overlay && this.overlay.css('display') !== 'none'){
			this.overlay.css('width', document.documentElement.offsetWidth + "px");
			this.overlay.css('height', document.documentElement.scrollHeight + "px");
		}
		for(var n in this.wnd){
			if(this.wnd[n].css('display') !== 'none'){
				var pos_top = document.documentElement.scrollTop + (document.documentElement.clientHeight - this.wnd[n].height())/2;
				var pos_left = document.documentElement.scrollLeft + (document.documentElement.clientWidth - this.wnd[n].width())/2;
				pos_top = pos_top < 0 ? 0 : pos_top;
				pos_left = pos_left < 0 ? 0 : pos_left;
				this.wnd[n].css('top', pos_top + 'px');
				this.wnd[n].css('left',  pos_left + 'px');
				//this.drag({o:this.wnd[n][0], h:this.wnd[n].children('.selectwndtitle')[0], r:[0, document.documentElement.offsetWidth - this.wnd[n].width(), 0, document.documentElement.offsetHeight - this.wnd[n].height()]});
			}
		}
	},
	/* 鼠标移出对象外的元素会触发callback
	 * obj: 对象(HTML Element)
	 * callback: 鼠标移出对象时调用的函数
	 * 注: onmouseout事件即使鼠标移到对象的子元素也会触发, 所以这里对onmouseout移出做了判断
	 */
	outside: function(obj, callback){
		$(obj).bind('mouseout', function(event){
			var e = window.event || event;
			var p = event.toElement || event.relatedTarget;
			var isfound = false;
			while(p){
				if(p == obj){
					isfound = true;
					break;
				}
				p = p.parentNode;
			}
			if(!isfound){
				callback.apply(obj);
			}
		});
	}
};

function removeme(obj){
	$(obj).remove();
}

var phpserver = {
	call: function(method, callback, args){
		$.ajax({url: 'ajaxcp.php?action=' + method,
		type:'POST',
		data:args,
		dataType: 'json',
		timeout: 1000,
		error: function(xmlhttp, textStatus){
			alert('与服务器通信发生错误, 请检查网络是否连通, 服务器是否可用\nErrorCode:\n' + xmlhttp.responseText);
			if(typeof(callback) == 'function'){
				callback.call(this, 'server.error', {errorCode: '-1', errorText: '与服务器通信发生错误'});
			}
		},
		success: function(data, textStatus){
			if(typeof(callback) == 'function'){
				if(!data.error || data.error.length <= 0){
					callback.call(this, 'success', data);
				}else{
					alert(data.error);
					callback.call(this, 'error', data);
				}
			}
		}	
		});
	}
}

var headerscroll = {
	stopped: false,
	domobj: null,
	effecttime: 1000,
	pausetime: 3000,
	scrollheight: 0,
	offsetheight: 0,
	scroll: function(istop){
		if(!headerscroll.stopped){
			var scrollheight = headerscroll.scrollheight;
			var offsetheight = headerscroll.offsetheight;
			var scrolltop = $(headerscroll.domobj).attr('scrollTop');
			var top	= scrolltop + offsetheight;
			$(headerscroll.domobj).animate({scrollTop: top}, headerscroll.effecttime, 'linear', function(){
				if((parseInt(top/offsetheight) + 1) * offsetheight > scrollheight){
					$(headerscroll.domobj).attr('scrollTop', 0);
				}
				setTimeout(headerscroll.scroll, headerscroll.pausetime);
			});
		}else{
			setTimeout(headerscroll.scroll, headerscroll.pausetime);
		}
	}, 
	scrollstop: function(){
		headerscroll.stopped = true;
	},
	scrollstart: function(){
		headerscroll.stopped = false;
	},
	init: function(objid){
		this.domobj = $(objid);
		if(this.domobj.length <= 0){return;}
		this.scrollheight = this.domobj.attr('scrollHeight');
		this.offsetheight = this.domobj.innerHeight();
		var html = this.domobj.html();
		this.domobj.html(html + html);
		this.domobj.hover(function(){headerscroll.scrollstop();}, function(){headerscroll.scrollstart();});
		setTimeout(headerscroll.scroll, headerscroll.pausetime);
	}
};


var headerscroll1 = {
	stopped: false,
	domobj: null,
	effecttime: 1000,
	pausetime: 3000,
	scrollheight: 0,
	offsetheight: 0,
	scroll: function(istop){
		if(!headerscroll.stopped){
			var scrollheight = headerscroll.scrollheight;
			var offsetheight = headerscroll.offsetheight;
			var scrolltop = $(headerscroll.domobj).attr('scrollTop');
			var top	= scrolltop + offsetheight;
			$(headerscroll.domobj).animate({scrollTop: top}, headerscroll.effecttime, 'linear', function(){
				if((parseInt(top/offsetheight) + 1) * offsetheight > scrollheight){
					$(headerscroll.domobj).attr('scrollTop', 0);
				}
				setTimeout(headerscroll.scroll, headerscroll.pausetime);
			});
		}else{
			setTimeout(headerscroll.scroll, headerscroll.pausetime);
		}
	}, 
	scrollstop: function(){
		headerscroll.stopped = true;
	},
	scrollstart: function(){
		headerscroll.stopped = false;
	},
	init: function(objid){
		this.domobj = $(objid);
		if(this.domobj.length <= 0){return;}
		this.scrollheight = this.domobj.attr('scrollHeight');
		this.offsetheight = this.domobj.innerHeight();
		var html = this.domobj.html();
		this.domobj.html(html + html);
		this.domobj.hover(function(){headerscroll.scrollstop();}, function(){headerscroll.scrollstart();});
		setTimeout(headerscroll.scroll, headerscroll.pausetime);
	}
};


var headerscroll2 = {
	stopped: false,
	domobj: null,
	effecttime: 1000,
	pausetime: 3000,
	scrollheight: 0,
	offsetheight: 0,
	scroll: function(istop){
		if(!headerscroll.stopped){
			var scrollheight = headerscroll.scrollheight;
			var offsetheight = headerscroll.offsetheight;
			var scrolltop = $(headerscroll.domobj).attr('scrollTop');
			var top	= scrolltop + offsetheight;
			$(headerscroll.domobj).animate({scrollTop: top}, headerscroll.effecttime, 'linear', function(){
				if((parseInt(top/offsetheight) + 1) * offsetheight > scrollheight){
					$(headerscroll.domobj).attr('scrollTop', 0);
				}
				setTimeout(headerscroll.scroll, headerscroll.pausetime);
			});
		}else{
			setTimeout(headerscroll.scroll, headerscroll.pausetime);
		}
	}, 
	scrollstop: function(){
		headerscroll.stopped = true;
	},
	scrollstart: function(){
		headerscroll.stopped = false;
	},
	init: function(objid){
		this.domobj = $(objid);
		if(this.domobj.length <= 0){return;}
		this.scrollheight = this.domobj.attr('scrollHeight');
		this.offsetheight = this.domobj.innerHeight();
		var html = this.domobj.html();
		this.domobj.html(html + html);
		this.domobj.hover(function(){headerscroll.scrollstop();}, function(){headerscroll.scrollstart();});
		setTimeout(headerscroll.scroll, headerscroll.pausetime);
	}
};

var headerscroll3 = {
	stopped: false,
	domobj: null,
	effecttime: 1000,
	pausetime: 3000,
	scrollheight: 0,
	offsetheight: 0,
	scroll: function(istop){
		if(!headerscroll.stopped){
			var scrollheight = headerscroll.scrollheight;
			var offsetheight = headerscroll.offsetheight;
			var scrolltop = $(headerscroll.domobj).attr('scrollTop');
			var top	= scrolltop + offsetheight;
			$(headerscroll.domobj).animate({scrollTop: top}, headerscroll.effecttime, 'linear', function(){
				if((parseInt(top/offsetheight) + 1) * offsetheight > scrollheight){
					$(headerscroll.domobj).attr('scrollTop', 0);
				}
				setTimeout(headerscroll.scroll, headerscroll.pausetime);
			});
		}else{
			setTimeout(headerscroll.scroll, headerscroll.pausetime);
		}
	}, 
	scrollstop: function(){
		headerscroll.stopped = true;
	},
	scrollstart: function(){
		headerscroll.stopped = false;
	},
	init: function(objid){
		this.domobj = $(objid);
		if(this.domobj.length <= 0){return;}
		this.scrollheight = this.domobj.attr('scrollHeight');
		this.offsetheight = this.domobj.innerHeight();
		var html = this.domobj.html();
		this.domobj.html(html + html);
		this.domobj.hover(function(){headerscroll.scrollstop();}, function(){headerscroll.scrollstart();});
		setTimeout(headerscroll.scroll, headerscroll.pausetime);
	}
};




function AdvertisementScroll () {
	this.stopped= false;
	this.domobj= null;
	this.effecttime= 1000;
	this.pausetime= 3000;
	this.scrollheight= 0;
	this.offsetheight= 0;
	this.tempObj = this;
 	this.scroll= function(){
    tempObj=this;
	var pausetime= this.pausetime;
		if(!tempObj.stopped){
		   
			var scrollheight = tempObj.scrollheight;
			var offsetheight = tempObj.offsetheight;
			var scrolltop = $(tempObj.domobj).attr('scrollTop');
			var top	= scrolltop + offsetheight;
			$(tempObj.domobj).animate({scrollTop: top}, tempObj.effecttime, 'linear', function(){
				if((parseInt(top/offsetheight) + 1) * offsetheight > scrollheight){
					$(tempObj.domobj).attr('scrollTop', 0);
				}
				$('.middleAdvertisement').each(function(){
				//setTimeout(new AdvertisementScroll().init($(this)).scroll(), tempObj.pausetime);
					setTimeout("new AdvertisementScroll().init($('#"+$(this).attr("id")+"')).scroll()", pausetime);	
											});
				//setTimeout("new AdvertisementScroll().init($('#"+$(tempObj.domobj).attr("id")+"')).scroll(false)", tempObj.pausetime);
			});
		}else{
			
			$('.middleAdvertisement').each(function(){
													
				//setTimeout(new AdvertisementScroll().init($(this)).scroll(), tempObj.pausetime);
				setTimeout("new AdvertisementScroll().init($('#"+$(this).attr("id")+"')).scroll()", pausetime);
											});
			//setTimeout("new AdvertisementScroll().init($('#"+$(tempObj.domobj).attr("id")+"')).scroll(false)", tempObj.pausetime);
		}
		
	}, 
	this.scrollstop= function(){
		this.stopped = true;
	},
	this.scrollstart= function(){
		this.stopped = false;
	},
	
	this.init= function(objid){
    
    var obj = search(objid.attr('id'));
    if(obj)
    {
      return obj;
    }
    
    window.ObjArray.push({"objid":objid.attr('id'),"obj":this});
    
		this.domobj = objid;
		if(this.domobj.length <= 0){return;}
		this.scrollheight = this.domobj.attr('scrollHeight');
		this.offsetheight = this.domobj.innerHeight();
		var html = this.domobj.html();
		this.domobj.html(html + html);
		var tempObj=this;
		this.domobj.hover(function(){
		new AdvertisementScroll().init( $(this)).scrollstop();}, 
		function(){
		new AdvertisementScroll().init( $(this)).scrollstart();});
		setTimeout("new AdvertisementScroll().init($('#"+$(this.domobj).attr("id")+"')).scroll()", this.pausetime);
		return this;
	}
}


//搜索
window.ObjArray=[];
function search(objId){
  for(var j in window.ObjArray)
  {
    if(window.ObjArray[j].objid==objId)
    {
      return window.ObjArray[j].obj;
    }
    else
    {
      continue;
    }
  }
  return null;
}





jQuery.extend({
	//选项卡
	tab:function(id){
		var O_tab = $("#" + id);
		var O_holder = O_tab.find(".tab-holder");
		var O_panel = O_tab.find(".tab-panel");
		O_holder.find("li").each(function(index){
			$(this).mouseover(function(){
				$(this)
					.addClass("current")
					.siblings().removeClass("current");
				O_panel.eq(index).siblings().hide();
				O_panel.eq(index).show();
			});
		});
	},
	//幻灯
	slide_player:function(slide_id,time){
		var index = 0;
		var O_slide = $("#" + slide_id);
		var O_list = O_slide.find(".slide-list");
		var O_title = O_slide.find(".slide-title");
		var O_trigger = O_slide.find(".slide-triggers");
		var F_time = time * 1000;
		var len = O_list.find("a").length;
		var html = '';
			
		for(var i = 1; i <= len; i++){
			if(i == 1){
				html += '<span class="current">' + i + '</span>';
			}
			else{
				html += '<span>' + i + '</span>';
			}
		}
		O_trigger.html(html);	//渲染数字触发器
			var loopTime = setInterval(function(){	//循环切换
				slidePlayer(index);
				index++;
				if(index == len){
					index = 0;
				}
			},F_time);
			
		O_trigger.find("span").mouseover(function(){	//鼠标事件
			index = O_trigger.find("span").index(this);
			slidePlayer(index);
		});
		O_trigger.hover(function(){
			if(loopTime){
				clearInterval(loopTime);
			}},
			function(){
				loopTime = setInterval(function(){
					slidePlayer(index);
					index++;
					if(index == len){
						index = 0;
					}},F_time);
		});
			
		function slidePlayer(index){	//定义幻灯播放效果
			O_list.find("li")
			.eq(index).show()
			.siblings().hide();
			O_title.find("li")
			.eq(index).show()
			.siblings().hide();
			O_trigger.find("span")
			.eq(index).addClass("current")
			.siblings().removeClass("current");
		}
	},
	//模拟下拉菜单
	select_list:function(select_id){
		var O_select = $("#" + select_id);
		var O_result = O_select.find("span")
		var O_option = O_select.find("ul");
		var O_item = O_option.find("li");
		O_select.hover(function(){
			O_option.show();
			O_item.hover(function(){
				$(this).addClass("current")
				.siblings().removeClass("current");
			},
			function(){
				$(this).removeClass("current");
			});
		},
		function(){
			O_option.hide();
		});
		O_item.each(function(i){
			$(this).click(function(){
				O_result.html($(this).html());
				O_option.hide();
				if(i == 0){
					j = 4;
				}else if(i == 1){
					j = 9;
				}else if(i == 2){
					j = 94;
				}
				$("#type_id").val(j);
			});
		});
	},
	//带按钮的翻动
	u_btn_roll:function(id,b_p,b_n,time,p){
		var O_parent = $("." + p);
		var O_obj = $("#" + id);
		var O_p = $("#" + b_p);
		var O_n = $("#" + b_n);
		var linewidth = O_obj.find("li").width();
		speed = time *1000;
		function marquee(){
			O_obj.animate({
				marginLeft: -linewidth },1000,function(){
				$(this).css({marginLeft:"0px"}).find("li:first").appendTo(this);
			});
		}
		var mar = setInterval(marquee, speed);
		O_parent.hover(function(){
			if(mar){
				clearInterval(mar);
			}},
			function(){
				clearInterval(mar);
				mar = setInterval(marquee, speed);
		});
			
		O_p.click(function(){
			O_obj.stop(true,true);
			O_obj.find("li:last").prependTo(O_obj);
			O_obj.css({marginLeft: -linewidth });
			O_obj.animate({marginLeft: 0},1000);
		});
		O_n.click(function(){
			O_obj.stop(true,true);
			O_obj.animate({
			marginLeft: -linewidth },1000,function(){
				$(this).css({marginLeft:"0px"}).find("li:first").appendTo(this);
			});
		});
	},
	//不带按钮的翻动
	u_roll:function(id,time,itemCount){
		var O_obj = $("#" + id);
		var linehieght = O_obj.find("li").height();
		speed = time *1000;
		function marquee(){
			O_obj.animate({
				marginTop: -linehieght},1000,function(){
				if(!itemCount || itemCount==1)
				{
					$(this).css({marginTop:"0px"}).find("li:first").appendTo(this);
				}
				else
				{
					var source=$(this).css({marginTop:"0px"});
					for(var j =0 ; j<itemCount;j++ )
					{
						source.find('li:first').appendTo(this);	
					}
				}
			});
		}
		if(O_obj.find("li").length > 1){
			var mar = setInterval(marquee, speed);
		}	
		O_obj.hover(function(){
			if(mar){
				clearInterval(mar);
			}},
			function(){
				clearInterval(mar);
				mar = setInterval(marquee, speed);

		});
	},
	//背投广告
	ad_rp:function(id,time){
		var O_obj = $("#" + id);
		var O_height = O_obj.height();
		speed = time * 1000;
		function rp_play(){
			O_obj.animate({marginTop: -O_height},1000);			
		}
		var mar = setTimeout(rp_play,speed);
	},
	//图片切换
	ad_change:function(show_id,trigger_id,c){
		var O_show = $("#" + show_id);
		var O_trigger = $("#" + trigger_id);
		O_trigger.find(c).each(function(index){
			$(this).mouseover(function(){
				if(c == "li"){
					$(this).addClass("current")
					.siblings().removeClass("current");
					O_show.find("li").eq(index).siblings().hide();
					O_show.find("li").eq(index).show();
				}
				else{
					O_show.children().eq(index).siblings().hide();
					O_show.children().eq(index).show();
				}
			})
		})
	},
	//关闭
	hidden:function(id){
		var O_obj = $("#" + id);
		O_obj.hide();
	},
	//设为首页
	set_homepage:function(){　 // 设置首页
		if(document.all){
			document.body.style.behavior = 'url(#default#homepage)';
			document.body.setHomePage('http://www.chengdu.cn');
		}
		else if (window.sidebar) {
			if (window.netscape) {
				try {
					netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
				}
				catch (e) {
					alert("该操作被浏览器拒绝，如果想启用该功能，请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true");
				}
			}
			var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
			prefs.setCharPref('browser.startup.homepage', 'http://www.chengdu.cn');
		}
	},
	//窗口广告
	ad_win:function(id,time){
	var projectionWidth = document.documentElement.clientWidth;
	var projectionHeight = document.documentElement.clientHeight;
	var ad_obj = $("#" + id);
	var ad_objWidth = ad_obj.width();
	var ad_objHeight = ad_obj.height();
	var close_obj = ad_obj.children(".close");
	//获取滚动条高度
	function getScrollTop() {    
	    var scrollPos = 0;     
	    if (typeof window.pageYOffset != 'undefined') {     
	       scrollPos = window.pageYOffset;     
	    }     
	    else if (typeof window.document.compatMode != 'undefined' &&     
	       window.document.compatMode != 'BackCompat') {     
	       scrollPos = window.document.documentElement.scrollTop;     
	    }     
	    else if (typeof window.document.body != 'undefined') {     
	       scrollPos = window.document.body.scrollTop;     
	    }     
	    return scrollPos;    
	}
	ad_obj.css({"top":projectionHeight,"right":0});
	ad_obj.animate({"top":projectionHeight - ad_objHeight},2000);
	if($.browser.msie && (parseInt($.browser.version) == 6)){
		$(window).scroll(function(){
			ad_obj.css("top",projectionHeight - ad_objHeight + getScrollTop());
		});
	}
	close_obj.click(function(){
		//if($.browser.msie && (parseInt($.browser.version) == 6)){
			ad_obj.hide();
		//}
	});
	var mar = setTimeout(function(){ad_obj.hide();},time*1000);
}

});



$(function(){
	headerscroll.init('#hotcomment-content');
	$.u_roll('advr_D',3);
	$.u_roll('advr_E',3);
	$.u_roll('advr_F',3);
	$.u_roll('advr_G',3);
	$.u_roll('lietouJob',3);
	$.u_roll('qiuzhiHotJob',3,3);
	
	//headerscroll1.init('#other_0_003');
	//headerscroll2.init('#qiuzhiHotJob');
	//headerscroll3.init('#other_0_001');
/*	$('.middleAdvertisement').each(function(){
				new AdvertisementScroll().init($(this));							
											});
	*/
	}
);
