$.extend({
	setHomePage:function(url) {
		url = url||"http://" + document.location.host;
		if(!window.confirm("是否设置" + url + "为首页?")) return false;
		if (window.sidebar)
		{
			try { 
			   netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); 
			} 
			catch (e) 
			{  
			   alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将[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://'+document.location.host);
		}
	},
	

	addFavorite:function(url,title) {   
	url = url||window.location.href;
	title = title||document.title;
	
		if(window.ActiveXObject){
			window.external.addFavorite(url,title);
		}
		else {
			window.sidebar.addPanel(title,url,""); 
		}
	},

	
	//显示“加入收藏夹”
	showFavorite:function(txt) {
		txt = txt||"加入收藏";
		document.writeln('<a href="javascript:$.addFavorite()">' + txt + '</a>');
	},

	
	//显示“设为首页”
	showSethome:function(txt, css, url) {
		txt = txt||"设为首页";
		css = css||"";
		css = (css.length == 0)? "":" class=\"" + css + "\"";
		url = url||"http://"+document.location.host;
		
		if(document.all) {
			document.writeln("<a href=\"#\" onclick=\"this.style.behavior='url(#default#homepage)';this.setHomePage('" + url + "');\"" + css + ">" + txt + "</a>");
		}
		else {
			document.writeln("<a href=\"#\" onclick=\"$.setHomePage('" + url + "')\"" + css + ">" + txt + "</a>");
		}
	},
	

	//登陆入口
	loginTxt:function(txt, settings) {
		settings = jQuery.extend({callback:false, target:"", css:""}, settings);

		var host;
		if(/\w+\.cn\.(.+)$/.test(window.location.host)) {
			host = window.location.host.replace(/\w+\.cn\.(.+)$/, "http://member.$1");
		}
		else {
			host = window.location.host.replace(/\w+\.(.+)$/, "http://member.$1");
		}

		var url = host + "/login.html";
		if(settings.callback) {
			url += "?callback=" + encodeURIComponent(window.location);
		}

		document.writeln('<a href="' + url + '" target="'+ settings.target +'" class="' + settings.css + '">' + txt + '</a>');
	},

	
	//注册入口
	registerTxt:function(txt, settings) {
		settings = jQuery.extend({callback:false, target:"", css:""}, settings);
		var host;
		if(/\w+\.cn\.(.+)$/.test(window.location.host)) {
			host = window.location.host.replace(/\w+\.cn\.(.+)$/, "http://member.$1");
		}
		else {
			host = window.location.host.replace(/\w+\.(.+)$/, "http://member.$1");
		}

		var url = host + "/reg.html";
		if(settings.callback) {
			url += "?callback=" + encodeURIComponent(window.location);
		}

		document.writeln('<a href="' + url + '" target="'+ settings.target +'" class="' + settings.css + '">' + txt + '</a>');
	},
	topBar:function(w){
	var w=w||"div.topbar dl";
	if($.browser.version==6){
		$(w).each(function(){
		  $(this).hover(function(){$(this).addClass("hover")},function(){$(this).removeClass("hover")});
		});		
	  };
	},
	reHeight:function(w) {
        var w = $(w);
        w.find("li").each(function() {
            var w = $(this);
            var c = w.find("h3");
            var padding = Math.round((w.height() - c.height()) / 2);
            c.css({
                "padding-top": padding,
                "padding-bottom": padding
            });
            w.hover(function() {
                w.addClass("current");
            },
            function() {
                w.removeClass("current");
            });
        });
    },
	focusPlay:function(w, t) {
        $(w).append("<ol><li class=\"current\">1<\/li><\/ol>");
        for (i = 2; i < $(w + " ul li").length + 1; i++) {
            $(w + " ol").append("<li>" + i + "<\/li>")
        }
        var current;
        function play(i) {
            $(w + " ul li").stop(true, true);
            $(w + " ol li").stop(true, true);
            $(w + " ul li:eq(" + i + ")").fadeIn("slow").siblings().fadeOut("fast");
            $(w + " ol li:eq(" + i + ")").addClass("current").siblings().removeClass();
            current = ++i;
        }
        function autoPlay() {
            playIng = setInterval(function() {
                if (current == null) {
                    current = 1;
                } else if (current == $(w + " ul li").length) {
                    current = 0;
                }
                play(current);
            },
            t);
        }
        $(w + " ol li").each(function(i) {
            $(this).hover(function() {
                clearInterval(playIng);
                play(i);
            },
            function() {
                autoPlay();
            });
        });
        autoPlay();
    }
	
		
});



$.fn.extend({
	//刷新验证码
	reverify:function() {
		var host;
		if(/\w+\.cn\.(.+)$/.test(window.location.host)) {
			host = window.location.host.replace(/\w+\.cn\.(.+)$/, "http://a.$1");
		}
		else {
			host = window.location.host.replace(/\w+\.(.+)$/, "http://a.$1");
		}

		host += "/checkcode.html?" + Math.random();
		$(this).attr("src", host);
		$(this).attr("title", $(this).attr('alt'));
	},
	
	

	//搜索关键词
	search:function(type) {
		type = type||"products";
		var keyword = $(this).val();
		keyword = keyword.replace("-", "=2D");
		
		if(keyword.length > 0) {
			var url = window.location.host.replace(/.+?(\..+?\..+)$/, "http://search$1/");
			url += type + "-" + encodeURIComponent($.trim(keyword)) + ".html";
			window.location = url;
		}
		else {
			alert("您还没有输入要进行搜索的关键词");
		}
	}
});