//<![CDATA[ 
JSoul.$(function(){
	JSoul("#searchBox").initSearchBox(JSoul("#searchTyper"));
	JSoul("#salesMenu").initUpEffect(JSoul("#salesContent"), "a", 200, true);
	//JSoul("#trendMenu").initTrendMenu(JSoul("#trendContent"), 30, true);
	//JSoul("#imgMenu").initUpEffect(JSoul("#imgContent"), "li", 410, false);
	JSoul("#siteList").initColScrollGroup(220, 4, "ul","li","null");
	JSoul("#inNav").initNavChanger(JSoul("@div,className,panel"));
	JSoul("#entryForm").initEntryForm();
	//JSoul("#bookLooks").initSingleOpener("h5", "opened");
	JSoul("#setHomepage").setHomepage();
	JSoul("#setFavorite").addFavorite();
	//JSoul("#rearPush").initRearPush();
});
/*******************JSoul原型扩展方法 [导航效果]******************/
/**
 * JSoul原型扩展方法 [方法类型]
 */
JSoul.fn.extend({
    /**
     * 初始搜索
     * @return JSoul
     */
    initSearchBox: function(searchTyper){
		var main = this.extend({
			choosed: null,
			keyWord: this.find(">keyword").bindEvent({
				onfocus: function(e){
					if(this.value == this.defaultValue){
						this.value = "";
					}
				},
				onblur: function(e){
					if(this.value.trim().length == 0 || this.value == this.defaultValue){
						this.value = this.defaultValue;
					}
				}
			}),
			selects: this.find("select").extend({
				batchShow: function(flag){
					this.each(function(i){
						if(this.getAttribute("for").indexOf(flag) != -1){
							JSoul.show(this.parentNode);
							JSoul.attr(this, "disabled", false);
						}else{
							JSoul.hidden(this.parentNode);
							JSoul.attr(this, "disabled", true);
						}
					});
				}
			})
		}).bindEvent({
			onsubmit: function(e){
				if(main.keyWord.val() == main.keyWord.attr("defaultValue")){
					if(main.choosed.rev == "news"){
						alert(main.keyWord.attr("defaultValue"));
						return false;
					}else{
						main.keyWord.val("");
					}
				}
				return true;
			}
		});
        searchTyper.find("a").bindEvent({
			onclick: function(e){
				if(main.choosed != this){
					if(main.choosed != null){
						main.choosed.className = ""
					}
					this.className = "choosed";
					main.choosed = this;
					main.attr("action", this.rel);
					main.keyBox.classForTyper(this.rev);
					main.selects.batchShow(this.rev);
				}
			}
		}).each(function(i){
			if(this.className == "choosed"){
				main.choosed = this;
			}
		});
		this.keyBox = this.keyWord.parentNode().extend({
			//设置外框长度样式
			classForTyper: function(flag){
				if(flag == "news"){
					this.className("filled filledlong");
				}else{
					this.className("filled");
				}
			}
		});
        return this;
    }
});
/***JSoul prototype extend Method [Login Form]***/
JSoul.fn.extend({
	/**
	 * 初始化登录入口
	 * @return JSoul
	 */
	initEntryForm: function(){
		var mask = JSoul.$b("div", {className:"mask"});
		this.insertBefore(mask);
		this.mask = JSoul(mask);
		this.initLoginForm().initLogoutForm();
		return this;
	},
    /**
     * 初始化登录
     * @return JSoul
     */
    initLoginForm: function(){
        var main = this.extend({
            MainInfo: this.find("#loginInfo"),
            Inputs: this.find("@input,type,text|password").bindEvent({
                onfocus: function(e){
                    if(this.value == this.defaultValue){
						this.value = "";
					}
                }
            }),
            loginBack: function(json){
				main.mask.hidden();
                if (json) {
                    if (json.isSucceed) {
                        main.innerHtml(json.loginContent);
                        main.initLogoutForm();
                    }else {
						main.MainInfo.innerHtml(json.errorInfo);
                    }
                }
            }
        }).bindEvent({
            onsubmit: function(e){
				var account = this["member"].value.trim();
                var isAccount = (account != "" && account != this["member"].defaultValue);
				if(isAccount){
					var pwd = this["password"].value.trim();
                	var isPwd = (pwd.length > 5 && pwd != this["password"].defaultValue);
					if(isPwd){
						main.MainInfo.innerHtml("");
						main.mask.show();
						JSoul.$xJson(this.action, main.loginBack, JSoul.getQuery(this));
					}else{
						main.MainInfo.innerHtml("请正确输入您的密码");
					}
				}else{
					main.MainInfo.innerHtml("请输入正确的帐号");
				}
                return false;
            }
        });
        return this;
    },
    /**
     * 初始已登录
     * @return JSoul
     */
    initLogoutForm: function(){
        var main = this.extend({
            LogoutBtn: this.find("#logoutBtn").bindEvent({
				onclick: function(e){
					main.mask.show();
					JSoul.$xJson(this.href, main.logoutBack);
					return false;
				}
			}),
            logoutBack: function(json){
				main.mask.hidden();
                if (json && json.isSucceed) {
                   main.innerHtml(json.logoutContent);
                   main.initLoginForm();
                }
            }
        });
    }
});
/*******************JSoul原型扩展方法 [导航效果]******************/
/**
 * JSoul原型扩展方法 [方法类型]
 */
