// JavaScript Document
(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':{
		}
	},
	
	/* 鼠标移出对象外的元素会触发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 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);
	}
};

$(function(){
	headerscroll.init('#hotcomment-content');}
);

