$(document).ready(function(){
    $("#keyword").keypress(function(e){
        if(e.keyCode == 13) {
            check_search();
        }
    }).blur(function(){
		if($(this).val() == '') $(this).val('请输入您要搜索的关键字...');
	}).focus(function(){
		if($(this).val() == '请输入您要搜索的关键字...') $(this).val('');
	});
	
	$.post('/ajax/category', "", function(data){
		$("#category[rel=1]").html(data);
	}, "text");
	
	$("#category_title").mouseover(function(){
		$(this).addClass('curr');
	}).mouseout(function(){
		$(this).removeClass('curr');
	});


	$("#category li").hover(function(){
		$(this).find("dt").addClass("curr");
		$(this).find("dd").show();
	},function(){
		$(this).find("dt").removeClass("curr");
		$(this).find("dd").hide();
	})

	
    $("#keyword").autocomplete('/ajax/fetchTags', {
        width: ($.browser.msie&&($.browser.version == "6.0"))?370:360,
        max:10,
	    selectFirst:false,
        dataType: "json",
        extraParams:{"keyword":$("#keyword").val(),"type":'search'},
        scrollHeight: 500,
        parse: function(data) {
            return $.map(eval(data), function(row) { 
                return {
                    data: row,
                    value: row.name,
                    result: row.name
                }
            });
        },
        formatItem: function(row, i, max, term) {
            return "<a class='autoComplete_list_a'  style='font-family:宋体;font-size:12px;' onclick='turn_url(\""+row.name+"\")'>"+row.name+"</a><span class='autoComplete_list_span' style='font-family:宋体;font-size:12px;'>约"+row.goods_count+"条</span>";
        },
        formatResult: function(row) {
            return row.name;
        }
    });
});
$(function(){
	$('a').bind('focus',function(){
		if(this.blur){ this.blur(); }
	});
	$.post('/ajax/cartInfo', "", function(data){
		$("#cart_info").html(data);
	}, "text");
});
function cartdrop(id) {
	$.post("/ajax/dropCartInfo", {id:id}, function(res){
		if (0 == res.error) {
			$("#cart_info").html(res.content);
		} else if(1 == res.error) {
			alert(res.message);
		} else {
			return false;
		}
	}, "json");
}
jQuery(document).ready(function(){
	jQuery("#cart_info").bind("mouseenter", function(){		
		jQuery("#cart").show("fast");
	});
	jQuery("#cart_info").bind("mouseleave", function(){
		jQuery("#cart").hide();
	});
	jQuery("#cart_info").bind("mouseleave", function(){
                
		jQuery("#cart").hide();
	});
});

function addToFavorite(url){
	var a;
	if(url){
		a= url;		
	}else{
		a="http://www.zhongyu.com/";
	}
	var b="中域商城-网购上中域，省钱又放心";
	if(document.all){
		window.external.AddFavorite(a,b);
	}else if(window.sidebar){
		window.sidebar.addPanel(b,a,"");
	}else{
		alert("对不起，您的浏览器不支持此操作!\n请您使用菜单栏或Ctrl+D收藏本站。")
	}
}