JSoul.fn.extend({
	/**
	 * 初始化单个导航切换
	 * @param {String} selector 点击元素
	 * @param {String} openName 开启时的className
	 * @return JSoul
	 */
	initSingleOpener: function(selector, openName){
		var main = this;
		this.extend({
			choosed:null
		});
		this.links = this.find(selector).bindEvent({
			onclick: function(e){
				if (this.parentNode.className != openName) {
					this.parentNode.className = openName;
					if(main.choosed){
						main.choosed.parentNode.className = "";
					}
					main.choosed = this;
				}
			}
		}).each(function(i){
			if(this.parentNode.className == openName){
				main.choosed = this;
			}
		});
	},
	/**
	 * 设置添加收藏
	 */
	addFavorite: function(){
		this.bindEvent({
			onclick: function(e){
				if (document.all) {
					window.external.addFavorite(location.href, document.title);
				}else if (window.sidebar) {
					window.sidebar.addPanel(document.title, location.href, "");
				}
			}
		});
		return this;
	},
	/**
	 * 设置首页
	 */
	setHomepage: function(){
		this.bindEvent({
			onclick: function(e){
				if(window.ActiveXObject){
					this.style.behavior="url(#default#homepage)";
					this.setHomePage(location.href);
				}else if(window.netscape){
					try {  
						netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
						var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
						prefs.setCharPref('browser.startup.homepage',location.href);
					}catch (e) {  
						alert("此操作被浏览器拒绝！\n请在浏览器地址输入“about:config”并回车\n然后將[signed.applets.codebase_principal_support]设置为'true'");  
					}
				}
			}
		});
		return this;
	}
});
/*******************JSoul原型扩展方法 [导航效果]******************/
/**
 * JSoul原型扩展方法 [方法类型]
 */
JSoul.fn.extend({
    /**
     * 背投效果
     * @return JSoul
     */
    initRearPush: function(){
		var main = this.initTimeIntervarEvent(50, 0.2).extend({
			oImg: this.find("img"),
			overStatus: false,
            start: 340,
            callback: function(selfer){
				selfer.style("height", selfer.start + "px");
				selfer.oImg.style("marginTop", (selfer.start - 310)/2 + "px");
            },
            showOut: function(){
				this.clearTimeEvent();
                this.end = 100;
                this.timeIntervarEvent(true);
				return this;
            },
			autoClose: function(){
				this.style("height", this.start + "px");
				this.style("overflow", "hidden");
				this.showOut();
				return this;
			}
		}).initTimeOutEvent(3000, "autoClose").timeOutEvent();
        return this;
    }
});
//]]>