/* bannei自定义界面元素 */

(function(){

/* dropdownlist */
$.fn.diyselect = function(action){
	this.each(function(o){
		var me = $(this),
			cur = me.find(".diyselect_current")[0],
			t = me.find("input")[0],
			ul = me.find("ul")[0];
		$(t).click(function(){
			if( ul.style.display != "block" ){
				ul.style.display="block";
				$(document.body).bind("click", whenClick);
			} else {
				whenClose();
			}			
		});

		function whenClick(e){
			var a = e.target, b = a.parentNode;
			if( b.parentNode.parentNode.className == "diyselect" ){
				t.value=a.innerHTML;
				if(typeof action=="function") action.call(me[0],a);
				whenClose();
				cur.className = "";
				b.className = "diyselect_current";
				cur = b;
			}else if( b.className != "diyselect" ){
				whenClose();
			}
			return false;
		}
		function whenClose(){
			ul.style.display="none";
			$(document.body).unbind("click", whenClick);
		}
	});
	return this;
};

/*弹出菜单*/
$.fn.popupmenu = function(){
	this.each(function(){
		var ul = $(this).find("ul")[0], 
			a = $(this).find("a")[0];
			
		$(this).mousemove(function(){
			ul.style.display = "block";
			//a.addClass("hover");
			
			$(a).parent().removeClass('arrow');
			$(a).parent().addClass('arrow');
		});
		$(this).mouseout(function(e){
			ul.style.display = "none";
		    $(a).parent().removeClass('arrow');
			$(a).parent().addClass('arrow');			
		});
	});
};

/*闪动标题栏*/
var g_bickerswitch = 0;
var g_bickertext = "";
var g_title = "";
$.fn.bickertitle = function(bickertext, title){	
	var blank = "";
	
	if(g_bickertext == ""){
		g_bickertext = bickertext;
		g_title = title;
	}

	for(var i=0; i<g_bickertext.length; i++)
		blank += "　";

	if(g_bickerswitch % 2){
		window.document.title = "【"+blank+"】" + " - " + g_title;
		window.status = "【您有" + g_bickertext + "，请注意查收！】"
	}
	else{
		window.document.title = "【"+g_bickertext+"】" + " - " + g_title;
		window.status = "";
	}
	
	g_bickerswitch++;
	
	//if(g_bickerswitch < 100)
	//	setTimeout("$('body').bickertitle()", 1000);
	//else
	//	window.document.title = g_title;
	window.status = "【您有" + g_bickertext + "，请注意查收！】";
};
})();

$(function(){
	$(window).load(function(){
		/* text box style */
		/*$("input[@type=text],input[@type=password],textarea").focus(function(){
			//if(this.className != 'form-text_focus')
			if(this.className.indexOf('_focus',this.className.length-6) < 0) {	
				this.className = this.className + "_focus";
			}
		}).blur(function(){		
			this.className = this.className.replace('_focus', '');
		});

		/* button style */
		/*$("input[@type=button],input[@type=submit], button").mouseover(function(){
			if(this.className.indexOf('_hover',this.className.length-6) < 0) {	
				//this.className = this.className + "_hover";
				var c_name = this.className;
				$(this).removeClass(c_name);
				$(this).addClass(c_name + "_hover");
			}
		}).mouseout(function(){
			//this.className = this.className.replace(/_hover/g, '');
			var c_name = this.className;
			$(this).removeClass(c_name)
			$(this).addClass(c_name.replace(/_hover/g, ''));
		});*/
	});

	/* ajax event */
	$('.loading-div').css('display','none');
	
	//关闭页面提醒消息
	$("#mid-top-close").click(function () {
		$('.mid-top').css('display','none');
	});
	
	/*
	$(".loading-div").ajaxStart(function(){
		$(this).show();
	});

	$(".loading-div").ajaxStop(function(){
		$(this).hide();
	});	
	*/
	
	/* ajax event */
	/*
	$(":button, :submit").ajaxStart(function () {
		var id = this.id;
		if(typeof($("#"+id+"_img").attr("id")) == "undefined") {
			$("#"+id).after("&nbsp;<img id='"+id+"_img' src='/site_media/bannei_portal/img/loading.gif' />");
		}
		$("#"+id).attr("disabled", true);
		$("#"+id+"_img").show();
	}).ajaxStop(function () {
		$("#"+this.id+"_img").hide();
		$("#"+this.id).attr("disabled", false);
	});
	*/
	
	/* tab代替回车 */
	//$(document).keydown(function(){if(event.keyCode==13){event.keyCode='9';}})
});

/*点击复制文本框文字*/
$.fn.cliptext = function(){
	return this.click(function(){
		if(clipboardData.setData("text", $(this).val()))
			alert("复制成功！");
		else
			alert("复制失败！");
	});
};

//兼容ff,ie的键盘事件
document.onkeydown = function( event_e ){
	 if( window.event ) {
		 event_e = window.event;
	 }
	 var int_keycode = event_e.charCode||event_e.keyCode;
	 if( int_keycode == '13' ) {
		 $('#submit').click();
	 }
}
