//wapi frame 
(function(A){
	//return core class
	var core = function(a, w){
		return new core.fn.init(a, w);
	};
    
	//core class
	core.fn = core.prototype = {
		init: function(a, w){			
			if(!a) return this;
			w = this.w = typeof w !== "undefined" ? w : window;
			
			if(a.nodeType){
				this[0] = a;
                this.length = 1;
                return this;
			}
			
			function domain(fT) {
                var d = false;
                try{
                    var s = window.document.domain;
                    if(typeof fT != "undefined" && fT){
                        window.document.domain = s;
                        d = true;
                    }else{
                        var i = s.search(/\./);
                        if (i >= 0) {
                            s = s.substr(i + 1);
                            document.domain = s;
                            d = true;
                        }
                    }
                }catch(e){}
                
                return d;
            }
			
            var fT = 1;
			while(1){
				try{			
					if(a === "body"){
						this[0] = w.document.body;
						this.length = 1;
						return this;
					}
					
					if(typeof a === "string"){
						var id = core.reg.selector.exec(a);
						if(id){
							if(id[1]){
								var node;
								if(node = w.document.getElementById(id[1])){
									this[0] = node;
									this.length = 1;						
								}
								
								return this;
							}else if(/^\w+$/.test(a)){
								a = w.document.getElementsByTagName(a);
								
								return core.merge(this, a);
							}else if(/^<([\w\W]+)>$/.exec(a)){
								var aTag = /^<([\w\W]+)>$/.exec(a);
								if(aTag[1]){
									this[0] = document.createElement(aTag[1]);
									this.length = 1;
									
									return this;
								}
							}
						}
					}
					break;
				}catch(e){
					if(!domain(fT)) {
                        fT = 0;
                        break;
                    }
				}
			}
			
			return this;
		},
		length: 0,
		each:function(a){
			return core.each(this, a);
		}
	};
    
	core.fn.init.prototype = core.fn;
    
	//extend handler
	core.extend = core.fn.extend = function(){
		var target = arguments[0] || {};
		var index = 1;
		var len = arguments.length;
		var deep = false;
		var property;
		var e;
        
		//deep copy
		if(typeof target === "boolean"){
			deep = target;
			target = arguments[1] || {};
			index = 2;
		}
		
		if(index === len){
			target = this; 
			--index;
		}
		
		for(; index < len; index++){
			if((e = arguments[index]) != null){
				for(property in e){
					var copy = e[property];
					var src = target[property];
                    //window.window === window
					if(target === copy) continue;
					if(deep && copy && (core.isPlainObject(copy) || core.isArray(copy))) {
						src = src && (core.isPlainObject(src) || core.isArray(src)) ? src : {};
						target[property] = core.extend(deep, src, copy);
					}else if(typeof copy !== "undefined") target[property] = copy;
				}
			}
		}
		
		return target;
	};
    
	//factory
	core.factory = {
		/**
		* attr/css function handler 
		*
		* @param  {Object}        a : Local bject
		* @param  {Object/String} b : attr/css property name if it is JSON object, it will be iterated.
		* @param  {String}        c : attr/css value
		* @param  {Function}      d : attr/css function
		*
		* @return {Object/String}   : if param "c" is undefined, it will return attr/css value. On otherwise, the attr/css value will be set.
		*
		*/
		x:function(a, b, c, d){
			var len = a.length;
			if(typeof b === "object"){
				for(var p in b){
					core.factory.x(a, p, b[p], d);
				}
				return a;
			}
			
			if(typeof c !== "undefined"){
				for(var i = 0; i < len; i++){
					d(a[i], b, c);					
				}
				return a;
			}
			
			return len ? d(a[0], b): null;
		},
		
		/**
		* common function handler 
		*
		* @param  {Object}   a : Local bject.
		* @param  {Function} b : function whitch will be handled.
		* @param  {Array}    c : arguments of function.
		*
		* @return {Object}   : execute function.
		*
		*/
		y:function(a, b, c){
			core.each(a, function(){				
				if((this || this.nodeType || this.nodeType === 1) && core.isFunction(b)){
					if(typeof c !== "undefined"){
						var v = [this].concat(c);
						return b.apply(this, v);
					}else{
						return b.call(this, this);
					}
				}
			})
		}
	};
	
	core.extend({
		/**
		* match browser
		*
		* @param  {String}  a : browser.
		*
		* @return {Boolean}   : check result.
		*
		*/
		uaMatch:function(a){
			var ua = navigator.userAgent;
			switch(a.toLowerCase()){
				case "ie":
				return /msie/i.test(ua)  && !/opera/.test(ua);
				break;
				case "ie6":
				return /(msie 6)/i.test(ua);
				break;
				case "safari":
				return /safari/i.test(ua);
				break;
				case "chrome":
				return /chrome/i.test(ua);
				break;
				case "opera":
				return /opera/i.test(ua);
				break;
				case "firefox":
				return /firefox/i.test(ua); 
				break;
				case "mobile":
				return /phone/i.test(ua) || /mobile/i.test(ua) || /mini/i.test(ua);
				break;
				case "iphone":
				return /iphone/i.test(ua) || /android/i.test(ua);
				break;
                case "ipad":
				return /ipad/i.test(ua);
				break;
				case "itunes":
				return /itunes/i.test(ua);
				break;
			}
		}
	});
	
	/**
	* check global property
	*
	*/
	(function(){		
		var i = false;
		var doc = document;
		
		var d = doc.createElement("div");
		d.style.display = "none";
		d.innerHTML = "<a style='opacity:.55; float:left;'></a>";
		
		var l = d.getElementsByTagName("a")[0];		
		var script = doc.createElement("script");
		var h = doc.getElementsByTagName("head")[0] || doc.documentElement;
		var f = "_f" + (new Date).getTime();
		script.type = "text/javascript";
		try{script.appendChild(doc.createTextNode("window." + f + " = 1"));}catch(e){}
		h.insertBefore(script, h.firstChild);
		if(A[f]) {
			i = true;
			delete A[f];
		}
		
		core.support = {
			filter:core.uaMatch("ie") ? false : /^0.55$/.test(l.style.opacity),
			cssFloat:!!l.style.cssFloat,
			addListener:!!d.addEventListener,
			CSS1Compat:document.compatMode != "BackCompat",
			script:i
		}
	})();
	
    core.props = { //compat handler
		"for": "htmlFor",
		"class": "className",
		"float": "styleFloat",
		cssFloat: "styleFloat",
		styleFloat: "styleFloat",
		readonly: "readOnly",
		maxlength: "maxLength",
		cellspacing: "cellSpacing",
		rowspan: "rowSpan",
		tabindex: "tabIndex"
    };
	
	core.reg = { //reg array
		selector: /^#([\w-]+)$|^<?([\W\w]+)>?$/,
		"float": /float/i,
		Capital: /([A-Z])/g,
		cssName: /-([a-z])/ig,
		chkAlpha: /alpha\([^)]*\)/,
		getOpacity: /opacity=([^)]*)/,
		chkAttr: /href|src|style/i,
		chkInput: /(button|input)/,
		isPixel: /z-?index|font-?weight|opacity|zoom|line-?height/i
	};
	
	core.format = { //format float & cssName
		"float": core.support.cssFloat ? "cssFloat": "styleFloat",
		"cssName": function(a, b){
			return b.toUpperCase();
		}
	};
	
	var ob = {
		position:"absolute",
		visibility:"hidden",
		display:"block"
	};

	var aLR = ["Left", "Right"];
	var aTB = ["Top", "Bottom"];
	
	/**
	* set/get attribute of HTMLElement
	*
	* @param {String} a : attribute name.
	* @param {String} b : attribute value.
	*
	* @return if param "b" is undefined, it will return attribute value. On otherwise, "b" will be set.
	*
	*/
	core.fn.attr = function(a, b){
		return core.factory.x(this, a, b, core.attr);
	};
	
	core.extend({
		attr:function(elem, name, val){
			if(elem.nodeType == 3 || elem.nodeType == 8) return null; //do not handle text and comment node
			
			var isWrite = typeof val !== "undefined"; //write or read
			var isHandle = elem.nodeType != 1 || !core.isXMLDoc(elem); //do not handle XML
			var name = isHandle && core.props[name] || name; //handle attribute name
			
			if(elem.nodeType == 1){
				var invariant = core.reg.chkAttr.test(name); //attribute which is not handled
				
				if(name in elem && isHandle && !invariant){
					if(isWrite && (name !== "type" && !core.reg.chkInput.test(elem.nodeName))) elem[name] = val;
					else if(!isWrite){
						//browsers index elements by id/name on forms, give priority to attributes.
						if (elem.nodeName.toUpperCase() == "FORM" && elem.getAttributeNode(name)) return elem.getAttributeNode(name).nodeValue;
						
						return elem[name];
					}
					
				}
				
				if(isHandle && name === "style"){
					if(isWrite) elem.style.cssText = "" + val;
					
					else return elem.style.cssText;					
				}
				
				if(isWrite) elem.setAttribute(name, val);
				else return elem.getAttribute(name);
				// return attribute when read
                // return element when write
				return elem == null ? null : elem
			}
		}
	});
    
	/**
	* set/get css of HTMLElement
	*
	* @param {String} a : css name.
	* @param {String} b : css value.
	*
	* @return if param "b" is undefined, it will return css value. On otherwise, "b" will be set.
	*
	*/
	core.fn.css = function(a, b){
		return core.factory.x(this, a, b, function(elem, name, val){
			if(typeof val === "undefined") return core.curCss(elem, name);
			if(typeof val === "number" && !core.reg.isPixel.test(name)) val += "px";
			core.style(elem, name, val);
		})
	};
	
	core.extend({		
		style:function(elem, name, val){
			if(elem.nodeType == 3 || elem.nodeType == 8) return null;
			if((/width|height/i.test(name)) && parseFloat(val) < 0) val = null;
			
			var style = elem.style || elem;
			var isWrite = typeof val !== "undefined";			
			
			if( !core.support.filter && name === "opacity"){ //handle opacity for ie
				if(isWrite){
					style.zoom = 1;
					val = parseInt(val, 10) + "" === "NaN" ? "" : "alpha(opacity="+ val*100 +")";
					elem = style.filter || core.curCss(elem, "filter") || "";
					style.filter = core.reg.chkAlpha.test(elem) ? elem.replace(core.reg.chkAlpha, val) : val
				}
				
				return style.filter && style.filter.indexOf("opacity") > -1 ? parseFloat(core.reg.getOpacity.exec(style.filter)[1])/100 + "" : "";
			}
			
			//handle css name
			if(core.reg.float.test(name)) name = core.format.float;
			name.replace(core.reg.cssName, core.format.cssName);//从驼峰结构转为连字符风格
			
			if(isWrite) style[name] = val;
			
			return style[name];
		},
		css:function(elem, name, val){
			//在标准模式中，offsetWidth是包含padding，borderWidth与width
            //在怪癖模式下，offsetWidth等于width，而width是包含padding与borderWidth
			if((name === "width" || name === "height") && typeof val === "undefined"){
				var wh;
				var aXY = name === "width" ? aLR : aTB;
				function getWH(){
					wh = name === "width" ? elem.offsetWidth : elem.offsetHeight;
					core.each(aXY, function(){
						wh -= parseFloat(core.curCss(elem, "padding" + this, true)) || 0;
						wh -=parseFloat(core.curCss(elem, "border" + this + "Width", true)) || 0;
					})
				}
				elem.offsetWidth !==0 ? getWH() : core.swap(elem, ob, getWH);
				
				return Math.max(0, Math.round(wh));
			}
			
			return core.style(elem, name, val);
		},
		curCss:function(elem, name){
			var val;
			var compat = document.defaultView && document.defaultView.getComputedStyle;
			
			//handle opacity for ie
			if(!core.support.filter && name === "opacity"){
				val = core.reg.getOpacity.test(elem.currentStyle.filter || "") ? parseFloat(RegExp.$1) + "" : "";
				return val === "" ? 1 : val/100;
			}
			
			if(core.reg.float.test(name)) name = core.format.float; //float name
			
			if(compat){
				if(core.reg.float.test(name)) name = "float";
				name = name.replace(core.reg.Capital, "-$1").toLowerCase();//从成连字符风格转成驼峰风格
				var style = elem.ownerDocument.defaultView;
				if(!style) return null;
				if(elem = style.getComputedStyle(elem, null)) val = elem.getPropertyValue(name);
				if (name === "opacity" && val === "") val = "1";
			}else if(elem.currentStyle){
				name = name.replace(core.reg.cssName, core.format.cssName);
				if(name === "backgroundPosition") val = elem.currentStyle[name + "X"] + " " + elem.currentStyle[name + "Y"];
				else val = elem.currentStyle[name];
			}
			
			return val;
		},
		swap:function(elem, arr, fn){
			var old = {};
			for(var a in arr){
				old[a] = elem.style[a];
				elem.style[a] = arr[a];
			}
			fn.call(elem);
			for(a in arr){
				elem.style[a] = old[a];
			}
		}
	});	
	
	var str = Object.prototype.toString;
	var ownPro = Object.prototype.hasOwnProperty;
    
	core.fn.extend({		
		bind:function(type, fn){
			core.factory.y(this, core.bind, [type, fn]);
			return this;
		},
		unbind:function(type, fn){
			core.factory.y(this, core.unbind, [type, fn]);
			return this;
		},
		append:function(a){
			if(typeof a === "undefined") return this;
			if(a instanceof core && a[0]) this[0].appendChild(a[0]);
			else if(a.nodeType) this[0].appendChild(a);
			return this;
		},
		remove:function(){
			core.factory.y(this, core.remove);			
			return this;
		},
		offset:function(){
			return core.offset(this[0]);
		},
		html:function(a){
			if(typeof a !== "undefined"){
				core.factory.y(this, function(elem,a){elem.innerHTML = a;}, [a]);
				return this;
			}else if(this[0]) return this[0].innerHTML;
		}
	});
	
    core.extend({
		isFunction:function(a){
			return str.call(a) === "[object Function]";
		},
		isArray:function(a){
			return str.call(a) === "[object Array]";
		},
		isPlainObject:function(a){
			if (!a || str.call(a) !== "[object Object]" || a.nodeType || a.setInterval) return false;
            if (a.constructor && !ownPro.call(a, "constructor") && !ownPro.call(a.constructor.prototype,  "isPrototypeOf")) return false;
            var b;
            for (b in a);
			return typeof b === "undefined" || ownPro.call(a, b);
		},
		isEmptyObject: function(a) {
            for (var b in a) return false;
            return true;
        },
		isXMLDoc:function(elem) {
			return (elem = (elem ? elem.ownerDocument || elem: 0).documentElement) ? elem.nodeName !== "HTML": false;
		},
		merge:function(a, b){
			var l = a.length;
			var _l = 0;
			if(typeof b.length === "number"){
				for(var i = b.length; _l < i; _l++){
					a[l++] = b[_l];
				}
			}else{
				for(;!!b[_l];) {
					a[l++] = b[_l++];
				}
			}
			a.length = l;
			return a;
		},
		each:function(object, fn){
			var name;
			var i = 0;
			var length = object.length;
			if (typeof length === "undefined") {
				for (name in object){
                    if(typeof name === "undefined") continue;
					if (fn.call(object[name], name, object[name]) === false) break;
				} 
			} else {
				for (var value = object[0]; i < length && fn.call(value, i, value) !== false; value = object[++i]){}	
			}
				
			return object;
		},        
		bindScope:function(scope, fn){
			return function(){
				fn.apply(scope, arguments);
			}
		},
		bindEvent:function(scope, fn){
			return function(event){
				fn.call(scope, event || window.event);
			}
		},		
		bind:function(elem, type, fn){
			if(core.support.addListener){
				elem.addEventListener(type, fn, false);
			}else{
				elem.attachEvent("on" + type, fn);
			}
		},
		unbind:function(elem, type, fn){
			if(core.support.addListener){
				elem.removeEventListener(type, fn, false);
			}else{
				elem.detachEvent("on" + type, fn);
			}
		},
		remove:function(elem){
			if(elem.nodeType && elem.parentNode){
				elem.parentNode.removeChild(elem);
			}
		},		
		event:function(elem, type, fn){
			elem[type] = core.bindScope(elem, fn);
		},
		globalScript:function(txt, isUrl){
            var isUrl = typeof isUrl !== "undefined" ? isUrl : false;
			var d = document;
			var h = d.getElementsByTagName("head")[0] || d.documentElement;
			var j = d.createElement("script");	
			j.type = "text/javascript";
            if(isUrl){
                j.src = txt;
            }else{
                if(core.support.script) j.appendChild(d.createTextNode(txt));
                else j.text = txt;
            }
			h.insertBefore(j, h.firstChild);
			if(!isUrl) h.removeChild(j);
		}
	});
	
	core.extend({
		offset: function(elem){
			var _left = 0, _top = 0, frame, tRect, fRect;
			try{
				if(self != top && self != self.parent){
					var curWin = self;
					while((typeof top.window != "undefined" && curWin != top) || curWin != curWin.parent){
						curWin = curWin.parent;
					}
                    frame = curWin.frameElement;
				}else if(core("#" + WF_getToolbarContentId())[0]){
					frame = core("#" + WF_getToolbarContentId())[0];
				}
			}catch(e){}
			
			if("getBoundingClientRect" in document.documentElement){
				tRect = elem.getBoundingClientRect();
				if(typeof frame !== "undefined" && frame != null){
					 fRect = frame.getBoundingClientRect();
					 _left = tRect.left + fRect.left;
					 _top = tRect.top + fRect.top;
				}else{
					_left = tRect.left;
					 _top = tRect.top;
				}
			}else{
				var e = elem.offsetParent;
				_left = e.offsetLeft;
				_top = e.offsetTop;
				function setXY(e){
					_left += e.offsetLeft;
					_top += e.offsetTop;
					e = e.offsetParent;
				};
				while(e){setXY(e);};
				while(frame){setXY(frame);};
			}
			
			return { left:_left, top:_top };
		},
		winSize: function(){
			var iWidth = 0, iHeight = 0;
			if (typeof window.innerWidth == 'number') {
				iWidth = window.innerWidth;
				iHeight = window.innerHeight;
				try{
					if(!core.uaMatch("ie") && core(window).scrollHeight() > iHeight) iWidth -= 20;
				}catch(e){}
			} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
				iWidth = document.documentElement.clientWidth;
				iHeight = document.documentElement.clientHeight;
			} else if (document.body && (document.body.clientWidth || document.clientHeight)) {
				iWidth = document.body.clientWidth;
				iHeight = document.body.clientHeight;
			}
			
			return {width:iWidth, height:iHeight};
		}
	});

	//get childNodes
	core.fn.extend({
		child:function(filter){
			var node = this[0];
			if(node && node.nodeType) {
				var nodes = core.child(node, filter);
				var childNodes = new core.fn.init("", this.w);
				return core.merge(childNodes, nodes);
			}
		}
	});
	
	core.extend({
		child:function(elem, filter){ // filter: .className, string, string|string|...|string 
			var nodes = [];
			filter = filter && /(\.?)([\w\|]+)/.exec(filter);
			core.each(elem.childNodes, function(i, node){
				if(node.nodeType === 1 && node.nodeName !== "SCRIPT") {
					if(filter){
						if(filter[1] && node.className === filter[2]) nodes.push(node);
						else if(filter[2]){
							var tags = filter[2];
							core.each(filter[2].split("|"), function(i, tag){
								if(node.nodeName.toUpperCase() === tag.toUpperCase()) nodes.push(node);
							});
							
						}
					}else nodes.push(node);
				}
			});			
			return nodes
		}
	});
	
	//get brother node
    core.each(["next", "pre"], function(a, b){
		var c = b === "next" ? "nextSibling" : "previousSibling";
		
		core.fn[b] = function(filter){
			if(this[0] && this[0].nodeType) return core[b](this[0], filter);
		};
		
		core[b] = function(elem, filter){
			var node = elem[c], element;
			filter = filter && /(\.?)(\w+)/.exec(filter);
			while(node){
				if(node.nodeType === 1 && node.nodeName !== "SCRIPT") {
					elem = node;
					if(filter){
						if(filter[1] && elem.className === filter[2]) break;
						else if(filter[2] && elem.nodeName.toUpperCase() === filter[2].toUpperCase()) break;
					}else break;
				}
				node = node[c];
			}
			return elem
		}
	});
	
	//scroll method
	core.each(["Top", "Left", "Width", "Height"],function(a, b){
		var c = "scroll" + b;
		core.fn[c] = function(a){
			var d = this[0];
			if(typeof a !== "undefined" && /[Top|Left]/.test(b) && parseInt(a) + "" !== "NaN"){
				d[c] = parseInt(a);
				return this;
			}
			if( !d || (d.nodeType && d.nodeName === "BODY") || ("scrollTo" in d && d.document)){
				var sc = core.support.CSS1Compat ? document.documentElement : document.body;
				if(sc && document.body)	return Math.max(sc[c], document.body[c]);
				else if(document.body) return document.body[c];
				else if(sc) return sc[c];
				else return 0;
			}else if(d && d.nodeType && d.nodeType === 1){
				return d[c];
			}
		};
	});
    
	//event method
	core.each("blur focus focusin focusout load resize scroll unload click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup error".split(" "),function(a, b){
		core.fn[b] = function(fn){
			core.factory.y(this, core.event, ["on" + b, fn]);
			return this;
		}
	});
    
	//ajax method
    core.fn.extend({
        loader:function(url, type){
            var target = this;
            var type = typeof type !== "undefined" ? type.toLowerCase() : "html";
            
            var xhr = core.ajax({
                url:url,
                success:function(xml){
                    if(type === "script") core.globalScript(xml.responseText);
                    else if(type === "html"){
                        var h = document.getElementsByTagName("head")[0] || document.documentElement;
                        var box = core("<div>").html(xml.responseText);
                        var nodes = box[0].childNodes;
                        
                        if(nodes.length > 0 ) while(nodes.length){
                            var elem = nodes[0];
                            if(elem.nodeType === 1){
                                if(elem.tagName !== "SCRIPT") target.append(elem);
                                else if(elem.tagName === "SCRIPT") {
                                    if(!!elem.src) h.insertBefore(elem, h.firstChild);
                                    if(!!elem.text) {
                                        core.globalScript(elem.text);
                                        wapi(elem).remove();
                                    }
                                }
                            }else if(elem.nodeType === 3) target.append(elem);
                        }
                    }
                }
            })
        }
    });
    
	core.extend({
		ajax:function(params){            
            return new core.ajaxCreate(params);
        },
        ajaxCreate:function(params){
            var xmlhttp = this.create();
            var data = params.data || null;
            var method = params.method || 'GET';
            var url = params.url;
            var async = params.async || true;
            var func = params.success || null;
            var cache = params.cache || false;
            var t = '';
            
            if(data != null){
                for(var key in data){
                    t += '&' + key + '=' + encodeURIComponent(data[key]);
                }
                if(t != '') t = t.substring(1);
                if(t != '' && !cache) t += '&' + new Date().getTime();
            }
            
            method = method.toUpperCase();
            
            if(xmlhttp){
                try{
                    if(method == 'GET'){
                        if(t != '') url += '?' + t;
                        data = null;
                    }
                    xmlhttp.open(method, url, async);
                    if(!cache) xmlhttp.setRequestHeader('cache-control', 'no-cache');
                    if(method == 'POST'){
                        xmlhttp.setRequestHeader('content-type', 'application/x-www-form-urlencoded; charset=utf-8');
                        data = t;
                    }
                    xmlhttp.onreadystatechange = function(){
                        if(xmlhttp.readyState == 4){
                            if(xmlhttp.status == 200){
                                if(func != null) func(xmlhttp);
                                xmlhttp = null;
                            }
                        }
                    };
                    xmlhttp.send(data);
                }catch(e){}
            }
        }
	});
    
    core.ajaxCreate.prototype = {
        create:function() {
            var xhr;
            var fns = [
                function () { return new XMLHttpRequest(); },
                function () { return new ActiveXObject('Msxml2.XMLHTTP'); },	  
                function () { return new ActiveXObject('Microsoft.XMLHTTP'); },
            ];
            for (var i = 0,n=fns.length; i < n; i++) {
                try {
                    xhr = fns[i]();
                    this.create = fns[i];
                    break;
                }catch(e){}
            }
            
            return xhr
        }
    };
	
	/**
	* dataBase: {uid:{column:value}}
	*
	*/
	var dataIndex = 0;
	var dataBase = {};
	var idIndex = "wishfiid";
	var data = {
		matchData:function(filter, array){
			var d = {};
			
			core.each(array, function(i, v){
				if(i == filter) {
					d = v;
					return false;
				}
			});
			
			return d;
		},
		read:function(uid, column){
			if(typeof column === "undefined") return this.matchData(uid, dataBase);
			else return this.matchData(column, this.matchData(uid, dataBase));
		},
		write:function(uid, column, value){
			if(typeof uid !== "object"){
				var old = this.matchData(column, this.matchData(uid, dataBase));
				if(core.isEmptyObject(old)) this.matchData(uid, dataBase)[column] = value;
				else core.extend(old, value);
			}else{
				uid = core(uid);
				uid.attr(idIndex, ++dataIndex);
				dataBase[uid.attr(idIndex)] = {};
				dataBase[uid.attr(idIndex)][column] = value;
			}
		}		
	};
	
	core.fn.extend({
		data:function(column, value){
			if(!this[0]) return this;
			if(typeof value !== "undefined"){
				if(!!this.attr(idIndex)) data.write(this.attr(idIndex), column, value);
				else core.factory.y(this, data.write, [column, value]);
				
				return this;
			}else{
				if(!!this.attr(idIndex)) return data.read(this.attr(idIndex), column);
				else return null;
			}
		}
	});
	
	//公共动画方法扩展
	core.fn.extend({
		animate:function(attr, duration, callback){//{width:"+100px", height:"=100px"}, speed, callback
			if(typeof attr !== "undefined" && core.isPlainObject(attr)){
				for(p in attr){
					var n = p.replace(core.reg.cssName, core.format.cssName);
					if(p !== n) {
						attr[n] = attr[p];
						delete attr[p];
						p = n;
					}					
				}
				this.each(function(){
					if(this.nodeType === 1){
						var node = this;
						var elem = core(this);
						
						elem.data("fx", {complete:callback||function(){}});						
						core.each(attr, function(attr, val){
							var c = {};
							var tick, change, step, unit, start, end;
							var v = /^([+|\-|=])?(\d+\.?\d*)(.*)$/.exec(val);
							
							var fx = elem.data("fx");
							if(!fx || !fx[attr]) {
								c[attr] = new core.fx(node, attr);
								elem.data("fx", c);
							}
							
							if(v && v[2]){								
								unit = v[3] || "px";								
								start = parseFloat(core.curCss(node, attr)) || 0;
								
								switch(true)
								{
									case (/[\-|+]/.test(v[1])):
										tick = v[1] == "-" ? -1 : 1;
										change = tick * v[2];
										end = start + change;
										break;									
									case (v[1] == "="):
										end = v[2];
										tick = start > end ? -1 : 1;
										change = tick * Math.abs(start - end);
										break;
								}
								
								end = Math.ceil(end * 100)/100;
								step = core.linear(change, duration);
                                
								if(c[attr]){
									c = c[attr];
									if((attr === "width" || attr === "height") && node.style){
										core.extend(c.options, {
											overflow: core.css(node, "overflow"),
											display: core.css(node, "display")
										});
										node.style.overflow = "hidden";
									}
									
									if(attr === "opacity" && c.opt.elem.css("filter") == "") c.opt.elem.css("opacity", 1);
									
									c.custom(start, end, step, tick, unit, change);
								}
								else elem.data("fx")[attr].custom(start, end, step, tick, unit);
							}
						})
					}
				})
			}
		},
		show:function(speed){
			if(this.css("display") === "none" || this.css(elem, "visibility") === "hidden"){
				core.factory.y(this, core.show, [true, speed]);
			}
			return this;
		},
		hidden:function(speed){
			if(this.css("display") !== "none" || this.css(elem, "visibility") !== "hidden"){
				core.factory.y(this, core.show, [false, speed]);
			}
			return this;
		},
		toggle:function(type){
			core.factory.y(this, core.toggle, [type].concat([].slice.call(arguments, 1)));
			
			return this;
		}
	});
	//动画控制
	core.extend({
		fx:function(elem, attr){
			this.opt = {
				elem:core(elem),
				attr:attr
			};
			if(attr === "opacity") this.opt.unit = " ";
		},
		clearTimer:function(timer){
			clearInterval(timer);
		},
		linear:function(val, duration){
			if(duration == 0) return val;
			else return parseFloat(val / (duration/10));
		},
		speed:{
			fast:300,
			slow:600
		},
		show:function(elem, isShow, speed){
			var d,v,_d,_v;
			if(isShow){
				d = "block", _d = "none", v = "visible", _v = "hidden";				
			}else{
				d = "none", v = "hidden", _d = "block", _v = "visible";
			}
			if(elem && elem.nodeType === 1){
				if(core.css(elem, "display") === _d){
					core.css(elem, "display", d);
				}else if(core.css(elem, "visibility") === _v){
					core.css(elem, "visibility", v)
				}
				if(typeof speed !== "undefined" && /^fast|slow$/i.test(speed)){
					if(isShow){
						core(elem).css("opacity","0").animate({opacity:"=1"}, core.speed[speed]);						
					} else {
						core(elem).css({opacity:1, display:"block"}).animate({opacity:"=0"}, core.speed[speed], function(){core.css(elem, "display", "none")});
					}
				}
			}
		},
		toggle:function(elem, type){
			var fns = [].slice.call(arguments, 2);
			var backup = fns.concat();
			core.bind(elem, type, function(e){
			  if (!fns.length) { fns = backup.concat()}
			  fns[0].call(elem, e);
			  fns.shift();
			});
		}
	});
	core.fx.prototype = {
		custom:function(start, end, step, tick, unit, callback, change){
			var isFilter = this.opt.attr === "opacity" && !core.support.filter;
			core.extend(this.opt, {
				start:start,
				end:end,
				step:step,
				now:0,
				tick:tick,
				change:change,
				unit:this.opt.unit || unit
			});
			this.run();
		},
		run:function(){
			var opt = this.opt;
			var v = 0;
			var count = 0;
			var begin;
			opt.pos = Math.ceil(opt.step * 100) / 100;
			opt.count = true;
			if(opt.t) clearInterval(opt.t);
			
			var t = new Date;
			
			function g(){
				if(opt.tick * parseFloat(opt.elem.css(opt.attr)) >= opt.tick * (opt.end - opt.step)){
					clearInterval(opt.t);
					
					//alert(new Date - t);
					
					if(opt.attr === "opacity" && !core.support.filter){						
						opt.end >= 1 ? opt.elem[0].style.filter = "" : opt.elem.css(opt.attr, opt.end);
					}else{
						opt.elem.css(opt.attr, opt.end);
					}
					
					opt.elem.data("fx").complete();
					opt.elem.data("fx", {complete:function(){}});
					
					return;
				}			
				
				v += opt.step;
				if(opt.attr === "opacity"){
					if(Math.abs(parseInt(v * 100)) > Math.abs(opt.now * 100)){
						opt.count = false;
						opt.pos = Math.ceil((Math.ceil(v * 100)/100 - opt.now) * 100)/100;
						opt.now = Math.ceil(v * 100)/100;
						update();
					}
				} else{
					if(Math.abs(parseInt(v)) > Math.abs(opt.now)){
						opt.count = false;
						opt.pos = parseInt(v) - opt.now;
						opt.now = parseInt(v);
						update();
					}
				}
			}			
			function update(){
				var cur = parseFloat(opt.elem.css(opt.attr)) + "" !== "NaN" ? parseFloat(opt.elem.css(opt.attr)) : 0;
				cur = parseFloat(cur) + parseFloat(opt.pos) + opt.unit;
				opt.elem.css(opt.attr, cur);				
			}
			
			opt.t = setInterval(g, 8);
			opt.elem.data("fx", {timer:opt.t}); 
		}
	};	
	
	//IMPORTANT NOTE: 
	//==========================================for wishfi-min.js, start delete from here
	//hover,drag接口方法
	core.fn.extend({
		hover:function(pos, content, offsetStyle){
			core.factory.y(this, function(elem, pos, content, offsetStyle){
				elem.hover = new core.ui.hover(elem, pos, content, offsetStyle);
			}, [pos, content || "", offsetStyle || 0]);
			
			return this;
		},
		drag:function(target){
			target = target instanceof core ? target[0] : target;
			core.factory.y(this, function(elem, target){
				elem.drag = new core.ui.drag(elem, target);
			}, [target]);
			
			return this;
		}
	});	
	//UI方法集合
	core.ui = {
		hover:function(target, pos, content, offsetStyle){
			this.options = {
				target:target,
				elem:core("<div>").attr("style", "position:fixed; width:auto; height:auto; display:none;  z-index:214748364;"),
				pos:pos || "bottom",			
                offsetStyle:offsetStyle
			};
            if(typeof content === "string") this.options.elem.html(content);
            else if(typeof content === "object") this.options.elem.append(content);
			core("body").append(this.options.elem[0]);
			if(core.uaMatch("ie6") || (!core.support.CSS1Compat && core.uaMatch("ie"))){
				this.options.elem.css("position", "absolute");
			}
			this.listener();
            
            var elem = this.options.elem;
            var show = core.bindScope(this, this.show);
            var hidden = core.bindScope(this, this.hidden);
            var toggle = core.bindScope(this, this.toggle);
            
            return {                
                element:elem,
                show:show,
                hidden:hidden,
                toggle:toggle
            }
		},
		drag:function(elem, target){
			this.elem = elem;
			this.target = target ? target : elem;			
			this.mouseMove = core.bindEvent(this, this.move);
			this.mouseUp = core.bindEvent(this, this.stop);
			this.mouseRange = core.bindScope(this, this.range);
			core(this.elem).bind( "mousedown",  core.bindEvent(this, this.start));
			
			if(typeof this.elem.fx !== "undefined") this.elem.fx.dragged = false;
			else this.elem.fx = {
				dragged:false
			};
		}
	};
	//UI-HOVER 方法原型
	core.ui.hover.prototype = {
		setPosition:function(){
			var fn,left,top;
			switch(this.options.pos)
			{
				case "top":
				fn = function(offset){
					left = offset.left;
					top = offset.top - this.options.elem[0].offsetHeight;
					return {left:left, top:top}
				};
				break;
				case "bottom":
				fn = function(offset){
					left = offset.left;
					top = offset.top + this.options.target.offsetHeight;
					return {left:left, top:top}
				};
				break;
				case "left":
				fn = function(offset){
					left = offset.left - this.options.elem[0].offsetWidth;
					return {left:left, top:offset.top}
				};
				break;
				case "right":
				fn =function(offset){
					left = offset.left + this.options.target.offsetWidth;
					return {left:left, top:offset.top}
				};
				break;
			}

			function setVal(){
				var _fn = fn.call(this, core(this.options.target).offset());
                var elem = this.options.elem;
                var offsetStyle = this.options.offsetStyle;
				elem.css("left", _fn.left + "px");
				elem.css("top", _fn.top + "px");
                
                var old = elem.css("left");
                if(parseFloat(offsetStyle) + "" !== "NaN"){                    
                    elem.css("left", -1 * parseFloat(offsetStyle) + parseFloat(old) + "px");
                }else {                
                    core.each(offsetStyle, function(name, val){
                        if(/left|top/i.test(name)){
                            old = elem.css(name);
                            var val = /([+|\-])?(\d*)(auto)?(px|%)?/i.exec(val);
                            var unit;
                            if(val && val[2]){
                                tick = val[1] && val[1] === "-" ? -1 : 1;
                                val = tick * parseFloat(val[2]);
                                if(name === "opacity") unit = "";
                                else unit = val[4] || "px";
                                if(unit === "%") val = "";
                                else old = parseFloat(old) + "" !== "NaN" ? parseFloat(old) : "";
                            }
                            else val = "";
                            
                            elem.css(name, (old + val) + unit);
                        }
                    })
                }
                
				if(core.uaMatch("ie6")  || (!core.support.CSS1Compat && core.uaMatch("ie"))) {
					this.options.elem.css("top", this.options.elem[0].offsetTop + core("body").scrollTop() + "px");
				}
			}
            
			this.setPosition = core.bindScope(this, setVal);//重置函数提高二次调用效率
			this.setPosition();
			return this.setPosition;
		},
		listener:function(){//监听目标位置变化
			var e = this;
			function listener(){
				if(core.css(e.options.elem[0], "display") != "none") e.setPosition();
				setTimeout(listener, 32);
			};
			listener();
		},
		show:function(a){
			if(this.options.elem.css("display") === "none" || this.options.elem.css(elem, "visibility") === "hidden"){
				this.options.elem.show(a);
			}
			return this.options.elem;
		},
		hidden:function(a){
			if(this.options.elem.css("display") !== "none" || this.options.elem.css(elem, "visibility") !== "hidden"){
				this.options.elem.hidden(a);
			}
			return this.options.elem;
		},
        toggle:function(a){
            this.options.elem.css("display") === "none" ? this.options.elem.show(a) : this.options.elem.hidden(a);
            return this.options.elem;
        }
	};
	//UI-DRAG 方法原型
	core.ui.drag.prototype = {
		start: function(e) {
			this.elem.fx.dragged = true; //判断是否被拖曳
			this.x = e.clientX - this.target.offsetLeft;
			this.y = e.clientY - this.target.offsetTop;
			core(document).bind("mousemove", this.mouseMove);
			core(document).bind("mouseup", this.mouseUp);
		},
		move: function(e){
			window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
			core.css(this.target, "left", e.clientX - this.x + "px");
			core.css(this.target, "top", e.clientY - this.y + "px");
			this.mouseRange(this.x, this.y, e.clientX, e.clientY);
		},
		stop: function() {
			core(document).unbind("mousemove", this.mouseMove);
			core(document).unbind("mouseup", this.mouseUp);
		},
		range: function(x0, y0, x1, y1){
			var size = core.winSize();			
			var target = core(this.target);
			var scY = target.css("position") === "absolute" ? core("body").scrollTop() : 0;
			var offsetX = x1 - x0;
			var offsetY = y1 - y0;
			if (offsetX  <= 0) target.css("left", 0);
			if (offsetX >= size.width - this.target.offsetWidth) target.css("left",  size.width - this.target.offsetWidth - 3 + "px");
			if (offsetY <= scY)	target.css("top", scY + "px");
			if (offsetY >= size.height + scY - this.target.offsetHeight) target.css("top", size.height + scY - this.target.offsetHeight - 3 + "px");
		}
	};
	//==========================================for wishfi-min.js, end delete from here
	
	A.iwapi = core;
})(window);
