$(function() {
	initSearch();	//init the search box
	if($.trim($(".errorDiv").html()) != "") {
		$(".errorDiv").show();
	}
});

/**
 * 鼠标经过产品效果
 */
function initProduct() {
	//mouseover effect
	$("dl > dd.img").mouseover(function(){
		$(this).addClass("onmouseover").mouseout(function(){
			$(this).removeClass("onmouseover");
		});
		
	});
}

/**
 * add overlay div to body
 */
function addOverlay() {
	if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
		
		$("body","html").css({height: "100%", width: "100%"});
		
		if (document.getElementById("HideSelect") === null) {//iframe to hide select elements in ie6
			$("body").append("<iframe id='HideSelect'></iframe><div id='overlay'></div>");
		}
	}else{//all others
		if(document.getElementById("overlay") === null){
			$("body").append("<div id='overlay'></div>");
		}
	}
	
	if(tb_detectMacXFF()){
		$("#overlay").addClass("overlayMacFFBGHack");//use png overlay so hide flash
	}else{
		$("#overlay").addClass("overlayBG");//use background and opacity
	}
}

/**
 * 判断是否为苹果机
 */
function tb_detectMacXFF() {
  var userAgent = navigator.userAgent.toLowerCase();
  if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
    return true;
  }
}

/**
 * 隐藏产品预览窗口、移除遮罩层
 */
function hideWindow() {
	$("#window").hide();
	$('#overlay,#HideSelect').remove();
	if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
		$("body","html").css({height: "auto", width: "auto"});
		$("html").css("overflow","");
	}
	document.onkeydown = "";
	document.onkeyup = "";
	return false;
}

/**
 * 设置产品预览窗口位置
 */
function setWindowPosition() {

	var windowHeight = document.body.clientHeight;
	var pageHeight = document.body.scrollHeight;
	var bodyTop = getbodyTop();
	var divWindowHeight = 800;
	
	$("#window").css({marginLeft: '-' + parseInt((divWindowHeight / 2),10) + 'px', width: 960 + 'px'});
	
	if ( !(jQuery.browser.msie && jQuery.browser.version < 7)) { // take away IE6
		
		$("#window").css({marginTop:   bodyTop +30 + 'px'});
	}
	else {
	    if((bodyTop + divWindowHeight)>pageHeight){
	        $("#window").css({marginTop:  bodyTop + (pageHeight-bodyTop-divWindowHeight)  + 'px'});
	    }
		else {
		    $("#window").css({marginTop:  bodyTop + 30 + 'px'});
		}
	}
}

/**
 * 取得网页滚动距离
 */
function getbodyTop() {
	var bodyTop = 0;
	if (typeof window.pageYOffset != 'undefined') {   
		bodyTop = window.pageYOffset;   
	} else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') {   
		bodyTop = document.documentElement.scrollTop;   
	}   
	else if (typeof document.body != 'undefined') {   
		bodyTop = document.body.scrollTop;   
	}
	return bodyTop
}

/**
 * 返回鼠标坐标
 */
function MouseEvent(e) {
	this.x = e.clientX;
	this.y = e.clientY;
}

//init the search box
function initSearch() {
	$("#searchkey").val("关键词...");
	$("#searchkey").focus(function() {
		if(this.value=='关键词...') this.value='';}).blur(function() {
		if($.trim(this.value)=='') this.value='关键词...';}
	);
}

var errorInfo = {
    info_username : '用户名不能为空',
    info_pass : '密码不能为空'
}
function clean() {
	$("#message > .content").text('');
}