function Tagtoo(){
	// All things start here!
}
var tagtoo_jQuery;
Tagtoo.weburl = document.location.href;
// the old version included is jquery 1.3.2, to use the delay() function, I upgrade the version to 1.5
// if the current page is in Yam domain, don't include jQuery again!
if(Tagtoo.weburl.indexOf("http://blog.yam.com/") == -1){
    /*! jQuery v1.7 jquery.com | jquery.org/license */
(function(a,b){function cA(a){return f.isWindow(a)?a:a.nodeType===9?a.defaultView||a.parentWindow:!1}function cx(a){if(!cm[a]){var b=c.body,d=f("<"+a+">").appendTo(b),e=d.css("display");d.remove();if(e==="none"||e===""){cn||(cn=c.createElement("iframe"),cn.frameBorder=cn.width=cn.height=0),b.appendChild(cn);if(!co||!cn.createElement)co=(cn.contentWindow||cn.contentDocument).document,co.write((c.compatMode==="CSS1Compat"?"<!doctype html>":"")+"<html><body>"),co.close();d=co.createElement(a),co.body.appendChild(d),e=f.css(d,"display"),b.removeChild(cn)}cm[a]=e}return cm[a]}function cw(a,b){var c={};f.each(cs.concat.apply([],cs.slice(0,b)),function(){c[this]=a});return c}function cv(){ct=b}function cu(){setTimeout(cv,0);return ct=f.now()}function cl(){try{return new a.ActiveXObject("Microsoft.XMLHTTP")}catch(b){}}function ck(){try{return new a.XMLHttpRequest}catch(b){}}function ce(a,c){a.dataFilter&&(c=a.dataFilter(c,a.dataType));var d=a.dataTypes,e={},g,h,i=d.length,j,k=d[0],l,m,n,o,p;for(g=1;g<i;g++){if(g===1)for(h in a.converters)typeof h=="string"&&(e[h.toLowerCase()]=a.converters[h]);l=k,k=d[g];if(k==="*")k=l;else if(l!=="*"&&l!==k){m=l+" "+k,n=e[m]||e["* "+k];if(!n){p=b;for(o in e){j=o.split(" ");if(j[0]===l||j[0]==="*"){p=e[j[1]+" "+k];if(p){o=e[o],o===!0?n=p:p===!0&&(n=o);break}}}}!n&&!p&&f.error("No conversion from "+m.replace(" "," to ")),n!==!0&&(c=n?n(c):p(o(c)))}}return c}function cd(a,c,d){var e=a.contents,f=a.dataTypes,g=a.responseFields,h,i,j,k;for(i in g)i in d&&(c[g[i]]=d[i]);while(f[0]==="*")f.shift(),h===b&&(h=a.mimeType||c.getResponseHeader("content-type"));if(h)for(i in e)if(e[i]&&e[i].test(h)){f.unshift(i);break}if(f[0]in d)j=f[0];else{for(i in d){if(!f[0]||a.converters[i+" "+f[0]]){j=i;break}k||(k=i)}j=j||k}if(j){j!==f[0]&&f.unshift(j);return d[j]}}function cc(a,b,c,d){if(f.isArray(b))f.each(b,function(b,e){c||bG.test(a)?d(a,e):cc(a+"["+(typeof e=="object"||f.isArray(e)?b:"")+"]",e,c,d)});else if(!c&&b!=null&&typeof b=="object")for(var e in b)cc(a+"["+e+"]",b[e],c,d);else d(a,b)}function cb(a,c){var d,e,g=f.ajaxSettings.flatOptions||{};for(d in c)c[d]!==b&&((g[d]?a:e||(e={}))[d]=c[d]);e&&f.extend(!0,a,e)}function ca(a,c,d,e,f,g){f=f||c.dataTypes[0],g=g||{},g[f]=!0;var h=a[f],i=0,j=h?h.length:0,k=a===bV,l;for(;i<j&&(k||!l);i++)l=h[i](c,d,e),typeof l=="string"&&(!k||g[l]?l=b:(c.dataTypes.unshift(l),l=ca(a,c,d,e,l,g)));(k||!l)&&!g["*"]&&(l=ca(a,c,d,e,"*",g));return l}function b_(a){return function(b,c){typeof b!="string"&&(c=b,b="*");if(f.isFunction(c)){var d=b.toLowerCase().split(bR),e=0,g=d.length,h,i,j;for(;e<g;e++)h=d[e],j=/^\+/.test(h),j&&(h=h.substr(1)||"*"),i=a[h]=a[h]||[],i[j?"unshift":"push"](c)}}}function bE(a,b,c){var d=b==="width"?a.offsetWidth:a.offsetHeight,e=b==="width"?bz:bA;if(d>0){c!=="border"&&f.each(e,function(){c||(d-=parseFloat(f.css(a,"padding"+this))||0),c==="margin"?d+=parseFloat(f.css(a,c+this))||0:d-=parseFloat(f.css(a,"border"+this+"Width"))||0});return d+"px"}d=bB(a,b,b);if(d<0||d==null)d=a.style[b]||0;d=parseFloat(d)||0,c&&f.each(e,function(){d+=parseFloat(f.css(a,"padding"+this))||0,c!=="padding"&&(d+=parseFloat(f.css(a,"border"+this+"Width"))||0),c==="margin"&&(d+=parseFloat(f.css(a,c+this))||0)});return d+"px"}function br(a,b){b.src?f.ajax({url:b.src,async:!1,dataType:"script"}):f.globalEval((b.text||b.textContent||b.innerHTML||"").replace(bi,"/*$0*/")),b.parentNode&&b.parentNode.removeChild(b)}function bq(a){var b=(a.nodeName||"").toLowerCase();b==="input"?bp(a):b!=="script"&&typeof a.getElementsByTagName!="undefined"&&f.grep(a.getElementsByTagName("input"),bp)}function bp(a){if(a.type==="checkbox"||a.type==="radio")a.defaultChecked=a.checked}function bo(a){return typeof a.getElementsByTagName!="undefined"?a.getElementsByTagName("*"):typeof a.querySelectorAll!="undefined"?a.querySelectorAll("*"):[]}function bn(a,b){var c;if(b.nodeType===1){b.clearAttributes&&b.clearAttributes(),b.mergeAttributes&&b.mergeAttributes(a),c=b.nodeName.toLowerCase();if(c==="object")b.outerHTML=a.outerHTML;else if(c!=="input"||a.type!=="checkbox"&&a.type!=="radio"){if(c==="option")b.selected=a.defaultSelected;else if(c==="input"||c==="textarea")b.defaultValue=a.defaultValue}else a.checked&&(b.defaultChecked=b.checked=a.checked),b.value!==a.value&&(b.value=a.value);b.removeAttribute(f.expando)}}function bm(a,b){if(b.nodeType===1&&!!f.hasData(a)){var c,d,e,g=f._data(a),h=f._data(b,g),i=g.events;if(i){delete h.handle,h.events={};for(c in i)for(d=0,e=i[c].length;d<e;d++)f.event.add(b,c+(i[c][d].namespace?".":"")+i[c][d].namespace,i[c][d],i[c][d].data)}h.data&&(h.data=f.extend({},h.data))}}function bl(a,b){return f.nodeName(a,"table")?a.getElementsByTagName("tbody")[0]||a.appendChild(a.ownerDocument.createElement("tbody")):a}function X(a){var b=Y.split(" "),c=a.createDocumentFragment();if(c.createElement)while(b.length)c.createElement(b.pop());return c}function W(a,b,c){b=b||0;if(f.isFunction(b))return f.grep(a,function(a,d){var e=!!b.call(a,d,a);return e===c});if(b.nodeType)return f.grep(a,function(a,d){return a===b===c});if(typeof b=="string"){var d=f.grep(a,function(a){return a.nodeType===1});if(R.test(b))return f.filter(b,d,!c);b=f.filter(b,d)}return f.grep(a,function(a,d){return f.inArray(a,b)>=0===c})}function V(a){return!a||!a.parentNode||a.parentNode.nodeType===11}function N(){return!0}function M(){return!1}function n(a,b,c){var d=b+"defer",e=b+"queue",g=b+"mark",h=f._data(a,d);h&&(c==="queue"||!f._data(a,e))&&(c==="mark"||!f._data(a,g))&&setTimeout(function(){!f._data(a,e)&&!f._data(a,g)&&(f.removeData(a,d,!0),h.fire())},0)}function m(a){for(var b in a){if(b==="data"&&f.isEmptyObject(a[b]))continue;if(b!=="toJSON")return!1}return!0}function l(a,c,d){if(d===b&&a.nodeType===1){var e="data-"+c.replace(k,"-$1").toLowerCase();d=a.getAttribute(e);if(typeof d=="string"){try{d=d==="true"?!0:d==="false"?!1:d==="null"?null:f.isNumeric(d)?parseFloat(d):j.test(d)?f.parseJSON(d):d}catch(g){}f.data(a,c,d)}else d=b}return d}function h(a){var b=g[a]={},c,d;a=a.split(/\s+/);for(c=0,d=a.length;c<d;c++)b[a[c]]=!0;return b}var c=a.document,d=a.navigator,e=a.location,f=function(){function K(){if(!e.isReady){try{c.documentElement.doScroll("left")}catch(a){setTimeout(K,1);return}e.ready()}}var e=function(a,b){return new e.fn.init(a,b,h)},f=a.jQuery,g=a.$,h,i=/^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/,j=/\S/,k=/^\s+/,l=/\s+$/,m=/\d/,n=/^<(\w+)\s*\/?>(?:<\/\1>)?$/,o=/^[\],:{}\s]*$/,p=/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,q=/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,r=/(?:^|:|,)(?:\s*\[)+/g,s=/(webkit)[ \/]([\w.]+)/,t=/(opera)(?:.*version)?[ \/]([\w.]+)/,u=/(msie) ([\w.]+)/,v=/(mozilla)(?:.*? rv:([\w.]+))?/,w=/-([a-z]|[0-9])/ig,x=/^-ms-/,y=function(a,b){return(b+"").toUpperCase()},z=d.userAgent,A,B,C,D=Object.prototype.toString,E=Object.prototype.hasOwnProperty,F=Array.prototype.push,G=Array.prototype.slice,H=String.prototype.trim,I=Array.prototype.indexOf,J={};e.fn=e.prototype={constructor:e,init:function(a,d,f){var g,h,j,k;if(!a)return this;if(a.nodeType){this.context=this[0]=a,this.length=1;return this}if(a==="body"&&!d&&c.body){this.context=c,this[0]=c.body,this.selector=a,this.length=1;return this}if(typeof a=="string"){a.charAt(0)!=="<"||a.charAt(a.length-1)!==">"||a.length<3?g=i.exec(a):g=[null,a,null];if(g&&(g[1]||!d)){if(g[1]){d=d instanceof e?d[0]:d,k=d?d.ownerDocument||d:c,j=n.exec(a),j?e.isPlainObject(d)?(a=[c.createElement(j[1])],e.fn.attr.call(a,d,!0)):a=[k.createElement(j[1])]:(j=e.buildFragment([g[1]],[k]),a=(j.cacheable?e.clone(j.fragment):j.fragment).childNodes);return e.merge(this,a)}h=c.getElementById(g[2]);if(h&&h.parentNode){if(h.id!==g[2])return f.find(a);this.length=1,this[0]=h}this.context=c,this.selector=a;return this}return!d||d.jquery?(d||f).find(a):this.constructor(d).find(a)}if(e.isFunction(a))return f.ready(a);a.selector!==b&&(this.selector=a.selector,this.context=a.context);return e.makeArray(a,this)},selector:"",jquery:"1.7",length:0,size:function(){return this.length},toArray:function(){return G.call(this,0)},get:function(a){return a==null?this.toArray():a<0?this[this.length+a]:this[a]},pushStack:function(a,b,c){var d=this.constructor();e.isArray(a)?F.apply(d,a):e.merge(d,a),d.prevObject=this,d.context=this.context,b==="find"?d.selector=this.selector+(this.selector?" ":"")+c:b&&(d.selector=this.selector+"."+b+"("+c+")");return d},each:function(a,b){return e.each(this,a,b)},ready:function(a){e.bindReady(),B.add(a);return this},eq:function(a){return a===-1?this.slice(a):this.slice(a,+a+1)},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},slice:function(){return this.pushStack(G.apply(this,arguments),"slice",G.call(arguments).join(","))},map:function(a){return this.pushStack(e.map(this,function(b,c){return a.call(b,c,b)}))},end:function(){return this.prevObject||this.constructor(null)},push:F,sort:[].sort,splice:[].splice},e.fn.init.prototype=e.fn,e.extend=e.fn.extend=function(){var a,c,d,f,g,h,i=arguments[0]||{},j=1,k=arguments.length,l=!1;typeof i=="boolean"&&(l=i,i=arguments[1]||{},j=2),typeof i!="object"&&!e.isFunction(i)&&(i={}),k===j&&(i=this,--j);for(;j<k;j++)if((a=arguments[j])!=null)for(c in a){d=i[c],f=a[c];if(i===f)continue;l&&f&&(e.isPlainObject(f)||(g=e.isArray(f)))?(g?(g=!1,h=d&&e.isArray(d)?d:[]):h=d&&e.isPlainObject(d)?d:{},i[c]=e.extend(l,h,f)):f!==b&&(i[c]=f)}return i},e.extend({noConflict:function(b){a.$===e&&(a.$=g),b&&a.jQuery===e&&(a.jQuery=f);return e},isReady:!1,readyWait:1,holdReady:function(a){a?e.readyWait++:e.ready(!0)},ready:function(a){if(a===!0&&!--e.readyWait||a!==!0&&!e.isReady){if(!c.body)return setTimeout(e.ready,1);e.isReady=!0;if(a!==!0&&--e.readyWait>0)return;B.fireWith(c,[e]),e.fn.trigger&&e(c).trigger("ready").unbind("ready")}},bindReady:function(){if(!B){B=e.Callbacks("once memory");if(c.readyState==="complete")return setTimeout(e.ready,1);if(c.addEventListener)c.addEventListener("DOMContentLoaded",C,!1),a.addEventListener("load",e.ready,!1);else if(c.attachEvent){c.attachEvent("onreadystatechange",C),a.attachEvent("onload",e.ready);var b=!1;try{b=a.frameElement==null}catch(d){}c.documentElement.doScroll&&b&&K()}}},isFunction:function(a){return e.type(a)==="function"},isArray:Array.isArray||function(a){return e.type(a)==="array"},isWindow:function(a){return a&&typeof a=="object"&&"setInterval"in a},isNumeric:function(a){return a!=null&&m.test(a)&&!isNaN(a)},type:function(a){return a==null?String(a):J[D.call(a)]||"object"},isPlainObject:function(a){if(!a||e.type(a)!=="object"||a.nodeType||e.isWindow(a))return!1;try{if(a.constructor&&!E.call(a,"constructor")&&!E.call(a.constructor.prototype,"isPrototypeOf"))return!1}catch(c){return!1}var d;for(d in a);return d===b||E.call(a,d)},isEmptyObject:function(a){for(var b in a)return!1;return!0},error:function(a){throw a},parseJSON:function(b){if(typeof b!="string"||!b)return null;b=e.trim(b);if(a.JSON&&a.JSON.parse)return a.JSON.parse(b);if(o.test(b.replace(p,"@").replace(q,"]").replace(r,"")))return(new Function("return "+b))();e.error("Invalid JSON: "+b)},parseXML:function(c){var d,f;try{a.DOMParser?(f=new DOMParser,d=f.parseFromString(c,"text/xml")):(d=new ActiveXObject("Microsoft.XMLDOM"),d.async="false",d.loadXML(c))}catch(g){d=b}(!d||!d.documentElement||d.getElementsByTagName("parsererror").length)&&e.error("Invalid XML: "+c);return d},noop:function(){},globalEval:function(b){b&&j.test(b)&&(a.execScript||function(b){a.eval.call(a,b)})(b)},camelCase:function(a){return a.replace(x,"ms-").replace(w,y)},nodeName:function(a,b){return a.nodeName&&a.nodeName.toUpperCase()===b.toUpperCase()},each:function(a,c,d){var f,g=0,h=a.length,i=h===b||e.isFunction(a);if(d){if(i){for(f in a)if(c.apply(a[f],d)===!1)break}else for(;g<h;)if(c.apply(a[g++],d)===!1)break}else if(i){for(f in a)if(c.call(a[f],f,a[f])===!1)break}else for(;g<h;)if(c.call(a[g],g,a[g++])===!1)break;return a},trim:H?function(a){return a==null?"":H.call(a)}:function(a){return a==null?"":(a+"").replace(k,"").replace(l,"")},makeArray:function(a,b){var c=b||[];if(a!=null){var d=e.type(a);a.length==null||d==="string"||d==="function"||d==="regexp"||e.isWindow(a)?F.call(c,a):e.merge(c,a)}return c},inArray:function(a,b,c){var d;if(b){if(I)return I.call(b,a,c);d=b.length,c=c?c<0?Math.max(0,d+c):c:0;for(;c<d;c++)if(c in b&&b[c]===a)return c}return-1},merge:function(a,c){var d=a.length,e=0;if(typeof c.length=="number")for(var f=c.length;e<f;e++)a[d++]=c[e];else while(c[e]!==b)a[d++]=c[e++];a.length=d;return a},grep:function(a,b,c){var d=[],e;c=!!c;for(var f=0,g=a.length;f<g;f++)e=!!b(a[f],f),c!==e&&d.push(a[f]);return d},map:function(a,c,d){var f,g,h=[],i=0,j=a.length,k=a instanceof e||j!==b&&typeof j=="number"&&(j>0&&a[0]&&a[j-1]||j===0||e.isArray(a));if(k)for(;i<j;i++)f=c(a[i],i,d),f!=null&&(h[h.length]=f);else for(g in a)f=c(a[g],g,d),f!=null&&(h[h.length]=f);return h.concat.apply([],h)},guid:1,proxy:function(a,c){if(typeof c=="string"){var d=a[c];c=a,a=d}if(!e.isFunction(a))return b;var f=G.call(arguments,2),g=function(){return a.apply(c,f.concat(G.call(arguments)))};g.guid=a.guid=a.guid||g.guid||e.guid++;return g},access:function(a,c,d,f,g,h){var i=a.length;if(typeof c=="object"){for(var j in c)e.access(a,j,c[j],f,g,d);return a}if(d!==b){f=!h&&f&&e.isFunction(d);for(var k=0;k<i;k++)g(a[k],c,f?d.call(a[k],k,g(a[k],c)):d,h);return a}return i?g(a[0],c):b},now:function(){return(new Date).getTime()},uaMatch:function(a){a=a.toLowerCase();var b=s.exec(a)||t.exec(a)||u.exec(a)||a.indexOf("compatible")<0&&v.exec(a)||[];return{browser:b[1]||"",version:b[2]||"0"}},sub:function(){function a(b,c){return new a.fn.init(b,c)}e.extend(!0,a,this),a.superclass=this,a.fn=a.prototype=this(),a.fn.constructor=a,a.sub=this.sub,a.fn.init=function(d,f){f&&f instanceof e&&!(f instanceof a)&&(f=a(f));return e.fn.init.call(this,d,f,b)},a.fn.init.prototype=a.fn;var b=a(c);return a},browser:{}}),e.each("Boolean Number String Function Array Date RegExp Object".split(" "),function(a,b){J["[object "+b+"]"]=b.toLowerCase()}),A=e.uaMatch(z),A.browser&&(e.browser[A.browser]=!0,e.browser.version=A.version),e.browser.webkit&&(e.browser.safari=!0),j.test(" ")&&(k=/^[\s\xA0]+/,l=/[\s\xA0]+$/),h=e(c),c.addEventListener?C=function(){c.removeEventListener("DOMContentLoaded",C,!1),e.ready()}:c.attachEvent&&(C=function(){c.readyState==="complete"&&(c.detachEvent("onreadystatechange",C),e.ready())}),typeof define=="function"&&define.amd&&define.amd.jQuery&&define("jquery",[],function(){return e});return e}(),g={};f.Callbacks=function(a){a=a?g[a]||h(a):{};var c=[],d=[],e,i,j,k,l,m=function(b){var d,e,g,h,i;for(d=0,e=b.length;d<e;d++)g=b[d],h=f.type(g),h==="array"?m(g):h==="function"&&(!a.unique||!o.has(g))&&c.push(g)},n=function(b,f){f=f||[],e=!a.memory||[b,f],i=!0,l=j||0,j=0,k=c.length;for(;c&&l<k;l++)if(c[l].apply(b,f)===!1&&a.stopOnFalse){e=!0;break}i=!1,c&&(a.once?e===!0?o.disable():c=[]:d&&d.length&&(e=d.shift(),o.fireWith(e[0],e[1])))},o={add:function(){if(c){var a=c.length;m(arguments),i?k=c.length:e&&e!==!0&&(j=a,n(e[0],e[1]))}return this},remove:function(){if(c){var b=arguments,d=0,e=b.length;for(;d<e;d++)for(var f=0;f<c.length;f++)if(b[d]===c[f]){i&&f<=k&&(k--,f<=l&&l--),c.splice(f--,1);if(a.unique)break}}return this},has:function(a){if(c){var b=0,d=c.length;for(;b<d;b++)if(a===c[b])return!0}return!1},empty:function(){c=[];return this},disable:function(){c=d=e=b;return this},disabled:function(){return!c},lock:function(){d=b,(!e||e===!0)&&o.disable();return this},locked:function(){return!d},fireWith:function(b,c){d&&(i?a.once||d.push([b,c]):(!a.once||!e)&&n(b,c));return this},fire:function(){o.fireWith(this,arguments);return this},fired:function(){return!!e}};return o};var i=[].slice;f.extend({Deferred:function(a){var b=f.Callbacks("once memory"),c=f.Callbacks("once memory"),d=f.Callbacks("memory"),e="pending",g={resolve:b,reject:c,notify:d},h={done:b.add,fail:c.add,progress:d.add,state:function(){return e},isResolved:b.fired,isRejected:c.fired,then:function(a,b,c){i.done(a).fail(b).progress(c);return this},always:function(){return i.done.apply(i,arguments).fail.apply(i,arguments)},pipe:function(a,b,c){return f.Deferred(function(d){f.each({done:[a,"resolve"],fail:[b,"reject"],progress:[c,"notify"]},function(a,b){var c=b[0],e=b[1],g;f.isFunction(c)?i[a](function(){g=c.apply(this,arguments),g&&f.isFunction(g.promise)?g.promise().then(d.resolve,d.reject,d.notify):d[e+"With"](this===i?d:this,[g])}):i[a](d[e])})}).promise()},promise:function(a){if(a==null)a=h;else for(var b in h)a[b]=h[b];return a}},i=h.promise({}),j;for(j in g)i[j]=g[j].fire,i[j+"With"]=g[j].fireWith;i.done(function(){e="resolved"},c.disable,d.lock).fail(function(){e="rejected"},b.disable,d.lock),a&&a.call(i,i);return i},when:function(a){function m(a){return function(b){e[a]=arguments.length>1?i.call(arguments,0):b,j.notifyWith(k,e)}}function l(a){return function(c){b[a]=arguments.length>1?i.call(arguments,0):c,--g||j.resolveWith(j,b)}}var b=i.call(arguments,0),c=0,d=b.length,e=Array(d),g=d,h=d,j=d<=1&&a&&f.isFunction(a.promise)?a:f.Deferred(),k=j.promise();if(d>1){for(;c<d;c++)b[c]&&b[c].promise&&f.isFunction(b[c].promise)?b[c].promise().then(l(c),j.reject,m(c)):--g;g||j.resolveWith(j,b)}else j!==a&&j.resolveWith(j,d?[a]:[]);return k}}),f.support=function(){var a=c.createElement("div"),b=c.documentElement,d,e,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u;a.setAttribute("className","t"),a.innerHTML="   <link/><table></table><a href='/a' style='top:1px;float:left;opacity:.55;'>a</a><input type='checkbox'/><nav></nav>",d=a.getElementsByTagName("*"),e=a.getElementsByTagName("a")[0];if(!d||!d.length||!e)return{};g=c.createElement("select"),h=g.appendChild(c.createElement("option")),i=a.getElementsByTagName("input")[0],k={leadingWhitespace:a.firstChild.nodeType===3,tbody:!a.getElementsByTagName("tbody").length,htmlSerialize:!!a.getElementsByTagName("link").length,style:/top/.test(e.getAttribute("style")),hrefNormalized:e.getAttribute("href")==="/a",opacity:/^0.55/.test(e.style.opacity),cssFloat:!!e.style.cssFloat,unknownElems:!!a.getElementsByTagName("nav").length,checkOn:i.value==="on",optSelected:h.selected,getSetAttribute:a.className!=="t",enctype:!!c.createElement("form").enctype,submitBubbles:!0,changeBubbles:!0,focusinBubbles:!1,deleteExpando:!0,noCloneEvent:!0,inlineBlockNeedsLayout:!1,shrinkWrapBlocks:!1,reliableMarginRight:!0},i.checked=!0,k.noCloneChecked=i.cloneNode(!0).checked,g.disabled=!0,k.optDisabled=!h.disabled;try{delete a.test}catch(v){k.deleteExpando=!1}!a.addEventListener&&a.attachEvent&&a.fireEvent&&(a.attachEvent("onclick",function(){k.noCloneEvent=!1}),a.cloneNode(!0).fireEvent("onclick")),i=c.createElement("input"),i.value="t",i.setAttribute("type","radio"),k.radioValue=i.value==="t",i.setAttribute("checked","checked"),a.appendChild(i),l=c.createDocumentFragment(),l.appendChild(a.lastChild),k.checkClone=l.cloneNode(!0).cloneNode(!0).lastChild.checked,a.innerHTML="",a.style.width=a.style.paddingLeft="1px",m=c.getElementsByTagName("body")[0],o=c.createElement(m?"div":"body"),p={visibility:"hidden",width:0,height:0,border:0,margin:0,background:"none"},m&&f.extend(p,{position:"absolute",left:"-999px",top:"-999px"});for(t in p)o.style[t]=p[t];o.appendChild(a),n=m||b,n.insertBefore(o,n.firstChild),k.appendChecked=i.checked,k.boxModel=a.offsetWidth===2,"zoom"in a.style&&(a.style.display="inline",a.style.zoom=1,k.inlineBlockNeedsLayout=a.offsetWidth===2,a.style.display="",a.innerHTML="<div style='width:4px;'></div>",k.shrinkWrapBlocks=a.offsetWidth!==2),a.innerHTML="<table><tr><td style='padding:0;border:0;display:none'></td><td>t</td></tr></table>",q=a.getElementsByTagName("td"),u=q[0].offsetHeight===0,q[0].style.display="",q[1].style.display="none",k.reliableHiddenOffsets=u&&q[0].offsetHeight===0,a.innerHTML="",c.defaultView&&c.defaultView.getComputedStyle&&(j=c.createElement("div"),j.style.width="0",j.style.marginRight="0",a.appendChild(j),k.reliableMarginRight=(parseInt((c.defaultView.getComputedStyle(j,null)||{marginRight:0}).marginRight,10)||0)===0);if(a.attachEvent)for(t in{submit:1,change:1,focusin:1})s="on"+t,u=s in a,u||(a.setAttribute(s,"return;"),u=typeof a[s]=="function"),k[t+"Bubbles"]=u;f(function(){var a,b,d,e,g,h,i=1,j="position:absolute;top:0;left:0;width:1px;height:1px;margin:0;",l="visibility:hidden;border:0;",n="style='"+j+"border:5px solid #000;padding:0;'",p="<div "+n+"><div></div></div>"+"<table "+n+" cellpadding='0' cellspacing='0'>"+"<tr><td></td></tr></table>";m=c.getElementsByTagName("body")[0];!m||(a=c.createElement("div"),a.style.cssText=l+"width:0;height:0;position:static;top:0;margin-top:"+i+"px",m.insertBefore(a,m.firstChild),o=c.createElement("div"),o.style.cssText=j+l,o.innerHTML=p,a.appendChild(o),b=o.firstChild,d=b.firstChild,g=b.nextSibling.firstChild.firstChild,h={doesNotAddBorder:d.offsetTop!==5,doesAddBorderForTableAndCells:g.offsetTop===5},d.style.position="fixed",d.style.top="20px",h.fixedPosition=d.offsetTop===20||d.offsetTop===15,d.style.position=d.style.top="",b.style.overflow="hidden",b.style.position="relative",h.subtractsBorderForOverflowNotVisible=d.offsetTop===-5,h.doesNotIncludeMarginInBodyOffset=m.offsetTop!==i,m.removeChild(a),o=a=null,f.extend(k,h))}),o.innerHTML="",n.removeChild(o),o=l=g=h=m=j=a=i=null;return k}(),f.boxModel=f.support.boxModel;var j=/^(?:\{.*\}|\[.*\])$/,k=/([A-Z])/g;f.extend({cache:{},uuid:0,expando:"jQuery"+(f.fn.jquery+Math.random()).replace(/\D/g,""),noData:{embed:!0,object:"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",applet:!0},hasData:function(a){a=a.nodeType?f.cache[a[f.expando]]:a[f.expando];return!!a&&!m(a)},data:function(a,c,d,e){if(!!f.acceptData(a)){var g,h,i,j=f.expando,k=typeof c=="string",l=a.nodeType,m=l?f.cache:a,n=l?a[f.expando]:a[f.expando]&&f.expando,o=c==="events";if((!n||!m[n]||!o&&!e&&!m[n].data)&&k&&d===b)return;n||(l?a[f.expando]=n=++f.uuid:n=f.expando),m[n]||(m[n]={},l||(m[n].toJSON=f.noop));if(typeof c=="object"||typeof c=="function")e?m[n]=f.extend(m[n],c):m[n].data=f.extend(m[n].data,c);g=h=m[n],e||(h.data||(h.data={}),h=h.data),d!==b&&(h[f.camelCase(c)]=d);if(o&&!h[c])return g.events;k?(i=h[c],i==null&&(i=h[f.camelCase(c)])):i=h;return i}},removeData:function(a,b,c){if(!!f.acceptData(a)){var d,e,g,h=f.expando,i=a.nodeType,j=i?f.cache:a,k=i?a[f.expando]:f.expando;if(!j[k])return;if(b){d=c?j[k]:j[k].data;if(d){f.isArray(b)?b=b:b in d?b=[b]:(b=f.camelCase(b),b in d?b=[b]:b=b.split(" "));for(e=0,g=b.length;e<g;e++)delete d[b[e]];if(!(c?m:f.isEmptyObject)(d))return}}if(!c){delete j[k].data;if(!m(j[k]))return}f.support.deleteExpando||!j.setInterval?delete j[k]:j[k]=null,i&&(f.support.deleteExpando?delete a[f.expando]:a.removeAttribute?a.removeAttribute(f.expando):a[f.expando]=null)}},_data:function(a,b,c){return f.data(a,b,c,!0)},acceptData:function(a){if(a.nodeName){var b=f.noData[a.nodeName.toLowerCase()];if(b)return b!==!0&&a.getAttribute("classid")===b}return!0}}),f.fn.extend({data:function(a,c){var d,e,g,h=null;if(typeof a=="undefined"){if(this.length){h=f.data(this[0]);if(this[0].nodeType===1&&!f._data(this[0],"parsedAttrs")){e=this[0].attributes;for(var i=0,j=e.length;i<j;i++)g=e[i].name,g.indexOf("data-")===0&&(g=f.camelCase(g.substring(5)),l(this[0],g,h[g]));f._data(this[0],"parsedAttrs",!0)}}return h}if(typeof a=="object")return this.each(function(){f.data(this,a)});d=a.split("."),d[1]=d[1]?"."+d[1]:"";if(c===b){h=this.triggerHandler("getData"+d[1]+"!",[d[0]]),h===b&&this.length&&(h=f.data(this[0],a),h=l(this[0],a,h));return h===b&&d[1]?this.data(d[0]):h}return this.each(function(){var b=f(this),e=[d[0],c];b.triggerHandler("setData"+d[1]+"!",e),f.data(this,a,c),b.triggerHandler("changeData"+d[1]+"!",e)})},removeData:function(a){return this.each(function(){f.removeData(this,a)})}}),f.extend({_mark:function(a,b){a&&(b=(b||"fx")+"mark",f._data(a,b,(f._data(a,b)||0)+1))},_unmark:function(a,b,c){a!==!0&&(c=b,b=a,a=!1);if(b){c=c||"fx";var d=c+"mark",e=a?0:(f._data(b,d)||1)-1;e?f._data(b,d,e):(f.removeData(b,d,!0),n(b,c,"mark"))}},queue:function(a,b,c){var d;if(a){b=(b||"fx")+"queue",d=f._data(a,b),c&&(!d||f.isArray(c)?d=f._data(a,b,f.makeArray(c)):d.push(c));return d||[]}},dequeue:function(a,b){b=b||"fx";var c=f.queue(a,b),d=c.shift(),e={};d==="inprogress"&&(d=c.shift()),d&&(b==="fx"&&c.unshift("inprogress"),f._data(a,b+".run",e),d.call(a,function(){f.dequeue(a,b)},e)),c.length||(f.removeData(a,b+"queue "+b+".run",!0),n(a,b,"queue"))}}),f.fn.extend({queue:function(a,c){typeof a!="string"&&(c=a,a="fx");if(c===b)return f.queue(this[0],a);return this.each(function(){var b=f.queue(this,a,c);a==="fx"&&b[0]!=="inprogress"&&f.dequeue(this,a)})},dequeue:function(a){return this.each(function(){f.dequeue(this,a)})},delay:function(a,b){a=f.fx?f.fx.speeds[a]||a:a,b=b||"fx";return this.queue(b,function(b,c){var d=setTimeout(b,a);c.stop=function(){clearTimeout(d)}})},clearQueue:function(a){return this.queue(a||"fx",[])},promise:function(a,c){function m(){--h||d.resolveWith(e,[e])}typeof a!="string"&&(c=a,a=b),a=a||"fx";var d=f.Deferred(),e=this,g=e.length,h=1,i=a+"defer",j=a+"queue",k=a+"mark",l;while(g--)if(l=f.data(e[g],i,b,!0)||(f.data(e[g],j,b,!0)||f.data(e[g],k,b,!0))&&f.data(e[g],i,f.Callbacks("once memory"),!0))h++,l.add(m);m();return d.promise()}});var o=/[\n\t\r]/g,p=/\s+/,q=/\r/g,r=/^(?:button|input)$/i,s=/^(?:button|input|object|select|textarea)$/i,t=/^a(?:rea)?$/i,u=/^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i,v=f.support.getSetAttribute,w,x,y;f.fn.extend({attr:function(a,b){return f.access(this,a,b,!0,f.attr)},removeAttr:function(a){return this.each(function(){f.removeAttr(this,a)})},prop:function(a,b){return f.access(this,a,b,!0,f.prop)},removeProp:function(a){a=f.propFix[a]||a;return this.each(function(){try{this[a]=b,delete this[a]}catch(c){}})},addClass:function(a){var b,c,d,e,g,h,i;if(f.isFunction(a))return this.each(function(b){f(this).addClass(a.call(this,b,this.className))});if(a&&typeof a=="string"){b=a.split(p);for(c=0,d=this.length;c<d;c++){e=this[c];if(e.nodeType===1)if(!e.className&&b.length===1)e.className=a;else{g=" "+e.className+" ";for(h=0,i=b.length;h<i;h++)~g.indexOf(" "+b[h]+" ")||(g+=b[h]+" ");e.className=f.trim(g)}}}return this},removeClass:function(a){var c,d,e,g,h,i,j;if(f.isFunction(a))return this.each(function(b){f(this).removeClass(a.call(this,b,this.className))});if(a&&typeof a=="string"||a===b){c=(a||"").split(p);for(d=0,e=this.length;d<e;d++){g=this[d];if(g.nodeType===1&&g.className)if(a){h=(" "+g.className+" ").replace(o," ");for(i=0,j=c.length;i<j;i++)h=h.replace(" "+c[i]+" "," ");g.className=f.trim(h)}else g.className=""}}return this},toggleClass:function(a,b){var c=typeof a,d=typeof b=="boolean";if(f.isFunction(a))return this.each(function(c){f(this).toggleClass(a.call(this,c,this.className,b),b)});return this.each(function(){if(c==="string"){var e,g=0,h=f(this),i=b,j=a.split(p);while(e=j[g++])i=d?i:!h.hasClass(e),h[i?"addClass":"removeClass"](e)}else if(c==="undefined"||c==="boolean")this.className&&f._data(this,"__className__",this.className),this.className=this.className||a===!1?"":f._data(this,"__className__")||""})},hasClass:function(a){var b=" "+a+" ",c=0,d=this.length;for(;c<d;c++)if(this[c].nodeType===1&&(" "+this[c].className+" ").replace(o," ").indexOf(b)>-1)return!0;return!1},val:function(a){var c,d,e,g=this[0];if(!arguments.length){if(g){c=f.valHooks[g.nodeName.toLowerCase()]||f.valHooks[g.type];if(c&&"get"in c&&(d=c.get(g,"value"))!==b)return d;d=g.value;return typeof d=="string"?d.replace(q,""):d==null?"":d}return b}e=f.isFunction(a);return this.each(function(d){var g=f(this),h;if(this.nodeType===1){e?h=a.call(this,d,g.val()):h=a,h==null?h="":typeof h=="number"?h+="":f.isArray(h)&&(h=f.map(h,function(a){return a==null?"":a+""})),c=f.valHooks[this.nodeName.toLowerCase()]||f.valHooks[this.type];if(!c||!("set"in c)||c.set(this,h,"value")===b)this.value=h}})}}),f.extend({valHooks:{option:{get:function(a){var b=a.attributes.value;return!b||b.specified?a.value:a.text}},select:{get:function(a){var b,c,d,e,g=a.selectedIndex,h=[],i=a.options,j=a.type==="select-one";if(g<0)return null;c=j?g:0,d=j?g+1:i.length;for(;c<d;c++){e=i[c];if(e.selected&&(f.support.optDisabled?!e.disabled:e.getAttribute("disabled")===null)&&(!e.parentNode.disabled||!f.nodeName(e.parentNode,"optgroup"))){b=f(e).val();if(j)return b;h.push(b)}}if(j&&!h.length&&i.length)return f(i[g]).val();return h},set:function(a,b){var c=f.makeArray(b);f(a).find("option").each(function(){this.selected=f.inArray(f(this).val(),c)>=0}),c.length||(a.selectedIndex=-1);return c}}},attrFn:{val:!0,css:!0,html:!0,text:!0,data:!0,width:!0,height:!0,offset:!0},attr:function(a,c,d,e){var g,h,i,j=a.nodeType;if(!a||j===3||j===8||j===2)return b;if(e&&c in f.attrFn)return f(a)[c](d);if(!("getAttribute"in a))return f.prop(a,c,d);i=j!==1||!f.isXMLDoc(a),i&&(c=c.toLowerCase(),h=f.attrHooks[c]||(u.test(c)?x:w));if(d!==b){if(d===null){f.removeAttr(a,c);return b}if(h&&"set"in h&&i&&(g=h.set(a,d,c))!==b)return g;a.setAttribute(c,""+d);return d}if(h&&"get"in h&&i&&(g=h.get(a,c))!==null)return g;g=a.getAttribute(c);return g===null?b:g},removeAttr:function(a,b){var c,d,e,g,h=0;if(a.nodeType===1){d=(b||"").split(p),g=d.length;for(;h<g;h++)e=d[h].toLowerCase(),c=f.propFix[e]||e,f.attr(a,e,""),a.removeAttribute(v?e:c),u.test(e)&&c in a&&(a[c]=!1)}},attrHooks:{type:{set:function(a,b){if(r.test(a.nodeName)&&a.parentNode)f.error("type property can't be changed");else if(!f.support.radioValue&&b==="radio"&&f.nodeName(a,"input")){var c=a.value;a.setAttribute("type",b),c&&(a.value=c);return b}}},value:{get:function(a,b){if(w&&f.nodeName(a,"button"))return w.get(a,b);return b in a?a.value:null},set:function(a,b,c){if(w&&f.nodeName(a,"button"))return w.set(a,b,c);a.value=b}}},propFix:{tabindex:"tabIndex",readonly:"readOnly","for":"htmlFor","class":"className",maxlength:"maxLength",cellspacing:"cellSpacing",cellpadding:"cellPadding",rowspan:"rowSpan",colspan:"colSpan",usemap:"useMap",frameborder:"frameBorder",contenteditable:"contentEditable"},prop:function(a,c,d){var e,g,h,i=a.nodeType;if(!a||i===3||i===8||i===2)return b;h=i!==1||!f.isXMLDoc(a),h&&(c=f.propFix[c]||c,g=f.propHooks[c]);return d!==b?g&&"set"in g&&(e=g.set(a,d,c))!==b?e:a[c]=d:g&&"get"in g&&(e=g.get(a,c))!==null?e:a[c]},propHooks:{tabIndex:{get:function(a){var c=a.getAttributeNode("tabindex");return c&&c.specified?parseInt(c.value,10):s.test(a.nodeName)||t.test(a.nodeName)&&a.href?0:b}}}}),f.attrHooks.tabindex=f.propHooks.tabIndex,x={get:function(a,c){var d,e=f.prop(a,c);return e===!0||typeof e!="boolean"&&(d=a.getAttributeNode(c))&&d.nodeValue!==!1?c.toLowerCase():b},set:function(a,b,c){var d;b===!1?f.removeAttr(a,c):(d=f.propFix[c]||c,d in a&&(a[d]=!0),a.setAttribute(c,c.toLowerCase()));return c}},v||(y={name:!0,id:!0},w=f.valHooks.button={get:function(a,c){var d;d=a.getAttributeNode(c);return d&&(y[c]?d.nodeValue!=="":d.specified)?d.nodeValue:b},set:function(a,b,d){var e=a.getAttributeNode(d);e||(e=c.createAttribute(d),a.setAttributeNode(e));return e.nodeValue=b+""}},f.attrHooks.tabindex.set=w.set,f.each(["width","height"],function(a,b){f.attrHooks[b]=f.extend(f.attrHooks[b],{set:function(a,c){if(c===""){a.setAttribute(b,"auto");return c}}})}),f.attrHooks.contenteditable={get:w.get,set:function(a,b,c){b===""&&(b="false"),w.set(a,b,c)}}),f.support.hrefNormalized||f.each(["href","src","width","height"],function(a,c){f.attrHooks[c]=f.extend(f.attrHooks[c],{get:function(a){var d=a.getAttribute(c,2);return d===null?b:d}})}),f.support.style||(f.attrHooks.style={get:function(a){return a.style.cssText.toLowerCase()||b},set:function(a,b){return a.style.cssText=""+b}}),f.support.optSelected||(f.propHooks.selected=f.extend(f.propHooks.selected,{get:function(a){var b=a.parentNode;b&&(b.selectedIndex,b.parentNode&&b.parentNode.selectedIndex);return null}})),f.support.enctype||(f.propFix.enctype="encoding"),f.support.checkOn||f.each(["radio","checkbox"],function(){f.valHooks[this]={get:function(a){return a.getAttribute("value")===null?"on":a.value}}}),f.each(["radio","checkbox"],function(){f.valHooks[this]=f.extend(f.valHooks[this],{set:function(a,b){if(f.isArray(b))return a.checked=f.inArray(f(a).val(),b)>=0}})});var z=/\.(.*)$/,A=/^(?:textarea|input|select)$/i,B=/\./g,C=/ /g,D=/[^\w\s.|`]/g,E=/^([^\.]*)?(?:\.(.+))?$/,F=/\bhover(\.\S+)?/,G=/^key/,H=/^(?:mouse|contextmenu)|click/,I=/^(\w*)(?:#([\w\-]+))?(?:\.([\w\-]+))?$/,J=function(a){var b=I.exec(a);b&&
(b[1]=(b[1]||"").toLowerCase(),b[3]=b[3]&&new RegExp("(?:^|\\s)"+b[3]+"(?:\\s|$)"));return b},K=function(a,b){return(!b[1]||a.nodeName.toLowerCase()===b[1])&&(!b[2]||a.id===b[2])&&(!b[3]||b[3].test(a.className))},L=function(a){return f.event.special.hover?a:a.replace(F,"mouseenter$1 mouseleave$1")};f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3||a.nodeType===8||!c||!d||!(h=f._data(a)))){d.handler&&(p=d,d=p.handler),d.guid||(d.guid=f.guid++),j=h.events,j||(h.events=j={}),i=h.handle,i||(h.handle=i=function(a){return typeof f!="undefined"&&(!a||f.event.triggered!==a.type)?f.event.dispatch.apply(i.elem,arguments):b},i.elem=a),c=L(c).split(" ");for(k=0;k<c.length;k++){l=E.exec(c[k])||[],m=l[1],n=(l[2]||"").split(".").sort(),s=f.event.special[m]||{},m=(g?s.delegateType:s.bindType)||m,s=f.event.special[m]||{},o=f.extend({type:m,origType:l[1],data:e,handler:d,guid:d.guid,selector:g,namespace:n.join(".")},p),g&&(o.quick=J(g),!o.quick&&f.expr.match.POS.test(g)&&(o.isPositional=!0)),r=j[m];if(!r){r=j[m]=[],r.delegateCount=0;if(!s.setup||s.setup.call(a,e,n,i)===!1)a.addEventListener?a.addEventListener(m,i,!1):a.attachEvent&&a.attachEvent("on"+m,i)}s.add&&(s.add.call(a,o),o.handler.guid||(o.handler.guid=d.guid)),g?r.splice(r.delegateCount++,0,o):r.push(o),f.event.global[m]=!0}a=null}},global:{},remove:function(a,b,c,d){var e=f.hasData(a)&&f._data(a),g,h,i,j,k,l,m,n,o,p,q;if(!!e&&!!(m=e.events)){b=L(b||"").split(" ");for(g=0;g<b.length;g++){h=E.exec(b[g])||[],i=h[1],j=h[2];if(!i){j=j?"."+j:"";for(l in m)f.event.remove(a,l+j,c,d);return}n=f.event.special[i]||{},i=(d?n.delegateType:n.bindType)||i,p=m[i]||[],k=p.length,j=j?new RegExp("(^|\\.)"+j.split(".").sort().join("\\.(?:.*\\.)?")+"(\\.|$)"):null;if(c||j||d||n.remove)for(l=0;l<p.length;l++){q=p[l];if(!c||c.guid===q.guid)if(!j||j.test(q.namespace))if(!d||d===q.selector||d==="**"&&q.selector)p.splice(l--,1),q.selector&&p.delegateCount--,n.remove&&n.remove.call(a,q)}else p.length=0;p.length===0&&k!==p.length&&((!n.teardown||n.teardown.call(a,j)===!1)&&f.removeEvent(a,i,e.handle),delete m[i])}f.isEmptyObject(m)&&(o=e.handle,o&&(o.elem=null),f.removeData(a,["events","handle"],!0))}},customEvent:{getData:!0,setData:!0,changeData:!0},trigger:function(c,d,e,g){if(!e||e.nodeType!==3&&e.nodeType!==8){var h=c.type||c,i=[],j,k,l,m,n,o,p,q,r,s;h.indexOf("!")>=0&&(h=h.slice(0,-1),k=!0),h.indexOf(".")>=0&&(i=h.split("."),h=i.shift(),i.sort());if((!e||f.event.customEvent[h])&&!f.event.global[h])return;c=typeof c=="object"?c[f.expando]?c:new f.Event(h,c):new f.Event(h),c.type=h,c.isTrigger=!0,c.exclusive=k,c.namespace=i.join("."),c.namespace_re=c.namespace?new RegExp("(^|\\.)"+i.join("\\.(?:.*\\.)?")+"(\\.|$)"):null,o=h.indexOf(":")<0?"on"+h:"",(g||!e)&&c.preventDefault();if(!e){j=f.cache;for(l in j)j[l].events&&j[l].events[h]&&f.event.trigger(c,d,j[l].handle.elem,!0);return}c.result=b,c.target||(c.target=e),d=d!=null?f.makeArray(d):[],d.unshift(c),p=f.event.special[h]||{};if(p.trigger&&p.trigger.apply(e,d)===!1)return;r=[[e,p.bindType||h]];if(!g&&!p.noBubble&&!f.isWindow(e)){s=p.delegateType||h,n=null;for(m=e.parentNode;m;m=m.parentNode)r.push([m,s]),n=m;n&&n===e.ownerDocument&&r.push([n.defaultView||n.parentWindow||a,s])}for(l=0;l<r.length;l++){m=r[l][0],c.type=r[l][1],q=(f._data(m,"events")||{})[c.type]&&f._data(m,"handle"),q&&q.apply(m,d),q=o&&m[o],q&&f.acceptData(m)&&q.apply(m,d);if(c.isPropagationStopped())break}c.type=h,c.isDefaultPrevented()||(!p._default||p._default.apply(e.ownerDocument,d)===!1)&&(h!=="click"||!f.nodeName(e,"a"))&&f.acceptData(e)&&o&&e[h]&&(h!=="focus"&&h!=="blur"||c.target.offsetWidth!==0)&&!f.isWindow(e)&&(n=e[o],n&&(e[o]=null),f.event.triggered=h,e[h](),f.event.triggered=b,n&&(e[o]=n));return c.result}},dispatch:function(c){c=f.event.fix(c||a.event);var d=(f._data(this,"events")||{})[c.type]||[],e=d.delegateCount,g=[].slice.call(arguments,0),h=!c.exclusive&&!c.namespace,i=(f.event.special[c.type]||{}).handle,j=[],k,l,m,n,o,p,q,r,s,t,u;g[0]=c,c.delegateTarget=this;if(e&&!c.target.disabled&&(!c.button||c.type!=="click"))for(m=c.target;m!=this;m=m.parentNode||this){o={},q=[];for(k=0;k<e;k++)r=d[k],s=r.selector,t=o[s],r.isPositional?t=(t||(o[s]=f(s))).index(m)>=0:t===b&&(t=o[s]=r.quick?K(m,r.quick):f(m).is(s)),t&&q.push(r);q.length&&j.push({elem:m,matches:q})}d.length>e&&j.push({elem:this,matches:d.slice(e)});for(k=0;k<j.length&&!c.isPropagationStopped();k++){p=j[k],c.currentTarget=p.elem;for(l=0;l<p.matches.length&&!c.isImmediatePropagationStopped();l++){r=p.matches[l];if(h||!c.namespace&&!r.namespace||c.namespace_re&&c.namespace_re.test(r.namespace))c.data=r.data,c.handleObj=r,n=(i||r.handler).apply(p.elem,g),n!==b&&(c.result=n,n===!1&&(c.preventDefault(),c.stopPropagation()))}}return c.result},props:"attrChange attrName relatedNode srcElement altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),fixHooks:{},keyHooks:{props:"char charCode key keyCode".split(" "),filter:function(a,b){a.which==null&&(a.which=b.charCode!=null?b.charCode:b.keyCode);return a}},mouseHooks:{props:"button buttons clientX clientY fromElement offsetX offsetY pageX pageY screenX screenY toElement wheelDelta".split(" "),filter:function(a,d){var e,f,g,h=d.button,i=d.fromElement;a.pageX==null&&d.clientX!=null&&(e=a.target.ownerDocument||c,f=e.documentElement,g=e.body,a.pageX=d.clientX+(f&&f.scrollLeft||g&&g.scrollLeft||0)-(f&&f.clientLeft||g&&g.clientLeft||0),a.pageY=d.clientY+(f&&f.scrollTop||g&&g.scrollTop||0)-(f&&f.clientTop||g&&g.clientTop||0)),!a.relatedTarget&&i&&(a.relatedTarget=i===a.target?d.toElement:i),!a.which&&h!==b&&(a.which=h&1?1:h&2?3:h&4?2:0);return a}},fix:function(a){if(a[f.expando])return a;var d,e,g=a,h=f.event.fixHooks[a.type]||{},i=h.props?this.props.concat(h.props):this.props;a=f.Event(g);for(d=i.length;d;)e=i[--d],a[e]=g[e];a.target||(a.target=g.srcElement||c),a.target.nodeType===3&&(a.target=a.target.parentNode),a.metaKey===b&&(a.metaKey=a.ctrlKey);return h.filter?h.filter(a,g):a},special:{ready:{setup:f.bindReady},focus:{delegateType:"focusin",noBubble:!0},blur:{delegateType:"focusout",noBubble:!0},beforeunload:{setup:function(a,b,c){f.isWindow(this)&&(this.onbeforeunload=c)},teardown:function(a,b){this.onbeforeunload===b&&(this.onbeforeunload=null)}}},simulate:function(a,b,c,d){var e=f.extend(new f.Event,c,{type:a,isSimulated:!0,originalEvent:{}});d?f.event.trigger(e,null,b):f.event.dispatch.call(b,e),e.isDefaultPrevented()&&c.preventDefault()}},f.event.handle=f.event.dispatch,f.removeEvent=c.removeEventListener?function(a,b,c){a.removeEventListener&&a.removeEventListener(b,c,!1)}:function(a,b,c){a.detachEvent&&a.detachEvent("on"+b,c)},f.Event=function(a,b){if(!(this instanceof f.Event))return new f.Event(a,b);a&&a.type?(this.originalEvent=a,this.type=a.type,this.isDefaultPrevented=a.defaultPrevented||a.returnValue===!1||a.getPreventDefault&&a.getPreventDefault()?N:M):this.type=a,b&&f.extend(this,b),this.timeStamp=a&&a.timeStamp||f.now(),this[f.expando]=!0},f.Event.prototype={preventDefault:function(){this.isDefaultPrevented=N;var a=this.originalEvent;!a||(a.preventDefault?a.preventDefault():a.returnValue=!1)},stopPropagation:function(){this.isPropagationStopped=N;var a=this.originalEvent;!a||(a.stopPropagation&&a.stopPropagation(),a.cancelBubble=!0)},stopImmediatePropagation:function(){this.isImmediatePropagationStopped=N,this.stopPropagation()},isDefaultPrevented:M,isPropagationStopped:M,isImmediatePropagationStopped:M},f.each({mouseenter:"mouseover",mouseleave:"mouseout"},function(a,b){f.event.special[a]=f.event.special[b]={delegateType:b,bindType:b,handle:function(a){var b=this,c=a.relatedTarget,d=a.handleObj,e=d.selector,g,h;if(!c||d.origType===a.type||c!==b&&!f.contains(b,c))g=a.type,a.type=d.origType,h=d.handler.apply(this,arguments),a.type=g;return h}}}),f.support.submitBubbles||(f.event.special.submit={setup:function(){if(f.nodeName(this,"form"))return!1;f.event.add(this,"click._submit keypress._submit",function(a){var c=a.target,d=f.nodeName(c,"input")||f.nodeName(c,"button")?c.form:b;d&&!d._submit_attached&&(f.event.add(d,"submit._submit",function(a){this.parentNode&&f.event.simulate("submit",this.parentNode,a,!0)}),d._submit_attached=!0)})},teardown:function(){if(f.nodeName(this,"form"))return!1;f.event.remove(this,"._submit")}}),f.support.changeBubbles||(f.event.special.change={setup:function(){if(A.test(this.nodeName)){if(this.type==="checkbox"||this.type==="radio")f.event.add(this,"propertychange._change",function(a){a.originalEvent.propertyName==="checked"&&(this._just_changed=!0)}),f.event.add(this,"click._change",function(a){this._just_changed&&(this._just_changed=!1,f.event.simulate("change",this,a,!0))});return!1}f.event.add(this,"beforeactivate._change",function(a){var b=a.target;A.test(b.nodeName)&&!b._change_attached&&(f.event.add(b,"change._change",function(a){this.parentNode&&!a.isSimulated&&f.event.simulate("change",this.parentNode,a,!0)}),b._change_attached=!0)})},handle:function(a){var b=a.target;if(this!==b||a.isSimulated||a.isTrigger||b.type!=="radio"&&b.type!=="checkbox")return a.handleObj.handler.apply(this,arguments)},teardown:function(){f.event.remove(this,"._change");return A.test(this.nodeName)}}),f.support.focusinBubbles||f.each({focus:"focusin",blur:"focusout"},function(a,b){var d=0,e=function(a){f.event.simulate(b,a.target,f.event.fix(a),!0)};f.event.special[b]={setup:function(){d++===0&&c.addEventListener(a,e,!0)},teardown:function(){--d===0&&c.removeEventListener(a,e,!0)}}}),f.fn.extend({on:function(a,c,d,e,g){var h,i;if(typeof a=="object"){typeof c!="string"&&(d=c,c=b);for(i in a)this.on(i,c,d,a[i],g);return this}d==null&&e==null?(e=c,d=c=b):e==null&&(typeof c=="string"?(e=d,d=b):(e=d,d=c,c=b));if(e===!1)e=M;else if(!e)return this;g===1&&(h=e,e=function(a){f().off(a);return h.apply(this,arguments)},e.guid=h.guid||(h.guid=f.guid++));return this.each(function(){f.event.add(this,a,e,d,c)})},one:function(a,b,c,d){return this.on.call(this,a,b,c,d,1)},off:function(a,c,d){if(a&&a.preventDefault&&a.handleObj){var e=a.handleObj;f(a.delegateTarget).off(e.namespace?e.type+"."+e.namespace:e.type,e.selector,e.handler);return this}if(typeof a=="object"){for(var g in a)this.off(g,c,a[g]);return this}if(c===!1||typeof c=="function")d=c,c=b;d===!1&&(d=M);return this.each(function(){f.event.remove(this,a,d,c)})},bind:function(a,b,c){return this.on(a,null,b,c)},unbind:function(a,b){return this.off(a,null,b)},live:function(a,b,c){f(this.context).on(a,this.selector,b,c);return this},die:function(a,b){f(this.context).off(a,this.selector||"**",b);return this},delegate:function(a,b,c,d){return this.on(b,a,c,d)},undelegate:function(a,b,c){return arguments.length==1?this.off(a,"**"):this.off(b,a,c)},trigger:function(a,b){return this.each(function(){f.event.trigger(a,b,this)})},triggerHandler:function(a,b){if(this[0])return f.event.trigger(a,b,this[0],!0)},toggle:function(a){var b=arguments,c=a.guid||f.guid++,d=0,e=function(c){var e=(f._data(this,"lastToggle"+a.guid)||0)%d;f._data(this,"lastToggle"+a.guid,e+1),c.preventDefault();return b[e].apply(this,arguments)||!1};e.guid=c;while(d<b.length)b[d++].guid=c;return this.click(e)},hover:function(a,b){return this.mouseenter(a).mouseleave(b||a)}}),f.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 contextmenu".split(" "),function(a,b){f.fn[b]=function(a,c){c==null&&(c=a,a=null);return arguments.length>0?this.bind(b,a,c):this.trigger(b)},f.attrFn&&(f.attrFn[b]=!0),G.test(b)&&(f.event.fixHooks[b]=f.event.keyHooks),H.test(b)&&(f.event.fixHooks[b]=f.event.mouseHooks)}),function(){function x(a,b,c,e,f,g){for(var h=0,i=e.length;h<i;h++){var j=e[h];if(j){var k=!1;j=j[a];while(j){if(j[d]===c){k=e[j.sizset];break}if(j.nodeType===1){g||(j[d]=c,j.sizset=h);if(typeof b!="string"){if(j===b){k=!0;break}}else if(m.filter(b,[j]).length>0){k=j;break}}j=j[a]}e[h]=k}}}function w(a,b,c,e,f,g){for(var h=0,i=e.length;h<i;h++){var j=e[h];if(j){var k=!1;j=j[a];while(j){if(j[d]===c){k=e[j.sizset];break}j.nodeType===1&&!g&&(j[d]=c,j.sizset=h);if(j.nodeName.toLowerCase()===b){k=j;break}j=j[a]}e[h]=k}}}var a=/((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,d="sizcache"+(Math.random()+"").replace(".",""),e=0,g=Object.prototype.toString,h=!1,i=!0,j=/\\/g,k=/\r\n/g,l=/\W/;[0,0].sort(function(){i=!1;return 0});var m=function(b,d,e,f){e=e||[],d=d||c;var h=d;if(d.nodeType!==1&&d.nodeType!==9)return[];if(!b||typeof b!="string")return e;var i,j,k,l,n,q,r,t,u=!0,v=m.isXML(d),w=[],x=b;do{a.exec(""),i=a.exec(x);if(i){x=i[3],w.push(i[1]);if(i[2]){l=i[3];break}}}while(i);if(w.length>1&&p.exec(b))if(w.length===2&&o.relative[w[0]])j=y(w[0]+w[1],d,f);else{j=o.relative[w[0]]?[d]:m(w.shift(),d);while(w.length)b=w.shift(),o.relative[b]&&(b+=w.shift()),j=y(b,j,f)}else{!f&&w.length>1&&d.nodeType===9&&!v&&o.match.ID.test(w[0])&&!o.match.ID.test(w[w.length-1])&&(n=m.find(w.shift(),d,v),d=n.expr?m.filter(n.expr,n.set)[0]:n.set[0]);if(d){n=f?{expr:w.pop(),set:s(f)}:m.find(w.pop(),w.length===1&&(w[0]==="~"||w[0]==="+")&&d.parentNode?d.parentNode:d,v),j=n.expr?m.filter(n.expr,n.set):n.set,w.length>0?k=s(j):u=!1;while(w.length)q=w.pop(),r=q,o.relative[q]?r=w.pop():q="",r==null&&(r=d),o.relative[q](k,r,v)}else k=w=[]}k||(k=j),k||m.error(q||b);if(g.call(k)==="[object Array]")if(!u)e.push.apply(e,k);else if(d&&d.nodeType===1)for(t=0;k[t]!=null;t++)k[t]&&(k[t]===!0||k[t].nodeType===1&&m.contains(d,k[t]))&&e.push(j[t]);else for(t=0;k[t]!=null;t++)k[t]&&k[t].nodeType===1&&e.push(j[t]);else s(k,e);l&&(m(l,h,e,f),m.uniqueSort(e));return e};m.uniqueSort=function(a){if(u){h=i,a.sort(u);if(h)for(var b=1;b<a.length;b++)a[b]===a[b-1]&&a.splice(b--,1)}return a},m.matches=function(a,b){return m(a,null,null,b)},m.matchesSelector=function(a,b){return m(b,null,null,[a]).length>0},m.find=function(a,b,c){var d,e,f,g,h,i;if(!a)return[];for(e=0,f=o.order.length;e<f;e++){h=o.order[e];if(g=o.leftMatch[h].exec(a)){i=g[1],g.splice(1,1);if(i.substr(i.length-1)!=="\\"){g[1]=(g[1]||"").replace(j,""),d=o.find[h](g,b,c);if(d!=null){a=a.replace(o.match[h],"");break}}}}d||(d=typeof b.getElementsByTagName!="undefined"?b.getElementsByTagName("*"):[]);return{set:d,expr:a}},m.filter=function(a,c,d,e){var f,g,h,i,j,k,l,n,p,q=a,r=[],s=c,t=c&&c[0]&&m.isXML(c[0]);while(a&&c.length){for(h in o.filter)if((f=o.leftMatch[h].exec(a))!=null&&f[2]){k=o.filter[h],l=f[1],g=!1,f.splice(1,1);if(l.substr(l.length-1)==="\\")continue;s===r&&(r=[]);if(o.preFilter[h]){f=o.preFilter[h](f,s,d,r,e,t);if(!f)g=i=!0;else if(f===!0)continue}if(f)for(n=0;(j=s[n])!=null;n++)j&&(i=k(j,f,n,s),p=e^i,d&&i!=null?p?g=!0:s[n]=!1:p&&(r.push(j),g=!0));if(i!==b){d||(s=r),a=a.replace(o.match[h],"");if(!g)return[];break}}if(a===q)if(g==null)m.error(a);else break;q=a}return s},m.error=function(a){throw"Syntax error, unrecognized expression: "+a};var n=m.getText=function(a){var b,c,d=a.nodeType,e="";if(d){if(d===1){if(typeof a.textContent=="string")return a.textContent;if(typeof a.innerText=="string")return a.innerText.replace(k,"");for(a=a.firstChild;a;a=a.nextSibling)e+=n(a)}else if(d===3||d===4)return a.nodeValue}else for(b=0;c=a[b];b++)c.nodeType!==8&&(e+=n(c));return e},o=m.selectors={order:["ID","NAME","TAG"],match:{ID:/#((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,CLASS:/\.((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,NAME:/\[name=['"]*((?:[\w\u00c0-\uFFFF\-]|\\.)+)['"]*\]/,ATTR:/\[\s*((?:[\w\u00c0-\uFFFF\-]|\\.)+)\s*(?:(\S?=)\s*(?:(['"])(.*?)\3|(#?(?:[\w\u00c0-\uFFFF\-]|\\.)*)|)|)\s*\]/,TAG:/^((?:[\w\u00c0-\uFFFF\*\-]|\\.)+)/,CHILD:/:(only|nth|last|first)-child(?:\(\s*(even|odd|(?:[+\-]?\d+|(?:[+\-]?\d*)?n\s*(?:[+\-]\s*\d+)?))\s*\))?/,POS:/:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^\-]|$)/,PSEUDO:/:((?:[\w\u00c0-\uFFFF\-]|\\.)+)(?:\((['"]?)((?:\([^\)]+\)|[^\(\)]*)+)\2\))?/},leftMatch:{},attrMap:{"class":"className","for":"htmlFor"},attrHandle:{href:function(a){return a.getAttribute("href")},type:function(a){return a.getAttribute("type")}},relative:{"+":function(a,b){var c=typeof b=="string",d=c&&!l.test(b),e=c&&!d;d&&(b=b.toLowerCase());for(var f=0,g=a.length,h;f<g;f++)if(h=a[f]){while((h=h.previousSibling)&&h.nodeType!==1);a[f]=e||h&&h.nodeName.toLowerCase()===b?h||!1:h===b}e&&m.filter(b,a,!0)},">":function(a,b){var c,d=typeof b=="string",e=0,f=a.length;if(d&&!l.test(b)){b=b.toLowerCase();for(;e<f;e++){c=a[e];if(c){var g=c.parentNode;a[e]=g.nodeName.toLowerCase()===b?g:!1}}}else{for(;e<f;e++)c=a[e],c&&(a[e]=d?c.parentNode:c.parentNode===b);d&&m.filter(b,a,!0)}},"":function(a,b,c){var d,f=e++,g=x;typeof b=="string"&&!l.test(b)&&(b=b.toLowerCase(),d=b,g=w),g("parentNode",b,f,a,d,c)},"~":function(a,b,c){var d,f=e++,g=x;typeof b=="string"&&!l.test(b)&&(b=b.toLowerCase(),d=b,g=w),g("previousSibling",b,f,a,d,c)}},find:{ID:function(a,b,c){if(typeof b.getElementById!="undefined"&&!c){var d=b.getElementById(a[1]);return d&&d.parentNode?[d]:[]}},NAME:function(a,b){if(typeof b.getElementsByName!="undefined"){var c=[],d=b.getElementsByName(a[1]);for(var e=0,f=d.length;e<f;e++)d[e].getAttribute("name")===a[1]&&c.push(d[e]);return c.length===0?null:c}},TAG:function(a,b){if(typeof b.getElementsByTagName!="undefined")return b.getElementsByTagName(a[1])}},preFilter:{CLASS:function(a,b,c,d,e,f){a=" "+a[1].replace(j,"")+" ";if(f)return a;for(var g=0,h;(h=b[g])!=null;g++)h&&(e^(h.className&&(" "+h.className+" ").replace(/[\t\n\r]/g," ").indexOf(a)>=0)?c||d.push(h):c&&(b[g]=!1));return!1},ID:function(a){return a[1].replace(j,"")},TAG:function(a,b){return a[1].replace(j,"").toLowerCase()},CHILD:function(a){if(a[1]==="nth"){a[2]||m.error(a[0]),a[2]=a[2].replace(/^\+|\s*/g,"");var b=/(-?)(\d*)(?:n([+\-]?\d*))?/.exec(a[2]==="even"&&"2n"||a[2]==="odd"&&"2n+1"||!/\D/.test(a[2])&&"0n+"+a[2]||a[2]);a[2]=b[1]+(b[2]||1)-0,a[3]=b[3]-0}else a[2]&&m.error(a[0]);a[0]=e++;return a},ATTR:function(a,b,c,d,e,f){var g=a[1]=a[1].replace(j,"");!f&&o.attrMap[g]&&(a[1]=o.attrMap[g]),a[4]=(a[4]||a[5]||"").replace(j,""),a[2]==="~="&&(a[4]=" "+a[4]+" ");return a},PSEUDO:function(b,c,d,e,f){if(b[1]==="not")if((a.exec(b[3])||"").length>1||/^\w/.test(b[3]))b[3]=m(b[3],null,null,c);else{var g=m.filter(b[3],c,d,!0^f);d||e.push.apply(e,g);return!1}else if(o.match.POS.test(b[0])||o.match.CHILD.test(b[0]))return!0;return b},POS:function(a){a.unshift(!0);return a}},filters:{enabled:function(a){return a.disabled===!1&&a.type!=="hidden"},disabled:function(a){return a.disabled===!0},checked:function(a){return a.checked===!0},selected:function(a){a.parentNode&&a.parentNode.selectedIndex;return a.selected===!0},parent:function(a){return!!a.firstChild},empty:function(a){return!a.firstChild},has:function(a,b,c){return!!m(c[3],a).length},header:function(a){return/h\d/i.test(a.nodeName)},text:function(a){var b=a.getAttribute("type"),c=a.type;return a.nodeName.toLowerCase()==="input"&&"text"===c&&(b===c||b===null)},radio:function(a){return a.nodeName.toLowerCase()==="input"&&"radio"===a.type},checkbox:function(a){return a.nodeName.toLowerCase()==="input"&&"checkbox"===a.type},file:function(a){return a.nodeName.toLowerCase()==="input"&&"file"===a.type},password:function(a){return a.nodeName.toLowerCase()==="input"&&"password"===a.type},submit:function(a){var b=a.nodeName.toLowerCase();return(b==="input"||b==="button")&&"submit"===a.type},image:function(a){return a.nodeName.toLowerCase()==="input"&&"image"===a.type},reset:function(a){var b=a.nodeName.toLowerCase();return(b==="input"||b==="button")&&"reset"===a.type},button:function(a){var b=a.nodeName.toLowerCase();return b==="input"&&"button"===a.type||b==="button"},input:function(a){return/input|select|textarea|button/i.test(a.nodeName)},focus:function(a){return a===a.ownerDocument.activeElement}},setFilters:{first:function(a,b){return b===0},last:function(a,b,c,d){return b===d.length-1},even:function(a,b){return b%2===0},odd:function(a,b){return b%2===1},lt:function(a,b,c){return b<c[3]-0},gt:function(a,b,c){return b>c[3]-0},nth:function(a,b,c){return c[3]-0===b},eq:function(a,b,c){return c[3]-0===b}},filter:{PSEUDO:function(a,b,c,d){var e=b[1],f=o.filters[e];if(f)return f(a,c,b,d);if(e==="contains")return(a.textContent||a.innerText||n([a])||"").indexOf(b[3])>=0;if(e==="not"){var g=b[3];for(var h=0,i=g.length;h<i;h++)if(g[h]===a)return!1;return!0}m.error(e)},CHILD:function(a,b){var c,e,f,g,h,i,j,k=b[1],l=a;switch(k){case"only":case"first":while(l=l.previousSibling)if(l.nodeType===1)return!1;if(k==="first")return!0;l=a;case"last":while(l=l.nextSibling)if(l.nodeType===1)return!1;return!0;case"nth":c=b[2],e=b[3];if(c===1&&e===0)return!0;f=b[0],g=a.parentNode;if(g&&(g[d]!==f||!a.nodeIndex)){i=0;for(l=g.firstChild;l;l=l.nextSibling)l.nodeType===1&&(l.nodeIndex=++i);g[d]=f}j=a.nodeIndex-e;return c===0?j===0:j%c===0&&j/c>=0}},ID:function(a,b){return a.nodeType===1&&a.getAttribute("id")===b},TAG:function(a,b){return b==="*"&&a.nodeType===1||!!a.nodeName&&a.nodeName.toLowerCase()===b},CLASS:function(a,b){return(" "+(a.className||a.getAttribute("class"))+" ").indexOf(b)>-1},ATTR:function(a,b){var c=b[1],d=m.attr?m.attr(a,c):o.attrHandle[c]?o.attrHandle[c](a):a[c]!=null?a[c]:a.getAttribute(c),e=d+"",f=b[2],g=b[4];return d==null?f==="!=":!f&&m.attr?d!=null:f==="="?e===g:f==="*="?e.indexOf(g)>=0:f==="~="?(" "+e+" ").indexOf(g)>=0:g?f==="!="?e!==g:f==="^="?e.indexOf(g)===0:f==="$="?e.substr(e.length-g.length)===g:f==="|="?e===g||e.substr(0,g.length+1)===g+"-":!1:e&&d!==!1},POS:function(a,b,c,d){var e=b[2],f=o.setFilters[e];if(f)return f(a,c,b,d)}}},p=o.match.POS,q=function(a,b){return"\\"+(b-0+1)};for(var r in o.match)o.match[r]=new RegExp(o.match[r].source+/(?![^\[]*\])(?![^\(]*\))/.source),o.leftMatch[r]=new RegExp(/(^(?:.|\r|\n)*?)/.source+o.match[r].source.replace(/\\(\d+)/g,q));var s=function(a,b){a=Array.prototype.slice.call(a,0);if(b){b.push.apply(b,a);return b}return a};try{Array.prototype.slice.call(c.documentElement.childNodes,0)[0].nodeType}catch(t){s=function(a,b){var c=0,d=b||[];if(g.call(a)==="[object Array]")Array.prototype.push.apply(d,a);else if(typeof a.length=="number")for(var e=a.length;c<e;c++)d.push(a[c]);else for(;a[c];c++)d.push(a[c]);return d}}var u,v;c.documentElement.compareDocumentPosition?u=function(a,b){if(a===b){h=!0;return 0}if(!a.compareDocumentPosition||!b.compareDocumentPosition)return a.compareDocumentPosition?-1:1;return a.compareDocumentPosition(b)&4?-1:1}:(u=function(a,b){if(a===b){h=!0;return 0}if(a.sourceIndex&&b.sourceIndex)return a.sourceIndex-b.sourceIndex;var c,d,e=[],f=[],g=a.parentNode,i=b.parentNode,j=g;if(g===i)return v(a,b);if(!g)return-1;if(!i)return 1;while(j)e.unshift(j),j=j.parentNode;j=i;while(j)f.unshift(j),j=j.parentNode;c=e.length,d=f.length;for(var k=0;k<c&&k<d;k++)if(e[k]!==f[k])return v(e[k],f[k]);return k===c?v(a,f[k],-1):v(e[k],b,1)},v=function(a,b,c){if(a===b)return c;var d=a.nextSibling;while(d){if(d===b)return-1;d=d.nextSibling}return 1}),function(){var a=c.createElement("div"),d="script"+(new Date).getTime(),e=c.documentElement;a.innerHTML="<a name='"+d+"'/>",e.insertBefore(a,e.firstChild),c.getElementById(d)&&(o.find.ID=function(a,c,d){if(typeof c.getElementById!="undefined"&&!d){var e=c.getElementById(a[1]);return e?e.id===a[1]||typeof e.getAttributeNode!="undefined"&&e.getAttributeNode("id").nodeValue===a[1]?[e]:b:[]}},o.filter.ID=function(a,b){var c=typeof a.getAttributeNode!="undefined"&&a.getAttributeNode("id");return a.nodeType===1&&c&&c.nodeValue===b}),e.removeChild(a),e=a=null}(),function(){var a=c.createElement("div");a.appendChild(c.createComment("")),a.getElementsByTagName("*").length>0&&(o.find.TAG=function(a,b){var c=b.getElementsByTagName(a[1]);if(a[1]==="*"){var d=[];for(var e=0;c[e];e++)c[e].nodeType===1&&d.push(c[e]);c=d}return c}),a.innerHTML="<a href='#'></a>",a.firstChild&&typeof a.firstChild.getAttribute!="undefined"&&a.firstChild.getAttribute("href")!=="#"&&(o.attrHandle.href=function(a){return a.getAttribute("href",2)}),a=null}(),c.querySelectorAll&&function(){var a=m,b=c.createElement("div"),d="__sizzle__";b.innerHTML="<p class='TEST'></p>";if(!b.querySelectorAll||b.querySelectorAll(".TEST").length!==0){m=function(b,e,f,g){e=e||c;if(!g&&!m.isXML(e)){var h=/^(\w+$)|^\.([\w\-]+$)|^#([\w\-]+$)/.exec(b);if(h&&(e.nodeType===1||e.nodeType===9)){if(h[1])return s(e.getElementsByTagName(b),f);if(h[2]&&o.find.CLASS&&e.getElementsByClassName)return s(e.getElementsByClassName(h[2]),f)}if(e.nodeType===9){if(b==="body"&&e.body)return s([e.body],f);if(h&&h[3]){var i=e.getElementById(h[3]);if(!i||!i.parentNode)return s([],f);if(i.id===h[3])return s([i],f)}try{return s(e.querySelectorAll(b),f)}catch(j){}}else if(e.nodeType===1&&e.nodeName.toLowerCase()!=="object"){var k=e,l=e.getAttribute("id"),n=l||d,p=e.parentNode,q=/^\s*[+~]/.test(b);l?n=n.replace(/'/g,"\\$&"):e.setAttribute("id",n),q&&p&&(e=e.parentNode);try{if(!q||p)return s(e.querySelectorAll("[id='"+n+"'] "+b),f)}catch(r){}finally{l||k.removeAttribute("id")}}}return a(b,e,f,g)};for(var e in a)m[e]=a[e];b=null}}(),function(){var a=c.documentElement,b=a.matchesSelector||a.mozMatchesSelector||a.webkitMatchesSelector||a.msMatchesSelector;if(b){var d=!b.call(c.createElement("div"),"div"),e=!1;try{b.call(c.documentElement,"[test!='']:sizzle")}catch(f){e=!0}m.matchesSelector=function(a,c){c=c.replace(/\=\s*([^'"\]]*)\s*\]/g,"='$1']");if(!m.isXML(a))try{if(e||!o.match.PSEUDO.test(c)&&!/!=/.test(c)){var f=b.call(a,c);if(f||!d||a.document&&a.document.nodeType!==11)return f}}catch(g){}return m(c,null,null,[a]).length>0}}}(),function(){var a=c.createElement("div");a.innerHTML="<div class='test e'></div><div class='test'></div>";if(!!a.getElementsByClassName&&a.getElementsByClassName("e").length!==0){a.lastChild.className="e";if(a.getElementsByClassName("e").length===1)return;o.order.splice(1,0,"CLASS"),o.find.CLASS=function(a,b,c){if(typeof b.getElementsByClassName!="undefined"&&!c)return b.getElementsByClassName(a[1])},a=null}}(),c.documentElement.contains?m.contains=function(a,b){return a!==b&&(a.contains?a.contains(b):!0)}:c.documentElement.compareDocumentPosition?m.contains=function(a,b){return!!(a.compareDocumentPosition(b)&16)}:m.contains=function(){return!1},m.isXML=function(a){var b=(a?a.ownerDocument||a:0).documentElement;return b?b.nodeName!=="HTML":!1};var y=function(a,b,c){var d,e=[],f="",g=b.nodeType?[b]:b;while(d=o.match.PSEUDO.exec(a))f+=d[0],a=a.replace(o.match.PSEUDO,"");a=o.relative[a]?a+"*":a;for(var h=0,i=g.length;h<i;h++)m(a,g[h],e,c);return m.filter(f,e)};m.attr=f.attr,m.selectors.attrMap={},f.find=m,f.expr=m.selectors,f.expr[":"]=f.expr.filters,f.unique=m.uniqueSort,f.text=m.getText,f.isXMLDoc=m.isXML,f.contains=m.contains}();var O=/Until$/,P=/^(?:parents|prevUntil|prevAll)/,Q=/,/,R=/^.[^:#\[\.,]*$/,S=Array.prototype.slice,T=f.expr.match.POS,U={children:!0,contents:!0,next:!0,prev:!0};f.fn.extend({find:function(a){var b=this,c,d;if(typeof a!="string")return f(a).filter(function(){for(c=0,d=b.length;c<d;c++)if(f.contains(b[c],this))return!0});var e=this.pushStack("","find",a),g,h,i;for(c=0,d=this.length;c<d;c++){g=e.length,f.find(a,this[c],e);if(c>0)for(h=g;h<e.length;h++)for(i=0;i<g;i++)if(e[i]===e[h]){e.splice(h--,1);break}}return e},has:function(a){var b=f(a);return this.filter(function(){for(var a=0,c=b.length;a<c;a++)if(f.contains(this,b[a]))return!0})},not:function(a){return this.pushStack(W(this,a,!1),"not",a)},filter:function(a){return this.pushStack(W(this,a,!0),"filter",a)},is:function(a){return!!a&&(typeof a=="string"?T.test(a)?f(a,this.context).index(this[0])>=0:f.filter(a,this).length>0:this.filter(a).length>0)},closest:function(a,b){var c=[],d,e,g=this[0];if(f.isArray(a)){var h=1;while(g&&g.ownerDocument&&g!==b){for(d=0;d<a.length;d++)f(g).is(a[d])&&c.push({selector:a[d],elem:g,level:h});g=g.parentNode,h++}return c}var i=T.test(a)||typeof a!="string"?f(a,b||this.context):0;for(d=0,e=this.length;d<e;d++){g=this[d];while(g){if(i?i.index(g)>-1:f.find.matchesSelector(g,a)){c.push(g);break}g=g.parentNode;if(!g||!g.ownerDocument||g===b||g.nodeType===11)break}}c=c.length>1?f.unique(c):c;return this.pushStack(c,"closest",a)},index:function(a){if(!a)return this[0]&&this[0].parentNode?this.prevAll().length:-1;if(typeof a=="string")return f.inArray(this[0],f(a));return f.inArray(a.jquery?a[0]:a,this)},add:function(a,b){var c=typeof a=="string"?f(a,b):f.makeArray(a&&a.nodeType?[a]:a),d=f.merge(this.get(),c);return this.pushStack(V(c[0])||V(d[0])?d:f.unique(d))},andSelf:function(){return this.add(this.prevObject)}}),f.each({parent:function(a){var b=a.parentNode;return b&&b.nodeType!==11?b:null},parents:function(a){return f.dir(a,"parentNode")},parentsUntil:function(a,b,c){return f.dir(a,"parentNode",c)},next:function(a){return f.nth(a,2,"nextSibling")},prev:function(a){return f.nth(a,2,"previousSibling")},nextAll:function(a){return f.dir(a,"nextSibling")},prevAll:function(a){return f.dir(a,"previousSibling")},nextUntil:function(a,b,c){return f.dir(a,"nextSibling",c)},prevUntil:function(a,b,c){return f.dir(a,"previousSibling",c)},siblings:function(a){return f.sibling(a.parentNode.firstChild,a)},children:function(a){return f.sibling(a.firstChild)},contents:function(a){return f.nodeName(a,"iframe")?a.contentDocument||a.contentWindow.document:f.makeArray(a.childNodes)}},function(a,b){f.fn[a]=function(c,d){var e=f.map(this,b,c),g=S.call(arguments);O.test(a)||(d=c),d&&typeof d=="string"&&(e=f.filter(d,e)),e=this.length>1&&!U[a]?f.unique(e):e,(this.length>1||Q.test(d))&&P.test(a)&&(e=e.reverse());return this.pushStack(e,a,g.join(","))}}),f.extend({filter:function(a,b,c){c&&(a=":not("+a+")");return b.length===1?f.find.matchesSelector(b[0],a)?[b[0]]:[]:f.find.matches(a,b)},dir:function(a,c,d){var e=[],g=a[c];while(g&&g.nodeType!==9&&(d===b||g.nodeType!==1||!f(g).is(d)))g.nodeType===1&&e.push(g),g=g[c];return e},nth:function(a,b,c,d){b=b||1;var e=0;for(;a;a=a[c])if(a.nodeType===1&&++e===b)break;return a},sibling:function(a,b){var c=[];for(;a;a=a.nextSibling)a.nodeType===1&&a!==b&&c.push(a);return c}});var Y="abbr article aside audio canvas datalist details figcaption figure footer header hgroup mark meter nav output progress section summary time video",Z=/ jQuery\d+="(?:\d+|null)"/g,$=/^\s+/,_=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,ba=/<([\w:]+)/,bb=/<tbody/i,bc=/<|&#?\w+;/,bd=/<(?:script|style)/i,be=/<(?:script|object|embed|option|style)/i,bf=new RegExp("<(?:"+Y.replace(" ","|")+")","i"),bg=/checked\s*(?:[^=]|=\s*.checked.)/i,bh=/\/(java|ecma)script/i,bi=/^\s*<!(?:\[CDATA\[|\-\-)/,bj={option:[1,"<select multiple='multiple'>","</select>"],legend:[1,"<fieldset>","</fieldset>"],thead:[1,"<table>","</table>"],tr:[2,"<table><tbody>","</tbody></table>"],td:[3,"<table><tbody><tr>","</tr></tbody></table>"],col:[2,"<table><tbody></tbody><colgroup>","</colgroup></table>"],area:[1,"<map>","</map>"],_default:[0,"",""]},bk=X(c);bj.optgroup=bj.option,bj.tbody=bj.tfoot=bj.colgroup=bj.caption=bj.thead,bj.th=bj.td,f.support.htmlSerialize||(bj._default=[1,"div<div>","</div>"]),f.fn.extend({text:function(a){if(f.isFunction(a))return this.each(function(b){var c=f(this);c.text(a.call(this,b,c.text()))});if(typeof a!="object"&&a!==b)return this.empty().append((this[0]&&this[0].ownerDocument||c).createTextNode(a));return f.text(this)},wrapAll:function(a){if(f.isFunction(a))return this.each(function(b){f(this).wrapAll(a.call(this,b))});if(this[0]){var b=f(a,this[0].ownerDocument).eq(0).clone(!0);this[0].parentNode&&b.insertBefore(this[0]),b.map(function(){var a=this;while(a.firstChild&&a.firstChild.nodeType===1)a=a.firstChild;return a}).append(this)}return this},wrapInner:function(a){if(f.isFunction(a))return this.each(function(b){f(this).wrapInner(a.call(this,b))});return this.each(function(){var b=f(this),c=b.contents();c.length?c.wrapAll(a):b.append(a)})},wrap:function(a){return this.each(function(){f(this).wrapAll(a)})},unwrap:function(){return this.parent().each(function(){f.nodeName(this,"body")||f(this).replaceWith(this.childNodes)}).end()},append:function(){return this.domManip(arguments,!0,function(a){this.nodeType===1&&this.appendChild(a)})},prepend:function(){return this.domManip(arguments,!0,function(a){this.nodeType===1&&this.insertBefore(a,this.firstChild)})},before:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this)});if(arguments.length){var a=f(arguments[0]);a.push.apply(a,this.toArray());return this.pushStack(a,"before",arguments)}},after:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this.nextSibling)});if(arguments.length){var a=this.pushStack(this,"after"
,arguments);a.push.apply(a,f(arguments[0]).toArray());return a}},remove:function(a,b){for(var c=0,d;(d=this[c])!=null;c++)if(!a||f.filter(a,[d]).length)!b&&d.nodeType===1&&(f.cleanData(d.getElementsByTagName("*")),f.cleanData([d])),d.parentNode&&d.parentNode.removeChild(d);return this},empty:function(){for(var a=0,b;(b=this[a])!=null;a++){b.nodeType===1&&f.cleanData(b.getElementsByTagName("*"));while(b.firstChild)b.removeChild(b.firstChild)}return this},clone:function(a,b){a=a==null?!1:a,b=b==null?a:b;return this.map(function(){return f.clone(this,a,b)})},html:function(a){if(a===b)return this[0]&&this[0].nodeType===1?this[0].innerHTML.replace(Z,""):null;if(typeof a=="string"&&!bd.test(a)&&(f.support.leadingWhitespace||!$.test(a))&&!bj[(ba.exec(a)||["",""])[1].toLowerCase()]){a=a.replace(_,"<$1></$2>");try{for(var c=0,d=this.length;c<d;c++)this[c].nodeType===1&&(f.cleanData(this[c].getElementsByTagName("*")),this[c].innerHTML=a)}catch(e){this.empty().append(a)}}else f.isFunction(a)?this.each(function(b){var c=f(this);c.html(a.call(this,b,c.html()))}):this.empty().append(a);return this},replaceWith:function(a){if(this[0]&&this[0].parentNode){if(f.isFunction(a))return this.each(function(b){var c=f(this),d=c.html();c.replaceWith(a.call(this,b,d))});typeof a!="string"&&(a=f(a).detach());return this.each(function(){var b=this.nextSibling,c=this.parentNode;f(this).remove(),b?f(b).before(a):f(c).append(a)})}return this.length?this.pushStack(f(f.isFunction(a)?a():a),"replaceWith",a):this},detach:function(a){return this.remove(a,!0)},domManip:function(a,c,d){var e,g,h,i,j=a[0],k=[];if(!f.support.checkClone&&arguments.length===3&&typeof j=="string"&&bg.test(j))return this.each(function(){f(this).domManip(a,c,d,!0)});if(f.isFunction(j))return this.each(function(e){var g=f(this);a[0]=j.call(this,e,c?g.html():b),g.domManip(a,c,d)});if(this[0]){i=j&&j.parentNode,f.support.parentNode&&i&&i.nodeType===11&&i.childNodes.length===this.length?e={fragment:i}:e=f.buildFragment(a,this,k),h=e.fragment,h.childNodes.length===1?g=h=h.firstChild:g=h.firstChild;if(g){c=c&&f.nodeName(g,"tr");for(var l=0,m=this.length,n=m-1;l<m;l++)d.call(c?bl(this[l],g):this[l],e.cacheable||m>1&&l<n?f.clone(h,!0,!0):h)}k.length&&f.each(k,br)}return this}}),f.buildFragment=function(a,b,d){var e,g,h,i,j=a[0];b&&b[0]&&(i=b[0].ownerDocument||b[0]),i.createDocumentFragment||(i=c),a.length===1&&typeof j=="string"&&j.length<512&&i===c&&j.charAt(0)==="<"&&!be.test(j)&&(f.support.checkClone||!bg.test(j))&&!f.support.unknownElems&&bf.test(j)&&(g=!0,h=f.fragments[j],h&&h!==1&&(e=h)),e||(e=i.createDocumentFragment(),f.clean(a,i,e,d)),g&&(f.fragments[j]=h?e:1);return{fragment:e,cacheable:g}},f.fragments={},f.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){f.fn[a]=function(c){var d=[],e=f(c),g=this.length===1&&this[0].parentNode;if(g&&g.nodeType===11&&g.childNodes.length===1&&e.length===1){e[b](this[0]);return this}for(var h=0,i=e.length;h<i;h++){var j=(h>0?this.clone(!0):this).get();f(e[h])[b](j),d=d.concat(j)}return this.pushStack(d,a,e.selector)}}),f.extend({clone:function(a,b,c){var d=a.cloneNode(!0),e,g,h;if((!f.support.noCloneEvent||!f.support.noCloneChecked)&&(a.nodeType===1||a.nodeType===11)&&!f.isXMLDoc(a)){bn(a,d),e=bo(a),g=bo(d);for(h=0;e[h];++h)g[h]&&bn(e[h],g[h])}if(b){bm(a,d);if(c){e=bo(a),g=bo(d);for(h=0;e[h];++h)bm(e[h],g[h])}}e=g=null;return d},clean:function(a,b,d,e){var g;b=b||c,typeof b.createElement=="undefined"&&(b=b.ownerDocument||b[0]&&b[0].ownerDocument||c);var h=[],i;for(var j=0,k;(k=a[j])!=null;j++){typeof k=="number"&&(k+="");if(!k)continue;if(typeof k=="string")if(!bc.test(k))k=b.createTextNode(k);else{k=k.replace(_,"<$1></$2>");var l=(ba.exec(k)||["",""])[1].toLowerCase(),m=bj[l]||bj._default,n=m[0],o=b.createElement("div");b===c?bk.appendChild(o):X(b).appendChild(o),o.innerHTML=m[1]+k+m[2];while(n--)o=o.lastChild;if(!f.support.tbody){var p=bb.test(k),q=l==="table"&&!p?o.firstChild&&o.firstChild.childNodes:m[1]==="<table>"&&!p?o.childNodes:[];for(i=q.length-1;i>=0;--i)f.nodeName(q[i],"tbody")&&!q[i].childNodes.length&&q[i].parentNode.removeChild(q[i])}!f.support.leadingWhitespace&&$.test(k)&&o.insertBefore(b.createTextNode($.exec(k)[0]),o.firstChild),k=o.childNodes}var r;if(!f.support.appendChecked)if(k[0]&&typeof (r=k.length)=="number")for(i=0;i<r;i++)bq(k[i]);else bq(k);k.nodeType?h.push(k):h=f.merge(h,k)}if(d){g=function(a){return!a.type||bh.test(a.type)};for(j=0;h[j];j++)if(e&&f.nodeName(h[j],"script")&&(!h[j].type||h[j].type.toLowerCase()==="text/javascript"))e.push(h[j].parentNode?h[j].parentNode.removeChild(h[j]):h[j]);else{if(h[j].nodeType===1){var s=f.grep(h[j].getElementsByTagName("script"),g);h.splice.apply(h,[j+1,0].concat(s))}d.appendChild(h[j])}}return h},cleanData:function(a){var b,c,d=f.cache,e=f.event.special,g=f.support.deleteExpando;for(var h=0,i;(i=a[h])!=null;h++){if(i.nodeName&&f.noData[i.nodeName.toLowerCase()])continue;c=i[f.expando];if(c){b=d[c];if(b&&b.events){for(var j in b.events)e[j]?f.event.remove(i,j):f.removeEvent(i,j,b.handle);b.handle&&(b.handle.elem=null)}g?delete i[f.expando]:i.removeAttribute&&i.removeAttribute(f.expando),delete d[c]}}}});var bs=/alpha\([^)]*\)/i,bt=/opacity=([^)]*)/,bu=/([A-Z]|^ms)/g,bv=/^-?\d+(?:px)?$/i,bw=/^-?\d/,bx=/^([\-+])=([\-+.\de]+)/,by={position:"absolute",visibility:"hidden",display:"block"},bz=["Left","Right"],bA=["Top","Bottom"],bB,bC,bD;f.fn.css=function(a,c){if(arguments.length===2&&c===b)return this;return f.access(this,a,c,!0,function(a,c,d){return d!==b?f.style(a,c,d):f.css(a,c)})},f.extend({cssHooks:{opacity:{get:function(a,b){if(b){var c=bB(a,"opacity","opacity");return c===""?"1":c}return a.style.opacity}}},cssNumber:{fillOpacity:!0,fontWeight:!0,lineHeight:!0,opacity:!0,orphans:!0,widows:!0,zIndex:!0,zoom:!0},cssProps:{"float":f.support.cssFloat?"cssFloat":"styleFloat"},style:function(a,c,d,e){if(!!a&&a.nodeType!==3&&a.nodeType!==8&&!!a.style){var g,h,i=f.camelCase(c),j=a.style,k=f.cssHooks[i];c=f.cssProps[i]||i;if(d===b){if(k&&"get"in k&&(g=k.get(a,!1,e))!==b)return g;return j[c]}h=typeof d,h==="string"&&(g=bx.exec(d))&&(d=+(g[1]+1)*+g[2]+parseFloat(f.css(a,c)),h="number");if(d==null||h==="number"&&isNaN(d))return;h==="number"&&!f.cssNumber[i]&&(d+="px");if(!k||!("set"in k)||(d=k.set(a,d))!==b)try{j[c]=d}catch(l){}}},css:function(a,c,d){var e,g;c=f.camelCase(c),g=f.cssHooks[c],c=f.cssProps[c]||c,c==="cssFloat"&&(c="float");if(g&&"get"in g&&(e=g.get(a,!0,d))!==b)return e;if(bB)return bB(a,c)},swap:function(a,b,c){var d={};for(var e in b)d[e]=a.style[e],a.style[e]=b[e];c.call(a);for(e in b)a.style[e]=d[e]}}),f.curCSS=f.css,f.each(["height","width"],function(a,b){f.cssHooks[b]={get:function(a,c,d){var e;if(c){if(a.offsetWidth!==0)return bE(a,b,d);f.swap(a,by,function(){e=bE(a,b,d)});return e}},set:function(a,b){if(!bv.test(b))return b;b=parseFloat(b);if(b>=0)return b+"px"}}}),f.support.opacity||(f.cssHooks.opacity={get:function(a,b){return bt.test((b&&a.currentStyle?a.currentStyle.filter:a.style.filter)||"")?parseFloat(RegExp.$1)/100+"":b?"1":""},set:function(a,b){var c=a.style,d=a.currentStyle,e=f.isNumeric(b)?"alpha(opacity="+b*100+")":"",g=d&&d.filter||c.filter||"";c.zoom=1;if(b>=1&&f.trim(g.replace(bs,""))===""){c.removeAttribute("filter");if(d&&!d.filter)return}c.filter=bs.test(g)?g.replace(bs,e):g+" "+e}}),f(function(){f.support.reliableMarginRight||(f.cssHooks.marginRight={get:function(a,b){var c;f.swap(a,{display:"inline-block"},function(){b?c=bB(a,"margin-right","marginRight"):c=a.style.marginRight});return c}})}),c.defaultView&&c.defaultView.getComputedStyle&&(bC=function(a,c){var d,e,g;c=c.replace(bu,"-$1").toLowerCase();if(!(e=a.ownerDocument.defaultView))return b;if(g=e.getComputedStyle(a,null))d=g.getPropertyValue(c),d===""&&!f.contains(a.ownerDocument.documentElement,a)&&(d=f.style(a,c));return d}),c.documentElement.currentStyle&&(bD=function(a,b){var c,d,e,f=a.currentStyle&&a.currentStyle[b],g=a.style;f===null&&g&&(e=g[b])&&(f=e),!bv.test(f)&&bw.test(f)&&(c=g.left,d=a.runtimeStyle&&a.runtimeStyle.left,d&&(a.runtimeStyle.left=a.currentStyle.left),g.left=b==="fontSize"?"1em":f||0,f=g.pixelLeft+"px",g.left=c,d&&(a.runtimeStyle.left=d));return f===""?"auto":f}),bB=bC||bD,f.expr&&f.expr.filters&&(f.expr.filters.hidden=function(a){var b=a.offsetWidth,c=a.offsetHeight;return b===0&&c===0||!f.support.reliableHiddenOffsets&&(a.style&&a.style.display||f.css(a,"display"))==="none"},f.expr.filters.visible=function(a){return!f.expr.filters.hidden(a)});var bF=/%20/g,bG=/\[\]$/,bH=/\r?\n/g,bI=/#.*$/,bJ=/^(.*?):[ \t]*([^\r\n]*)\r?$/mg,bK=/^(?:color|date|datetime|datetime-local|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,bL=/^(?:about|app|app\-storage|.+\-extension|file|res|widget):$/,bM=/^(?:GET|HEAD)$/,bN=/^\/\//,bO=/\?/,bP=/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,bQ=/^(?:select|textarea)/i,bR=/\s+/,bS=/([?&])_=[^&]*/,bT=/^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/,bU=f.fn.load,bV={},bW={},bX,bY,bZ=["*/"]+["*"];try{bX=e.href}catch(b$){bX=c.createElement("a"),bX.href="",bX=bX.href}bY=bT.exec(bX.toLowerCase())||[],f.fn.extend({load:function(a,c,d){if(typeof a!="string"&&bU)return bU.apply(this,arguments);if(!this.length)return this;var e=a.indexOf(" ");if(e>=0){var g=a.slice(e,a.length);a=a.slice(0,e)}var h="GET";c&&(f.isFunction(c)?(d=c,c=b):typeof c=="object"&&(c=f.param(c,f.ajaxSettings.traditional),h="POST"));var i=this;f.ajax({url:a,type:h,dataType:"html",data:c,complete:function(a,b,c){c=a.responseText,a.isResolved()&&(a.done(function(a){c=a}),i.html(g?f("<div>").append(c.replace(bP,"")).find(g):c)),d&&i.each(d,[c,b,a])}});return this},serialize:function(){return f.param(this.serializeArray())},serializeArray:function(){return this.map(function(){return this.elements?f.makeArray(this.elements):this}).filter(function(){return this.name&&!this.disabled&&(this.checked||bQ.test(this.nodeName)||bK.test(this.type))}).map(function(a,b){var c=f(this).val();return c==null?null:f.isArray(c)?f.map(c,function(a,c){return{name:b.name,value:a.replace(bH,"\r\n")}}):{name:b.name,value:c.replace(bH,"\r\n")}}).get()}}),f.each("ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".split(" "),function(a,b){f.fn[b]=function(a){return this.bind(b,a)}}),f.each(["get","post"],function(a,c){f[c]=function(a,d,e,g){f.isFunction(d)&&(g=g||e,e=d,d=b);return f.ajax({type:c,url:a,data:d,success:e,dataType:g})}}),f.extend({getScript:function(a,c){return f.get(a,b,c,"script")},getJSON:function(a,b,c){return f.get(a,b,c,"json")},ajaxSetup:function(a,b){b?cb(a,f.ajaxSettings):(b=a,a=f.ajaxSettings),cb(a,b);return a},ajaxSettings:{url:bX,isLocal:bL.test(bY[1]),global:!0,type:"GET",contentType:"application/x-www-form-urlencoded",processData:!0,async:!0,accepts:{xml:"application/xml, text/xml",html:"text/html",text:"text/plain",json:"application/json, text/javascript","*":bZ},contents:{xml:/xml/,html:/html/,json:/json/},responseFields:{xml:"responseXML",text:"responseText"},converters:{"* text":a.String,"text html":!0,"text json":f.parseJSON,"text xml":f.parseXML},flatOptions:{context:!0,url:!0}},ajaxPrefilter:b_(bV),ajaxTransport:b_(bW),ajax:function(a,c){function w(a,c,l,m){if(s!==2){s=2,q&&clearTimeout(q),p=b,n=m||"",v.readyState=a>0?4:0;var o,r,u,w=c,x=l?cd(d,v,l):b,y,z;if(a>=200&&a<300||a===304){if(d.ifModified){if(y=v.getResponseHeader("Last-Modified"))f.lastModified[k]=y;if(z=v.getResponseHeader("Etag"))f.etag[k]=z}if(a===304)w="notmodified",o=!0;else try{r=ce(d,x),w="success",o=!0}catch(A){w="parsererror",u=A}}else{u=w;if(!w||a)w="error",a<0&&(a=0)}v.status=a,v.statusText=""+(c||w),o?h.resolveWith(e,[r,w,v]):h.rejectWith(e,[v,w,u]),v.statusCode(j),j=b,t&&g.trigger("ajax"+(o?"Success":"Error"),[v,d,o?r:u]),i.fireWith(e,[v,w]),t&&(g.trigger("ajaxComplete",[v,d]),--f.active||f.event.trigger("ajaxStop"))}}typeof a=="object"&&(c=a,a=b),c=c||{};var d=f.ajaxSetup({},c),e=d.context||d,g=e!==d&&(e.nodeType||e instanceof f)?f(e):f.event,h=f.Deferred(),i=f.Callbacks("once memory"),j=d.statusCode||{},k,l={},m={},n,o,p,q,r,s=0,t,u,v={readyState:0,setRequestHeader:function(a,b){if(!s){var c=a.toLowerCase();a=m[c]=m[c]||a,l[a]=b}return this},getAllResponseHeaders:function(){return s===2?n:null},getResponseHeader:function(a){var c;if(s===2){if(!o){o={};while(c=bJ.exec(n))o[c[1].toLowerCase()]=c[2]}c=o[a.toLowerCase()]}return c===b?null:c},overrideMimeType:function(a){s||(d.mimeType=a);return this},abort:function(a){a=a||"abort",p&&p.abort(a),w(0,a);return this}};h.promise(v),v.success=v.done,v.error=v.fail,v.complete=i.add,v.statusCode=function(a){if(a){var b;if(s<2)for(b in a)j[b]=[j[b],a[b]];else b=a[v.status],v.then(b,b)}return this},d.url=((a||d.url)+"").replace(bI,"").replace(bN,bY[1]+"//"),d.dataTypes=f.trim(d.dataType||"*").toLowerCase().split(bR),d.crossDomain==null&&(r=bT.exec(d.url.toLowerCase()),d.crossDomain=!(!r||r[1]==bY[1]&&r[2]==bY[2]&&(r[3]||(r[1]==="http:"?80:443))==(bY[3]||(bY[1]==="http:"?80:443)))),d.data&&d.processData&&typeof d.data!="string"&&(d.data=f.param(d.data,d.traditional)),ca(bV,d,c,v);if(s===2)return!1;t=d.global,d.type=d.type.toUpperCase(),d.hasContent=!bM.test(d.type),t&&f.active++===0&&f.event.trigger("ajaxStart");if(!d.hasContent){d.data&&(d.url+=(bO.test(d.url)?"&":"?")+d.data,delete d.data),k=d.url;if(d.cache===!1){var x=f.now(),y=d.url.replace(bS,"$1_="+x);d.url=y+(y===d.url?(bO.test(d.url)?"&":"?")+"_="+x:"")}}(d.data&&d.hasContent&&d.contentType!==!1||c.contentType)&&v.setRequestHeader("Content-Type",d.contentType),d.ifModified&&(k=k||d.url,f.lastModified[k]&&v.setRequestHeader("If-Modified-Since",f.lastModified[k]),f.etag[k]&&v.setRequestHeader("If-None-Match",f.etag[k])),v.setRequestHeader("Accept",d.dataTypes[0]&&d.accepts[d.dataTypes[0]]?d.accepts[d.dataTypes[0]]+(d.dataTypes[0]!=="*"?", "+bZ+"; q=0.01":""):d.accepts["*"]);for(u in d.headers)v.setRequestHeader(u,d.headers[u]);if(d.beforeSend&&(d.beforeSend.call(e,v,d)===!1||s===2)){v.abort();return!1}for(u in{success:1,error:1,complete:1})v[u](d[u]);p=ca(bW,d,c,v);if(!p)w(-1,"No Transport");else{v.readyState=1,t&&g.trigger("ajaxSend",[v,d]),d.async&&d.timeout>0&&(q=setTimeout(function(){v.abort("timeout")},d.timeout));try{s=1,p.send(l,w)}catch(z){s<2?w(-1,z):f.error(z)}}return v},param:function(a,c){var d=[],e=function(a,b){b=f.isFunction(b)?b():b,d[d.length]=encodeURIComponent(a)+"="+encodeURIComponent(b)};c===b&&(c=f.ajaxSettings.traditional);if(f.isArray(a)||a.jquery&&!f.isPlainObject(a))f.each(a,function(){e(this.name,this.value)});else for(var g in a)cc(g,a[g],c,e);return d.join("&").replace(bF,"+")}}),f.extend({active:0,lastModified:{},etag:{}});var cf=f.now(),cg=/(\=)\?(&|$)|\?\?/i;f.ajaxSetup({jsonp:"callback",jsonpCallback:function(){return f.expando+"_"+cf++}}),f.ajaxPrefilter("json jsonp",function(b,c,d){var e=b.contentType==="application/x-www-form-urlencoded"&&typeof b.data=="string";if(b.dataTypes[0]==="jsonp"||b.jsonp!==!1&&(cg.test(b.url)||e&&cg.test(b.data))){var g,h=b.jsonpCallback=f.isFunction(b.jsonpCallback)?b.jsonpCallback():b.jsonpCallback,i=a[h],j=b.url,k=b.data,l="$1"+h+"$2";b.jsonp!==!1&&(j=j.replace(cg,l),b.url===j&&(e&&(k=k.replace(cg,l)),b.data===k&&(j+=(/\?/.test(j)?"&":"?")+b.jsonp+"="+h))),b.url=j,b.data=k,a[h]=function(a){g=[a]},d.always(function(){a[h]=i,g&&f.isFunction(i)&&a[h](g[0])}),b.converters["script json"]=function(){g||f.error(h+" was not called");return g[0]},b.dataTypes[0]="json";return"script"}}),f.ajaxSetup({accepts:{script:"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"},contents:{script:/javascript|ecmascript/},converters:{"text script":function(a){f.globalEval(a);return a}}}),f.ajaxPrefilter("script",function(a){a.cache===b&&(a.cache=!1),a.crossDomain&&(a.type="GET",a.global=!1)}),f.ajaxTransport("script",function(a){if(a.crossDomain){var d,e=c.head||c.getElementsByTagName("head")[0]||c.documentElement;return{send:function(f,g){d=c.createElement("script"),d.async="async",a.scriptCharset&&(d.charset=a.scriptCharset),d.src=a.url,d.onload=d.onreadystatechange=function(a,c){if(c||!d.readyState||/loaded|complete/.test(d.readyState))d.onload=d.onreadystatechange=null,e&&d.parentNode&&e.removeChild(d),d=b,c||g(200,"success")},e.insertBefore(d,e.firstChild)},abort:function(){d&&d.onload(0,1)}}}});var ch=a.ActiveXObject?function(){for(var a in cj)cj[a](0,1)}:!1,ci=0,cj;f.ajaxSettings.xhr=a.ActiveXObject?function(){return!this.isLocal&&ck()||cl()}:ck,function(a){f.extend(f.support,{ajax:!!a,cors:!!a&&"withCredentials"in a})}(f.ajaxSettings.xhr()),f.support.ajax&&f.ajaxTransport(function(c){if(!c.crossDomain||f.support.cors){var d;return{send:function(e,g){var h=c.xhr(),i,j;c.username?h.open(c.type,c.url,c.async,c.username,c.password):h.open(c.type,c.url,c.async);if(c.xhrFields)for(j in c.xhrFields)h[j]=c.xhrFields[j];c.mimeType&&h.overrideMimeType&&h.overrideMimeType(c.mimeType),!c.crossDomain&&!e["X-Requested-With"]&&(e["X-Requested-With"]="XMLHttpRequest");try{for(j in e)h.setRequestHeader(j,e[j])}catch(k){}h.send(c.hasContent&&c.data||null),d=function(a,e){var j,k,l,m,n;try{if(d&&(e||h.readyState===4)){d=b,i&&(h.onreadystatechange=f.noop,ch&&delete cj[i]);if(e)h.readyState!==4&&h.abort();else{j=h.status,l=h.getAllResponseHeaders(),m={},n=h.responseXML,n&&n.documentElement&&(m.xml=n),m.text=h.responseText;try{k=h.statusText}catch(o){k=""}!j&&c.isLocal&&!c.crossDomain?j=m.text?200:404:j===1223&&(j=204)}}}catch(p){e||g(-1,p)}m&&g(j,k,m,l)},!c.async||h.readyState===4?d():(i=++ci,ch&&(cj||(cj={},f(a).unload(ch)),cj[i]=d),h.onreadystatechange=d)},abort:function(){d&&d(0,1)}}}});var cm={},cn,co,cp=/^(?:toggle|show|hide)$/,cq=/^([+\-]=)?([\d+.\-]+)([a-z%]*)$/i,cr,cs=[["height","marginTop","marginBottom","paddingTop","paddingBottom"],["width","marginLeft","marginRight","paddingLeft","paddingRight"],["opacity"]],ct;f.fn.extend({show:function(a,b,c){var d,e;if(a||a===0)return this.animate(cw("show",3),a,b,c);for(var g=0,h=this.length;g<h;g++)d=this[g],d.style&&(e=d.style.display,!f._data(d,"olddisplay")&&e==="none"&&(e=d.style.display=""),e===""&&f.css(d,"display")==="none"&&f._data(d,"olddisplay",cx(d.nodeName)));for(g=0;g<h;g++){d=this[g];if(d.style){e=d.style.display;if(e===""||e==="none")d.style.display=f._data(d,"olddisplay")||""}}return this},hide:function(a,b,c){if(a||a===0)return this.animate(cw("hide",3),a,b,c);var d,e,g=0,h=this.length;for(;g<h;g++)d=this[g],d.style&&(e=f.css(d,"display"),e!=="none"&&!f._data(d,"olddisplay")&&f._data(d,"olddisplay",e));for(g=0;g<h;g++)this[g].style&&(this[g].style.display="none");return this},_toggle:f.fn.toggle,toggle:function(a,b,c){var d=typeof a=="boolean";f.isFunction(a)&&f.isFunction(b)?this._toggle.apply(this,arguments):a==null||d?this.each(function(){var b=d?a:f(this).is(":hidden");f(this)[b?"show":"hide"]()}):this.animate(cw("toggle",3),a,b,c);return this},fadeTo:function(a,b,c,d){return this.filter(":hidden").css("opacity",0).show().end().animate({opacity:b},a,c,d)},animate:function(a,b,c,d){function g(){e.queue===!1&&f._mark(this);var b=f.extend({},e),c=this.nodeType===1,d=c&&f(this).is(":hidden"),g,h,i,j,k,l,m,n,o;b.animatedProperties={};for(i in a){g=f.camelCase(i),i!==g&&(a[g]=a[i],delete a[i]),h=a[g],f.isArray(h)?(b.animatedProperties[g]=h[1],h=a[g]=h[0]):b.animatedProperties[g]=b.specialEasing&&b.specialEasing[g]||b.easing||"swing";if(h==="hide"&&d||h==="show"&&!d)return b.complete.call(this);c&&(g==="height"||g==="width")&&(b.overflow=[this.style.overflow,this.style.overflowX,this.style.overflowY],f.css(this,"display")==="inline"&&f.css(this,"float")==="none"&&(!f.support.inlineBlockNeedsLayout||cx(this.nodeName)==="inline"?this.style.display="inline-block":this.style.zoom=1))}b.overflow!=null&&(this.style.overflow="hidden");for(i in a)j=new f.fx(this,b,i),h=a[i],cp.test(h)?(o=f._data(this,"toggle"+i)||(h==="toggle"?d?"show":"hide":0),o?(f._data(this,"toggle"+i,o==="show"?"hide":"show"),j[o]()):j[h]()):(k=cq.exec(h),l=j.cur(),k?(m=parseFloat(k[2]),n=k[3]||(f.cssNumber[i]?"":"px"),n!=="px"&&(f.style(this,i,(m||1)+n),l=(m||1)/j.cur()*l,f.style(this,i,l+n)),k[1]&&(m=(k[1]==="-="?-1:1)*m+l),j.custom(l,m,n)):j.custom(l,h,""));return!0}var e=f.speed(b,c,d);if(f.isEmptyObject(a))return this.each(e.complete,[!1]);a=f.extend({},a);return e.queue===!1?this.each(g):this.queue(e.queue,g)},stop:function(a,c,d){typeof a!="string"&&(d=c,c=a,a=b),c&&a!==!1&&this.queue(a||"fx",[]);return this.each(function(){function h(a,b,c){var e=b[c];f.removeData(a,c,!0),e.stop(d)}var b,c=!1,e=f.timers,g=f._data(this);d||f._unmark(!0,this);if(a==null)for(b in g)g[b].stop&&b.indexOf(".run")===b.length-4&&h(this,g,b);else g[b=a+".run"]&&g[b].stop&&h(this,g,b);for(b=e.length;b--;)e[b].elem===this&&(a==null||e[b].queue===a)&&(d?e[b](!0):e[b].saveState(),c=!0,e.splice(b,1));(!d||!c)&&f.dequeue(this,a)})}}),f.each({slideDown:cw("show",1),slideUp:cw("hide",1),slideToggle:cw("toggle",1),fadeIn:{opacity:"show"},fadeOut:{opacity:"hide"},fadeToggle:{opacity:"toggle"}},function(a,b){f.fn[a]=function(a,c,d){return this.animate(b,a,c,d)}}),f.extend({speed:function(a,b,c){var d=a&&typeof a=="object"?f.extend({},a):{complete:c||!c&&b||f.isFunction(a)&&a,duration:a,easing:c&&b||b&&!f.isFunction(b)&&b};d.duration=f.fx.off?0:typeof d.duration=="number"?d.duration:d.duration in f.fx.speeds?f.fx.speeds[d.duration]:f.fx.speeds._default;if(d.queue==null||d.queue===!0)d.queue="fx";d.old=d.complete,d.complete=function(a){f.isFunction(d.old)&&d.old.call(this),d.queue?f.dequeue(this,d.queue):a!==!1&&f._unmark(this)};return d},easing:{linear:function(a,b,c,d){return c+d*a},swing:function(a,b,c,d){return(-Math.cos(a*Math.PI)/2+.5)*d+c}},timers:[],fx:function(a,b,c){this.options=b,this.elem=a,this.prop=c,b.orig=b.orig||{}}}),f.fx.prototype={update:function(){this.options.step&&this.options.step.call(this.elem,this.now,this),(f.fx.step[this.prop]||f.fx.step._default)(this)},cur:function(){if(this.elem[this.prop]!=null&&(!this.elem.style||this.elem.style[this.prop]==null))return this.elem[this.prop];var a,b=f.css(this.elem,this.prop);return isNaN(a=parseFloat(b))?!b||b==="auto"?0:b:a},custom:function(a,c,d){function h(a){return e.step(a)}var e=this,g=f.fx;this.startTime=ct||cu(),this.end=c,this.now=this.start=a,this.pos=this.state=0,this.unit=d||this.unit||(f.cssNumber[this.prop]?"":"px"),h.queue=this.options.queue,h.elem=this.elem,h.saveState=function(){e.options.hide&&f._data(e.elem,"fxshow"+e.prop)===b&&f._data(e.elem,"fxshow"+e.prop,e.start)},h()&&f.timers.push(h)&&!cr&&(cr=setInterval(g.tick,g.interval))},show:function(){var a=f._data(this.elem,"fxshow"+this.prop);this.options.orig[this.prop]=a||f.style(this.elem,this.prop),this.options.show=!0,a!==b?this.custom(this.cur(),a):this.custom(this.prop==="width"||this.prop==="height"?1:0,this.cur()),f(this.elem).show()},hide:function(){this.options.orig[this.prop]=f._data(this.elem,"fxshow"+this.prop)||f.style(this.elem,this.prop),this.options.hide=!0,this.custom(this.cur(),0)},step:function(a){var b,c,d,e=ct||cu(),g=!0,h=this.elem,i=this.options;if(a||e>=i.duration+this.startTime){this.now=this.end,this.pos=this.state=1,this.update(),i.animatedProperties[this.prop]=!0;for(b in i.animatedProperties)i.animatedProperties[b]!==!0&&(g=!1);if(g){i.overflow!=null&&!f.support.shrinkWrapBlocks&&f.each(["","X","Y"],function(a,b){h.style["overflow"+b]=i.overflow[a]}),i.hide&&f(h).hide();if(i.hide||i.show)for(b in i.animatedProperties)f.style(h,b,i.orig[b]),f.removeData(h,"fxshow"+b,!0),f.removeData(h,"toggle"+b,!0);d=i.complete,d&&(i.complete=!1,d.call(h))}return!1}i.duration==Infinity?this.now=e:(c=e-this.startTime,this.state=c/i.duration,this.pos=f.easing[i.animatedProperties[this.prop]](this.state,c,0,1,i.duration),this.now=this.start+(this.end-this.start)*this.pos),this.update();return!0}},f.extend(f.fx,{tick:function(){var a,b=f.timers,c=0;for(;c<b.length;c++)a=b[c],!a()&&b[c]===a&&b.splice(c--,1);b.length||f.fx.stop()},interval:13,stop:function(){clearInterval(cr),cr=null},speeds:{slow:600,fast:200,_default:400},step:{opacity:function(a){f.style(a.elem,"opacity",a.now)},_default:function(a){a.elem.style&&a.elem.style[a.prop]!=null?a.elem.style[a.prop]=a.now+a.unit:a.elem[a.prop]=a.now}}}),f.each(["width","height"],function(a,b){f.fx.step[b]=function(a){f.style(a.elem,b,Math.max(0,a.now))}}),f.expr&&f.expr.filters&&(f.expr.filters.animated=function(a){return f.grep(f.timers,function(b){return a===b.elem}).length});var cy=/^t(?:able|d|h)$/i,cz=/^(?:body|html)$/i;"getBoundingClientRect"in c.documentElement?f.fn.offset=function(a){var b=this[0],c;if(a)return this.each(function(b){f.offset.setOffset(this,a,b)});if(!b||!b.ownerDocument)return null;if(b===b.ownerDocument.body)return f.offset.bodyOffset(b);try{c=b.getBoundingClientRect()}catch(d){}var e=b.ownerDocument,g=e.documentElement;if(!c||!f.contains(g,b))return c?{top:c.top,left:c.left}:{top:0,left:0};var h=e.body,i=cA(e),j=g.clientTop||h.clientTop||0,k=g.clientLeft||h.clientLeft||0,l=i.pageYOffset||f.support.boxModel&&g.scrollTop||h.scrollTop,m=i.pageXOffset||f.support.boxModel&&g.scrollLeft||h.scrollLeft,n=c.top+l-j,o=c.left+m-k;return{top:n,left:o}}:f.fn.offset=function(a){var b=this[0];if(a)return this.each(function(b){f.offset.setOffset(this,a,b)});if(!b||!b.ownerDocument)return null;if(b===b.ownerDocument.body)return f.offset.bodyOffset(b);var c,d=b.offsetParent,e=b,g=b.ownerDocument,h=g.documentElement,i=g.body,j=g.defaultView,k=j?j.getComputedStyle(b,null):b.currentStyle,l=b.offsetTop,m=b.offsetLeft;while((b=b.parentNode)&&b!==i&&b!==h){if(f.support.fixedPosition&&k.position==="fixed")break;c=j?j.getComputedStyle(b,null):b.currentStyle,l-=b.scrollTop,m-=b.scrollLeft,b===d&&(l+=b.offsetTop,m+=b.offsetLeft,f.support.doesNotAddBorder&&(!f.support.doesAddBorderForTableAndCells||!cy.test(b.nodeName))&&(l+=parseFloat(c.borderTopWidth)||0,m+=parseFloat(c.borderLeftWidth)||0),e=d,d=b.offsetParent),f.support.subtractsBorderForOverflowNotVisible&&c.overflow!=="visible"&&(l+=parseFloat(c.borderTopWidth)||0,m+=parseFloat(c.borderLeftWidth)||0),k=c}if(k.position==="relative"||k.position==="static")l+=i.offsetTop,m+=i.offsetLeft;f.support.fixedPosition&&k.position==="fixed"&&(l+=Math.max(h.scrollTop,i.scrollTop),m+=Math.max(h.scrollLeft,i.scrollLeft));return{top:l,left:m}},f.offset={bodyOffset:function(a){var b=a.offsetTop,c=a.offsetLeft;f.support.doesNotIncludeMarginInBodyOffset&&(b+=parseFloat(f.css(a,"marginTop"))||0,c+=parseFloat(f.css(a,"marginLeft"))||0);return{top:b,left:c}},setOffset:function(a,b,c){var d=f.css(a,"position");d==="static"&&(a.style.position="relative");var e=f(a),g=e.offset(),h=f.css(a,"top"),i=f.css(a,"left"),j=(d==="absolute"||d==="fixed")&&f.inArray("auto",[h,i])>-1,k={},l={},m,n;j?(l=e.position(),m=l.top,n=l.left):(m=parseFloat(h)||0,n=parseFloat(i)||0),f.isFunction(b)&&(b=b.call(a,c,g)),b.top!=null&&(k.top=b.top-g.top+m),b.left!=null&&(k.left=b.left-g.left+n),"using"in b?b.using.call(a,k):e.css(k)}},f.fn.extend({position:function(){if(!this[0])return null;var a=this[0],b=this.offsetParent(),c=this.offset(),d=cz.test(b[0].nodeName)?{top:0,left:0}:b.offset();c.top-=parseFloat(f.css(a,"marginTop"))||0,c.left-=parseFloat(f.css(a,"marginLeft"))||0,d.top+=parseFloat(f.css(b[0],"borderTopWidth"))||0,d.left+=parseFloat(f.css(b[0],"borderLeftWidth"))||0;return{top:c.top-d.top,left:c.left-d.left}},offsetParent:function(){return this.map(function(){var a=this.offsetParent||c.body;while(a&&!cz.test(a.nodeName)&&f.css(a,"position")==="static")a=a.offsetParent;return a})}}),f.each(["Left","Top"],function(a,c){var d="scroll"+c;f.fn[d]=function(c){var e,g;if(c===b){e=this[0];if(!e)return null;g=cA(e);return g?"pageXOffset"in g?g[a?"pageYOffset":"pageXOffset"]:f.support.boxModel&&g.document.documentElement[d]||g.document.body[d]:e[d]}return this.each(function(){g=cA(this),g?g.scrollTo(a?f(g).scrollLeft():c,a?c:f(g).scrollTop()):this[d]=c})}}),f.each(["Height","Width"],function(a,c){var d=c.toLowerCase();f.fn["inner"+c]=function(){var a=this[0];return a?a.style?parseFloat(f.css(a,d,"padding")):this[d]():null},f.fn["outer"+c]=function(a){var b=this[0];return b?b.style?parseFloat(f.css(b,d,a?"margin":"border")):this[d]():null},f.fn[d]=function(a){var e=this[0];if(!e)return a==null?null:this;if(f.isFunction(a))return this.each(function(b){var c=f(this);c[d](a.call(this,b,c[d]()))});if(f.isWindow(e)){var g=e.document.documentElement["client"+c],h=e.document.body;return e.document.compatMode==="CSS1Compat"&&g||h&&h["client"+c]||g}if(e.nodeType===9)return Math.max(e.documentElement["client"+c],e.body["scroll"+c],e.documentElement["scroll"+c],e.body["offset"+c],e.documentElement["offset"+c]);if(a===b){var i=f.css(e,d),j=parseFloat(i);return f.isNumeric(j)?j:i}return this.css(d,typeof a=="string"?a:a+"px")}}),a.jQuery=a.$=f})(window);
    // to avoid lib conflict(release the $ and jQuery variables)
    tagtoo_jQuery = jQuery.noConflict(true);
}
else{
    tagtoo_jQuery = jQuery;
}


function md5 (str) {
    // http://kevin.vanzonneveld.net
    // +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
    // + namespaced by: Michael White (http://getsprink.com)
    // +    tweaked by: Jack
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // -    depends on: utf8_encode
    // *     example 1: md5('Kevin van Zonneveld');
    // *     returns 1: '6e658d4bfcb59cc13f96c14450ac40b9'
    var xl;

    var rotateLeft = function (lValue, iShiftBits) {
        return (lValue << iShiftBits) | (lValue >>> (32 - iShiftBits));
    };

    var addUnsigned = function (lX, lY) {
        var lX4, lY4, lX8, lY8, lResult;
        lX8 = (lX & 0x80000000);
        lY8 = (lY & 0x80000000);
        lX4 = (lX & 0x40000000);
        lY4 = (lY & 0x40000000);
        lResult = (lX & 0x3FFFFFFF) + (lY & 0x3FFFFFFF);
        if (lX4 & lY4) {
            return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
        }
        if (lX4 | lY4) {
            if (lResult & 0x40000000) {
                return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);
            } else {
                return (lResult ^ 0x40000000 ^ lX8 ^ lY8);
            }
        } else {
            return (lResult ^ lX8 ^ lY8);
        }
    };

    var _F = function (x, y, z) {
        return (x & y) | ((~x) & z);
    };
    var _G = function (x, y, z) {
        return (x & z) | (y & (~z));
    };
    var _H = function (x, y, z) {
        return (x ^ y ^ z);
    };
    var _I = function (x, y, z) {
        return (y ^ (x | (~z)));
    };

    var _FF = function (a, b, c, d, x, s, ac) {
        a = addUnsigned(a, addUnsigned(addUnsigned(_F(b, c, d), x), ac));
        return addUnsigned(rotateLeft(a, s), b);
    };

    var _GG = function (a, b, c, d, x, s, ac) {
        a = addUnsigned(a, addUnsigned(addUnsigned(_G(b, c, d), x), ac));
        return addUnsigned(rotateLeft(a, s), b);
    };

    var _HH = function (a, b, c, d, x, s, ac) {
        a = addUnsigned(a, addUnsigned(addUnsigned(_H(b, c, d), x), ac));
        return addUnsigned(rotateLeft(a, s), b);
    };

    var _II = function (a, b, c, d, x, s, ac) {
        a = addUnsigned(a, addUnsigned(addUnsigned(_I(b, c, d), x), ac));
        return addUnsigned(rotateLeft(a, s), b);
    };

    var convertToWordArray = function (str) {
        var lWordCount;
        var lMessageLength = str.length;
        var lNumberOfWords_temp1 = lMessageLength + 8;
        var lNumberOfWords_temp2 = (lNumberOfWords_temp1 - (lNumberOfWords_temp1 % 64)) / 64;
        var lNumberOfWords = (lNumberOfWords_temp2 + 1) * 16;
        var lWordArray = new Array(lNumberOfWords - 1);
        var lBytePosition = 0;
        var lByteCount = 0;
        while (lByteCount < lMessageLength) {
            lWordCount = (lByteCount - (lByteCount % 4)) / 4;
            lBytePosition = (lByteCount % 4) * 8;
            lWordArray[lWordCount] = (lWordArray[lWordCount] | (str.charCodeAt(lByteCount) << lBytePosition));
            lByteCount++;
        }
        lWordCount = (lByteCount - (lByteCount % 4)) / 4;
        lBytePosition = (lByteCount % 4) * 8;
        lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80 << lBytePosition);
        lWordArray[lNumberOfWords - 2] = lMessageLength << 3;
        lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29;
        return lWordArray;
    };

    var wordToHex = function (lValue) {
        var wordToHexValue = "",
            wordToHexValue_temp = "",
            lByte, lCount;
        for (lCount = 0; lCount <= 3; lCount++) {
            lByte = (lValue >>> (lCount * 8)) & 255;
            wordToHexValue_temp = "0" + lByte.toString(16);
            wordToHexValue = wordToHexValue + wordToHexValue_temp.substr(wordToHexValue_temp.length - 2, 2);
        }
        return wordToHexValue;
    };
    
    var utf8_encode =function (argString) {
        // http://kevin.vanzonneveld.net
        // +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
        // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
        // +   improved by: sowberry
        // +    tweaked by: Jack
        // +   bugfixed by: Onno Marsman
        // +   improved by: Yves Sucaet
        // +   bugfixed by: Onno Marsman
        // +   bugfixed by: Ulrich
        // +   bugfixed by: Rafal Kukawski
        // *     example 1: utf8_encode('Kevin van Zonneveld');
        // *     returns 1: 'Kevin van Zonneveld'
    
        if (argString === null || typeof argString === "undefined") {
            return "";
        }
    
        var string = (argString + ''); // .replace(/\r\n/g, "\n").replace(/\r/g, "\n");
        var utftext = "",
            start, end, stringl = 0;
    
        start = end = 0;
        stringl = string.length;
        for (var n = 0; n < stringl; n++) {
            var c1 = string.charCodeAt(n);
            var enc = null;
    
            if (c1 < 128) {
                end++;
            } else if (c1 > 127 && c1 < 2048) {
                enc = String.fromCharCode((c1 >> 6) | 192) + String.fromCharCode((c1 & 63) | 128);
            } else {
                enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128);
            }
            if (enc !== null) {
                if (end > start) {
                    utftext += string.slice(start, end);
                }
                utftext += enc;
                start = end = n + 1;
            }
        }
    
        if (end > start) {
            utftext += string.slice(start, stringl);
        }
        return utftext;
    }

    var x = [],
        k, AA, BB, CC, DD, a, b, c, d, S11 = 7,
        S12 = 12,
        S13 = 17,
        S14 = 22,
        S21 = 5,
        S22 = 9,
        S23 = 14,
        S24 = 20,
        S31 = 4,
        S32 = 11,
        S33 = 16,
        S34 = 23,
        S41 = 6,
        S42 = 10,
        S43 = 15,
        S44 = 21;

    str = utf8_encode(str);
    x = convertToWordArray(str);
    a = 0x67452301;
    b = 0xEFCDAB89;
    c = 0x98BADCFE;
    d = 0x10325476;

    xl = x.length;
    for (k = 0; k < xl; k += 16) {
        AA = a;
        BB = b;
        CC = c;
        DD = d;
        a = _FF(a, b, c, d, x[k + 0], S11, 0xD76AA478);
        d = _FF(d, a, b, c, x[k + 1], S12, 0xE8C7B756);
        c = _FF(c, d, a, b, x[k + 2], S13, 0x242070DB);
        b = _FF(b, c, d, a, x[k + 3], S14, 0xC1BDCEEE);
        a = _FF(a, b, c, d, x[k + 4], S11, 0xF57C0FAF);
        d = _FF(d, a, b, c, x[k + 5], S12, 0x4787C62A);
        c = _FF(c, d, a, b, x[k + 6], S13, 0xA8304613);
        b = _FF(b, c, d, a, x[k + 7], S14, 0xFD469501);
        a = _FF(a, b, c, d, x[k + 8], S11, 0x698098D8);
        d = _FF(d, a, b, c, x[k + 9], S12, 0x8B44F7AF);
        c = _FF(c, d, a, b, x[k + 10], S13, 0xFFFF5BB1);
        b = _FF(b, c, d, a, x[k + 11], S14, 0x895CD7BE);
        a = _FF(a, b, c, d, x[k + 12], S11, 0x6B901122);
        d = _FF(d, a, b, c, x[k + 13], S12, 0xFD987193);
        c = _FF(c, d, a, b, x[k + 14], S13, 0xA679438E);
        b = _FF(b, c, d, a, x[k + 15], S14, 0x49B40821);
        a = _GG(a, b, c, d, x[k + 1], S21, 0xF61E2562);
        d = _GG(d, a, b, c, x[k + 6], S22, 0xC040B340);
        c = _GG(c, d, a, b, x[k + 11], S23, 0x265E5A51);
        b = _GG(b, c, d, a, x[k + 0], S24, 0xE9B6C7AA);
        a = _GG(a, b, c, d, x[k + 5], S21, 0xD62F105D);
        d = _GG(d, a, b, c, x[k + 10], S22, 0x2441453);
        c = _GG(c, d, a, b, x[k + 15], S23, 0xD8A1E681);
        b = _GG(b, c, d, a, x[k + 4], S24, 0xE7D3FBC8);
        a = _GG(a, b, c, d, x[k + 9], S21, 0x21E1CDE6);
        d = _GG(d, a, b, c, x[k + 14], S22, 0xC33707D6);
        c = _GG(c, d, a, b, x[k + 3], S23, 0xF4D50D87);
        b = _GG(b, c, d, a, x[k + 8], S24, 0x455A14ED);
        a = _GG(a, b, c, d, x[k + 13], S21, 0xA9E3E905);
        d = _GG(d, a, b, c, x[k + 2], S22, 0xFCEFA3F8);
        c = _GG(c, d, a, b, x[k + 7], S23, 0x676F02D9);
        b = _GG(b, c, d, a, x[k + 12], S24, 0x8D2A4C8A);
        a = _HH(a, b, c, d, x[k + 5], S31, 0xFFFA3942);
        d = _HH(d, a, b, c, x[k + 8], S32, 0x8771F681);
        c = _HH(c, d, a, b, x[k + 11], S33, 0x6D9D6122);
        b = _HH(b, c, d, a, x[k + 14], S34, 0xFDE5380C);
        a = _HH(a, b, c, d, x[k + 1], S31, 0xA4BEEA44);
        d = _HH(d, a, b, c, x[k + 4], S32, 0x4BDECFA9);
        c = _HH(c, d, a, b, x[k + 7], S33, 0xF6BB4B60);
        b = _HH(b, c, d, a, x[k + 10], S34, 0xBEBFBC70);
        a = _HH(a, b, c, d, x[k + 13], S31, 0x289B7EC6);
        d = _HH(d, a, b, c, x[k + 0], S32, 0xEAA127FA);
        c = _HH(c, d, a, b, x[k + 3], S33, 0xD4EF3085);
        b = _HH(b, c, d, a, x[k + 6], S34, 0x4881D05);
        a = _HH(a, b, c, d, x[k + 9], S31, 0xD9D4D039);
        d = _HH(d, a, b, c, x[k + 12], S32, 0xE6DB99E5);
        c = _HH(c, d, a, b, x[k + 15], S33, 0x1FA27CF8);
        b = _HH(b, c, d, a, x[k + 2], S34, 0xC4AC5665);
        a = _II(a, b, c, d, x[k + 0], S41, 0xF4292244);
        d = _II(d, a, b, c, x[k + 7], S42, 0x432AFF97);
        c = _II(c, d, a, b, x[k + 14], S43, 0xAB9423A7);
        b = _II(b, c, d, a, x[k + 5], S44, 0xFC93A039);
        a = _II(a, b, c, d, x[k + 12], S41, 0x655B59C3);
        d = _II(d, a, b, c, x[k + 3], S42, 0x8F0CCC92);
        c = _II(c, d, a, b, x[k + 10], S43, 0xFFEFF47D);
        b = _II(b, c, d, a, x[k + 1], S44, 0x85845DD1);
        a = _II(a, b, c, d, x[k + 8], S41, 0x6FA87E4F);
        d = _II(d, a, b, c, x[k + 15], S42, 0xFE2CE6E0);
        c = _II(c, d, a, b, x[k + 6], S43, 0xA3014314);
        b = _II(b, c, d, a, x[k + 13], S44, 0x4E0811A1);
        a = _II(a, b, c, d, x[k + 4], S41, 0xF7537E82);
        d = _II(d, a, b, c, x[k + 11], S42, 0xBD3AF235);
        c = _II(c, d, a, b, x[k + 2], S43, 0x2AD7D2BB);
        b = _II(b, c, d, a, x[k + 9], S44, 0xEB86D391);
        a = addUnsigned(a, AA);
        b = addUnsigned(b, BB);
        c = addUnsigned(c, CC);
        d = addUnsigned(d, DD);
    }

    var temp = wordToHex(a) + wordToHex(b) + wordToHex(c) + wordToHex(d);

    return temp.toLowerCase();
}

Tagtoo.importFile = function(path, type, doc, parent_name){
	var parent_element = undefined;
	try {
			parent_element = doc.getElementsByTagName(parent_name)[0];
	}
	catch(e) {
			parent_element = doc.createElement(parent_name);
			doc.appendChild(parent_element);
	}

	// Check scripts are import already or not?
	if(type == "css") {
			for(var link in doc.getElementsByTagName("link")) {
					if(link.href && link.href.match(path)) {                                
							return;
					}
			}
			var link = doc.createElement("link");
			link.setAttribute("href", path);
			link.setAttribute("type", "text/css");
			link.setAttribute("rel", "stylesheet");
			parent_element.appendChild(link);         
	}
	else if(type == "js"){
			for(var script in doc.getElementsByTagName("script")) { 
					if(script.src && scripts.src.match(src)){                               
							return;
					}
			}
			var script = doc.createElement("script");
			script.setAttribute("src", path);
			script.setAttribute("charset", "utf8");
			parent_element.appendChild(script);       
	}
}

Tagtoo.textStrip = function(text){
	if(text.length > 6)	
		return text.substr(0,6) + "...";
	else
		return text;
}

Tagtoo.isFBLink = function(url){
	if(url != null)
		var pos = url.indexOf("http://www.facebook.com/profile.php?id=");
	else
		return false;
		
	if(pos >= 0)
		return true;
	else
		return false;
}

Tagtoo.isProductLink = function(url){
	if(url != null){
		var pos1 = url.indexOf("http://buy.yahoo.com.tw/");
		var pos2 = url.indexOf("http://tw.partner.buy.yahoo.com/");
		var womany = url.indexOf("http://www.womany.net/shop/item/");
		var ta_mode = url.indexOf("http://www.tamode.com.tw/");
	}
	else
		return false;
	
	if(pos1 >= 0 || pos2 >= 0 || womany >= 0 || ta_mode >= 0)
		return true;
	else
		return false;
}

Tagtoo.isYamLink = function(url){
    if(url != null){
		var pos = url.indexOf("http://blog.yam.com/");
	}
	else
		return false;
        
    if(pos >= 0)
		return true;
	else
		return false;
}

Tagtoo.isWretchImg = function(imgurl){
    if(imgurl.indexOf('wretch.yimg.com') > -1)
        return true;
    else
        return false;
}

Tagtoo.isYamImg = function(imgurl){
    if(imgurl.indexOf('yamedia.tw') > -1)
        return true;
    else
        return false;
}

Tagtoo.isSinaImg = function(imgurl){
    if(imgurl.indexOf('sinaimg') > -1 || imgurl.indexOf('photo.sina.com') > -1)
        return true;
    else
        return false;
}

Tagtoo.getImageExtension = function(imgurl){
    var pos = imgurl.lastIndexOf(".");
    var ext = imgurl.substr(pos);
    return ext;
}

Tagtoo.switchMeasureToInt = function(inputStr){
	return parseInt(inputStr.replace("px", ""));
}

Tagtoo.getBrowserLang = function(){
	var userLang = (navigator.language) ? navigator.language : navigator.userLanguage; 
	userLang = userLang.toLowerCase();
	if(userLang == 'zh-tw')
		return "tw";
	else
		return "en";
}

Tagtoo.imgurlProcess = function(imgurl){
		
	/* fix if image url is relative url */
	if(imgurl.indexOf('http://')!=0 && imgurl.indexOf('https://')!=0 ){
		if(imgurl.indexOf('/')==0){//check if is point to root domain
			imgurl='http://'+location.host+imgurl;
		}else if(tagtoo_jQuery('base').size()>0){
			var baseHref=tagtoo_jQuery('base').attr('href');
			if(baseHref.lastIndexOf('/')!=baseHref.length-1){
				imgurl=baseHref+'/'+imgurl;
			}else{
				imgurl=baseHref+imgurl;
			}
		}else{
			var loc=String(location);
			if(loc.lastIndexOf('/')>0){
				loc.substring(0,loc.lastIndexOf('/'));
			}else{
				loc+='/';
			}
			imgurl=loc+imgurl;
		}
	}
	imgurl=imgurl.replace( 'https://' , 'http://' );//must change to "http" to make sure same in same out
	/* double decode cause problem? anyway, decode the url to ensure that it is in ordinary state, then there is no problem to encode.
		because in some cases, the imgurl is partially already encode, some we always decode it first to avoid this case.*/
    return encodeURIComponent(decodeURIComponent(imgurl));
}

Tagtoo.isInsideVisableArea = function(imgobj){
    var imgOffset = imgobj.offset();
    // the top of the screen
    var visableAreaOffsetTop = tagtoo_jQuery(window).scrollTop();
    // the bottom of the screen
    var visableAreaOffsetBottom = visableAreaOffsetTop + tagtoo_jQuery(window).height();
    // the top of the image
    var imgOffsetTop = imgOffset.top;
    // the bottom of the image
    var imgOffsetBottom = imgOffset.top + imgobj.height();
    // let the tag data of image loaded when image close to screen, not already enter the screen.
    var bufferSize = 170;
    if(imgobj.css('display') == 'none' || imgobj.css('visibility') == 'hidden'){
        return false;
    }
    
    //var tagClass = 'tagtoo-tag-'+imgOffset.top + '-' + imgOffset.left;
    // image already in screen
    if( visableAreaOffsetBottom > imgOffsetTop && visableAreaOffsetTop < imgOffsetTop){
        return true;
    }else if( visableAreaOffsetBottom > imgOffsetBottom && visableAreaOffsetTop < imgOffsetBottom ){
        return true;
    }
    // image is about to enter scrren
    else if(visableAreaOffsetBottom > (imgOffsetTop - bufferSize) && (imgOffsetTop - bufferSize) > visableAreaOffsetTop){
        return true;
    }
    else if(visableAreaOffsetBottom > (imgOffsetBottom + bufferSize) && (imgOffsetBottom + bufferSize) > visableAreaOffsetTop){
        return true;
    }
    return false;
}
Tagtoo.setPalseEffect = function(obj){
    obj.fadeIn(700);
    obj.fadeOut(700);
}

// define variable for google analytics
var _gaq = _gaq || []; 
// google analytics tracking object
_gaq.push(['_setAccount', 'UA-18757665-1']);
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_trackPageview']);

// define global variables
// I separate requestsite & filesite temporarily, because the data transformation not complete yet!
// only tagtootest has the new scehema data 
// var TagtooSite = "http://www.tagtoo.org";
//var TagtooRequestSite = "http://tagtootest.appspot.com";

Tagtoo.weburl = document.location.href;
Tagtoo.webtitle = document.title;
var TagtooRequestSite = "";
if(Tagtoo.isYamLink(Tagtoo.weburl)){
    TagtooRequestSite = "http://yam.tagtoo.org";
}
else{
    //TagtooRequestSite = "http://www.tagtoo.org";
    //TagtooRequestSite = "http://tagtoov1.appspot.com";
    TagtooRequestSite = "http://www.tagtoo.org";
    //TagtooRequestSite = "http://tagtootest.appspot.com";
}
var TagtooFileSite = "http://www.tagtoo.org";

// There are three state, read, write, remove
// environmental variables(about executial environment and all setting about related panels)
Tagtoo.state = "read";
Tagtoo.Lang = Tagtoo.getBrowserLang();
Tagtoo.imgurl = "";
Tagtoo.imgTop;
Tagtoo.imgLeft;
Tagtoo.imgWidth;
Tagtoo.imgHeight;
Tagtoo.addImageAuth = false;
Tagtoo.queryImageAuth = true;
Tagtoo.removeImageAuth = false;
Tagtoo.TagDataLoaded = false;
Tagtoo.PanelWidth = 300;
Tagtoo.PanelHeight = 31;
// count from 1
Tagtoo.nowFriendPage = 1;
Tagtoo.FriendPageItemAmount = 200;
Tagtoo.FriendPageAmount = 0;
Tagtoo.PanelTop;
Tagtoo.PanelLeft;
// about login status
Tagtoo.username = "";
Tagtoo.uid = "";
Tagtoo.userkey = "";
Tagtoo.friendlist = new Array();
Tagtoo.friendlistSettled = false;
Tagtoo.permission;

// to avoid get tag data from server every time
Tagtoo.tagCatch = new Array();
// parameters which get from embed js tag
Tagtoo.pageOwnerKey = "";
Tagtoo.pageOwnerTraceCode = "";
// only page owner can edit
Tagtoo.authority = "private";
Tagtoo.editable = false;
Tagtoo.deletable = false;
Tagtoo.proxyServerTransmit = "";

/**
*
*  Secure Hash Algorithm (SHA1)
*  http://www.webtoolkit.info/
*
**/
 
Tagtoo.sha1 = function(msg){
	function rotate_left(n,s) {
		var t4 = ( n<<s ) | (n>>>(32-s));
		return t4;
	};
 
	function lsb_hex(val) {
		var str="";
		var i;
		var vh;
		var vl;
 
		for( i=0; i<=6; i+=2 ) {
			vh = (val>>>(i*4+4))&0x0f;
			vl = (val>>>(i*4))&0x0f;
			str += vh.toString(16) + vl.toString(16);
		}
		return str;
	};
 
	function cvt_hex(val) {
		var str="";
		var i;
		var v;
 
		for( i=7; i>=0; i-- ) {
			v = (val>>>(i*4))&0x0f;
			str += v.toString(16);
		}
		return str;
	};
 
 
	function Utf8Encode(string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	};
 
	var blockstart;
	var i, j;
	var W = new Array(80);
	var H0 = 0x67452301;
	var H1 = 0xEFCDAB89;
	var H2 = 0x98BADCFE;
	var H3 = 0x10325476;
	var H4 = 0xC3D2E1F0;
	var A, B, C, D, E;
	var temp;
 
	msg = Utf8Encode(msg);
 
	var msg_len = msg.length;
 
	var word_array = new Array();
	for( i=0; i<msg_len-3; i+=4 ) {
		j = msg.charCodeAt(i)<<24 | msg.charCodeAt(i+1)<<16 |
		msg.charCodeAt(i+2)<<8 | msg.charCodeAt(i+3);
		word_array.push( j );
	}
 
	switch( msg_len % 4 ) {
		case 0:
			i = 0x080000000;
		break;
		case 1:
			i = msg.charCodeAt(msg_len-1)<<24 | 0x0800000;
		break;
 
		case 2:
			i = msg.charCodeAt(msg_len-2)<<24 | msg.charCodeAt(msg_len-1)<<16 | 0x08000;
		break;
 
		case 3:
			i = msg.charCodeAt(msg_len-3)<<24 | msg.charCodeAt(msg_len-2)<<16 | msg.charCodeAt(msg_len-1)<<8	| 0x80;
		break;
	}
 
	word_array.push( i );
 
	while( (word_array.length % 16) != 14 ) word_array.push( 0 );
 
	word_array.push( msg_len>>>29 );
	word_array.push( (msg_len<<3)&0x0ffffffff );
 
 
	for ( blockstart=0; blockstart<word_array.length; blockstart+=16 ) {
 
		for( i=0; i<16; i++ ) W[i] = word_array[blockstart+i];
		for( i=16; i<=79; i++ ) W[i] = rotate_left(W[i-3] ^ W[i-8] ^ W[i-14] ^ W[i-16], 1);
 
		A = H0;
		B = H1;
		C = H2;
		D = H3;
		E = H4;
 
		for( i= 0; i<=19; i++ ) {
			temp = (rotate_left(A,5) + ((B&C) | (~B&D)) + E + W[i] + 0x5A827999) & 0x0ffffffff;
			E = D;
			D = C;
			C = rotate_left(B,30);
			B = A;
			A = temp;
		}
 
		for( i=20; i<=39; i++ ) {
			temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0x6ED9EBA1) & 0x0ffffffff;
			E = D;
			D = C;
			C = rotate_left(B,30);
			B = A;
			A = temp;
		}
 
		for( i=40; i<=59; i++ ) {
			temp = (rotate_left(A,5) + ((B&C) | (B&D) | (C&D)) + E + W[i] + 0x8F1BBCDC) & 0x0ffffffff;
			E = D;
			D = C;
			C = rotate_left(B,30);
			B = A;
			A = temp;
		}
 
		for( i=60; i<=79; i++ ) {
			temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0xCA62C1D6) & 0x0ffffffff;
			E = D;
			D = C;
			C = rotate_left(B,30);
			B = A;
			A = temp;
		}
 
		H0 = (H0 + A) & 0x0ffffffff;
		H1 = (H1 + B) & 0x0ffffffff;
		H2 = (H2 + C) & 0x0ffffffff;
		H3 = (H3 + D) & 0x0ffffffff;
		H4 = (H4 + E) & 0x0ffffffff;
 
	}
 
	var temp = cvt_hex(H0) + cvt_hex(H1) + cvt_hex(H2) + cvt_hex(H3) + cvt_hex(H4);
 
	return temp.toLowerCase();
 
}
Tagtoo.notification = "您已登入Tagtoo，請將滑鼠移到圖片上即可開始新增或移除標籤！";
Tagtoo.dictionary = {
	//"TAG_INPUT_PROMPT":			{"en": "Input tag or friend name", "tw": "在此輸入標籤或人名"},
	//"REFER_URL_INPUT_PROMPT":	{"en": "Input refer url", "tw": "在此輸入參考連結"},
	//"WHATS_IN_YOUR_MIND": 		{"en": "I'm thinking...", "tw": "在想什麼嗎?"},
	//"ADD_TAG_PROMPT": 			{"en": "Click the pic and input the describtion below", "tw": "請在圖片上點一下開始, 或在下方欄位輸入描述"},
	//"DESCRIB_HERE":				{"en": "Describ here", "tw": "請輸入描述"},
	//"COMMENT_HERE": 			{"en": "Comment here", "tw": "請輸入評論"},
	//"REGIONAL_TAG_PROMPT":		{"en": "Choose from your FRIENDS on Facebook or input the describtion on tag or link.", "tw": "請在標籤和參考連結輸入適當的內容，或從Facebook好友的名單點選。"},
	//"PLEASE_INPUT_COMMENT":		{"en": "Please enter the comment!", "tw": "請輸入評論!"},
	//"LOGOUT_FAIL":				{"en": "Opps, fail to log out", "tw": "登出時發生錯誤!"},
	//"CONNECT_SUCCESS":			{"en": "Already connect with Facebook", "tw": "已連結Facebook"},
	//"CONNECT_FAIL":				{"en": "You may not log in Facebook or not connect with Tagtoo", "tw": "未成功登入Facebook或尚未和本應用程式連結"},
	//"LOGINED":					{"en": "login", "tw": "已登入"},
	//"CHECK_FAIL":				{"en": "Checking fails", "tw": "檢查失敗"},
	//"ERROR_OCCUR":				{"en": "Error!", "tw": "發生錯誤!"},
	//"MESSAGE_POSTED":			{"en": "Message posted", "tw": "已成功留言"},
	//"ADDTAG_SUCCESS":			{"en": "New tag added!", "tw": "新增標籤成功"},
	//"ADDTAG_FAIL":				{"en": "Adding tag fails.", "tw": "新增標籤失敗"},
	//"NO_TAG_YET":				{"en": "This photo is no tagged yet. Be the first one?!", "tw": "本圖尚無標籤!"},
	//"ADDCOMMENT_SCCESS":		{"en": "Comments added!", "tw": " 新增評論成功"},
	//"ADDCOMMENT_FAIL":			{"en": "Adding comment fails.", "tw": " 新增評論失敗"},
	//"NO_COMMENT_YET":			{"en": "This photo is no tagged yet. Be the first one?!", "tw": "本圖尚無評論!"},
	//"ME":						{"en": "Me", "tw": "我"},
	//"SET_REFER_URL":			{"en": "add refer url", "tw": "設定網址"},
	
	"LANG":						{"en": "en", "tw": "tw"},
	"WHAT_IS_TAGTOO":			{"en": "What is it?", "tw": "這是什麼?"},
	"ADD_TAG":					{"en": "Add", "tw": "新增"},
	"DELETE_TAG":				{"en": "Del", "tw": "刪除"},
	"LOGOUT":					{"en": "Logout", "tw": "登出"},
	"LOGIN":					{"en": "Login", "tw": "登入"},
	"TAG": 						{"en": "Tag", "tw": "標籤"},
	"REFER_URL": 				{"en": "Link", "tw": "參考連結"},
	"PLEASE_INPUT_TAG":			{"en": "Please enter the tag!", "tw": "請輸入標籤!"},
	"LOGIN_FIRST":				{"en": "Please login first", "tw": "請先登入!"},
	"ADDTAG_ACCESS_DENY":		{"en": "You don't have the authority to add tag!", "tw": "你沒有加標籤的權限!"},
    "DELTAG_ACCESS_DENY":		{"en": "You don't have the authority to delete tag!", "tw": "你沒有刪除標籤的權限!"},
	"ENTER_ADD_MODE":			{"en": "Enter add mode,<br/> click on this image to add!", "tw": "進入新增模式!<br/>在圖片上點一下即可新增"},
	"ENTER_DEL_MODE":			{"en": "Enter delete mode,<br/> click on the dot you want to delete!", "tw": "進入刪除模式!<br/>在標籤上點一下即可刪除"},
	"FACEBOOK_LOGINED":			{"en": "Facebook login successfully", "tw": "已登入Tagtoo!"},
	"LOGIN_FAIL":				{"en": "Opps, fail to log in", "tw": "登入時發生錯誤!"},
	"FACEBOOK_LOGOUT":			{"en": "Facebook logout successfully", "tw": "已登出Tagtoo"},
	"POWERED_BY_TAGTOO":		{"en": "Powered by Tagtoo - http://www.tagtoo.org", "tw": "本服務由Tagtoo - http://www.tagtoo.org 提供"},
    "POWERED_BY_YAM":		    {"en": "Powered by Yam - http://blog.yam.com", "tw": "本服務由Yam天空部落 - http://blog.yam.com 提供"},
	"DELETE":					{"en": "Delete", "tw": "刪除"},
	"REMOVETAG_ACCESS_DENY":	{"en": "You don't have the authority to delete this tag!", "tw": "你沒有刪除此標籤的權限!"},
    "PREV_PAGE":	            {"en": "Previous page", "tw": "上一頁"},
	"NEXT_PAGE":	            {"en": "Next page", "tw": "下一頁"},
    "NOTIFICATION":             {"en": Tagtoo.notification, "tw": Tagtoo.notification}
};
Tagtoo.queryDictionary = function(index){
	if(Tagtoo.dictionary[index]){
		return Tagtoo.dictionary[index][Tagtoo.Lang];
	}
	else
		return index;
}
// input = {"fb_username": username, "tag": tag}
// sid = string to recognize which string should be displayed
Tagtoo.querySentence = function(sid, input){
	var fb_username = input["fb_username"];
	var tag = input["tag"];
    var total_page = input["total_page"];
    var now_page = input["now_page"];
	
	switch(sid){
        case "YOU_ARE_IN_PAGE":
            if(Tagtoo.Lang == "tw")
				return "你在" + now_page + "/" + total_page + "頁";
			else
				return "Page " + now_page + "/" + total_page + " now";
			break;
            
		case "NOTIFY_FRIEND":
			if(Tagtoo.Lang == "tw")
				return fb_username + " 在這張圖片上標記了你(妳), 過去看看吧!";
			else
				return fb_username + " is tagging you on this photo, go check it out!";
			break;
			
		case "SHARE_TO_MY_WALL":
			if(Tagtoo.Lang == "tw")
				return fb_username + " 正在看這張圖片, 一起過去看看吧!";
			else
				return fb_username + " is wachting this photo. Go check it out too.";
			break;
			
		case "INTERESTED_IN":
			if(Tagtoo.Lang == "tw")
				return fb_username + ' 對"' + tag + '"有興趣, 過去看看吧!';
			else
				return fb_username + "is intersted in " + tag + ". Go check it out as well!";
			break;
	}
}
// Cross Domain Ajax Solution set

// Constructor: pass a REST request URL to the constructor
function JSONscriptRequest(fullUrl) {
	// REST request path
	this.fullUrl = fullUrl;
	// Keep IE from caching requests
	this.noCacheIE = '&noCacheIE=' + (new Date()).getTime();
	// Get the DOM location to put the script tag
	this.headLoc = document.getElementsByTagName("head").item(0);
	// Generate a unique script tag id
	this.scriptId = 'JscriptId' + JSONscriptRequest.scriptCounter++;
}

// Static script ID counter
JSONscriptRequest.scriptCounter = 1;

// buildScriptTag method
JSONscriptRequest.prototype.buildScriptTag = function() {
	// Create the script tag
	this.scriptObj = document.createElement("script");

	// Add script object attributes
	this.scriptObj.setAttribute("type", "text/javascript");
	this.scriptObj.setAttribute("charset", "utf-8");
	this.scriptObj.setAttribute("src", this.fullUrl + this.noCacheIE);
	this.scriptObj.setAttribute("id", this.scriptId);
}

// addScriptTag method
JSONscriptRequest.prototype.addScriptTag = function() {
	// Create the script tag
	this.headLoc.appendChild(this.scriptObj);
}

// removeScriptTag method
JSONscriptRequest.prototype.removeScriptTag = function() {
	// Destroy the script tag
	if (this.scriptObj)
		this.headLoc.removeChild(this.scriptObj);
}
// cross domain ajax solution
Tagtoo.ajaxCrossDomain = function(req, variable, callback){
	var req = req + "?" + variable + "&callback=" + callback;
	bObj = new JSONscriptRequest(req);
	bObj.buildScriptTag();
	bObj.addScriptTag();
}

//Tagtoo.importFile(TagtooFileSite+"/plugin/js/cross-domain-ajax.js", "js", document, "head");
Tagtoo.importFile(TagtooFileSite+"/plugin/js/3rd-party/base64.js", "js", document, "head");
Tagtoo.importFile(TagtooFileSite+"/plugin/css/new/" + Tagtoo.Lang + "/plugin.css", "css", document, "head");
	

Tagtoo.panel_loggined = '<div id="logo_button" title="' + Tagtoo.queryDictionary('WHAT_IS_TAGTOO') + '" class="tagtoo_button"></div>';
Tagtoo.panel_loggined += '<div id="add_tag_button" class="tagtoo_button"><div class="tagtoo_button_text_area">' + Tagtoo.queryDictionary('ADD_TAG') + '</div></div>';
Tagtoo.panel_loggined += '<div id="del_tag_button" class="tagtoo_button"><div class="tagtoo_button_text_area">' + Tagtoo.queryDictionary('DELETE_TAG') + '</div></div>';
Tagtoo.panel_loggined += '<div class="dividing_line"></div>';
Tagtoo.panel_loggined += '<div id="fb_button" class="tagtoo_button">';
Tagtoo.panel_loggined += '	<div id="fb_button-logo"></div>';
Tagtoo.panel_loggined += '	<div id="facebook_logout_button" class="fb_button-text">' + Tagtoo.queryDictionary('LOGOUT') + '</div>';
Tagtoo.panel_loggined += '</div>';

Tagtoo.panel_loggined_short = '<div id="logo_button" title="' + Tagtoo.queryDictionary('WHAT_IS_TAGTOO') + '" class="tagtoo_button"></div>';
Tagtoo.panel_loggined_short += '<div class="dividing_line"></div>';
Tagtoo.panel_loggined_short += '<div id="fb_button" class="tagtoo_button">';
Tagtoo.panel_loggined_short += '	<div id="fb_button-logo"></div>';
Tagtoo.panel_loggined_short += '	<div id="facebook_logout_button" class="fb_button-text">' + Tagtoo.queryDictionary('LOGOUT') + '</div>';
Tagtoo.panel_loggined_short += '</div>';

Tagtoo.panel = '<div id="logo_button" title="' + Tagtoo.queryDictionary('WHAT_IS_TAGTOO') + '" class="tagtoo_button"></div>';
Tagtoo.panel += '<div class="dividing_line"></div>';
Tagtoo.panel += '<div id="fb_button" class="tagtoo_button">';
Tagtoo.panel += '	<div id="fb_button-logo"></div>';
Tagtoo.panel += '	<div id="facebook_login_button" class="fb_button-text">' + Tagtoo.queryDictionary('LOGIN') + '</div>';
Tagtoo.panel += '</div>';

Tagtoo.friendlist_panel = '<div id="tagtoo_friendlist" style="position: absolute; display: none;">';
Tagtoo.friendlist_panel += '<div id="tagtoo_friendlist_top">';
Tagtoo.friendlist_panel += '<div id="tagtoo_facebook_username"></div>';
Tagtoo.friendlist_panel += '<div style="height: 3px; clear: both"></div>';
Tagtoo.friendlist_panel += '<div id="tagtoo_regional_tag">';
Tagtoo.friendlist_panel += '<div id="tagtoo_regional_tag_input_prompt">' + Tagtoo.queryDictionary('TAG') + '</div>';
Tagtoo.friendlist_panel += '<div style="float: left; width: 50px; color: white; font-size: 9pt"><input size="22" style="font-size: 8pt" id="regional_tag_input_field"></div>';
Tagtoo.friendlist_panel += '</div>';
Tagtoo.friendlist_panel += '<div style="height: 8px; clear: both"></div>';
Tagtoo.friendlist_panel += '<div id="refer_url">';
Tagtoo.friendlist_panel += '<div id="refer_url_input_prompt">' + Tagtoo.queryDictionary('REFER_URL') + '</div>';
Tagtoo.friendlist_panel += '<div style="float: left; width: 50px; color: white; font-size: 9pt"><input size="22" style="font-size: 8pt" id="refer_url_input_field"></div>';
Tagtoo.friendlist_panel += '</div>';
Tagtoo.friendlist_panel += '</div>';
Tagtoo.friendlist_panel += '<div id="friendlist_middle">';
Tagtoo.friendlist_panel += '</div>';
Tagtoo.friendlist_panel += '<div id="friendlist_bottom">';
Tagtoo.friendlist_panel += '<div id="friendlist_submit" class="tagtoo_button"></div>';
Tagtoo.friendlist_panel += '<div id="friendlist_cancel" class="tagtoo_button"></div>';
Tagtoo.friendlist_panel += '</div>';
Tagtoo.friendlist_panel += '</div>';

Tagtoo.temp_dot = '<div id="tagtoo_temp_dot"></div>';

Tagtoo.prompt_panel = '<div id="prompt_panel" style="display: none"></div>';

Tagtoo.img_mask = '<div id="tagtoo_img_mask" style="display: none"></div>';
Tagtoo.queryTagCatch = function(imgID){
    //alert("queryTagCatch:" + imgID);
	for(var i in Tagtoo.tagCatch){
		if(Tagtoo.tagCatch[i]['imgID'] == imgID ){
            //alert("queryTagCatch--imgID:" + imgID);
			return {"pos": i, "data": Tagtoo.tagCatch[i]['data']};
        }
	}
	return false;
}
// to avoid conflict, once find there is an older data mapping to the same imgurl, clean it before push new data in.
Tagtoo.putTagDataToCatch = function(imgID, data){
    
	var result = Tagtoo.queryTagCatch(imgID);
    //alert("putTagDataToCatch:"+imgID);
	if(result == false){
		Tagtoo.tagCatch.push({"imgID": imgID, "data": data});
	}
    // overwrite the data in catch
	else{
		var pos = result['pos'];
		Tagtoo.tagCatch[pos]['data'] = data;
	}
}
Tagtoo.getImgObjByID = function(imgID){
    var imgclass = "tagtoo_imgobj" + imgID;
    return tagtoo_jQuery('img[class*="'+imgclass+'"]');
}
Tagtoo.preloadTagData = function(imgID){
    var imgObj = Tagtoo.getImgObjByID(imgID);
    if(imgObj.data('loaded') != 'loaded'){
        var QueryImageAPI = TagtooRequestSite + "/api/QueryImage/";
        var imgurl = imgObj.attr('src');
        var width = imgObj.width();
        var height = imgObj.height();
        var top = imgObj.offset().top;
        var left = imgObj.offset().left;
        // load gif to indicate tag data of this image is not loaded
        if(tagtoo_jQuery("#tagtoo_tag_load"+imgID).length == 0)
            tagtoo_jQuery("body").append("<div id='tagtoo_tag_load"+imgID+"' class='tagtoo_tag_load' style='text-align: center; position: absolute; width: 220px; height: 50px; left: "+(left+width/2-110)+"px; top: "+(top+height/2-25)+"px; background: url("+TagtooRequestSite+"/plugin/img/ajax-loader.gif) no-repeat scroll 0% 85% transparent; background-color: white; font-size: 10pt; color: black; padding: 0px; padding-top: 10px; -webkit-border-radius: 8px; -moz-border-radius: 8px; border-radius: 8px;'>Tagtoo 圖片標籤資料讀取中...</div>");
        Tagtoo.ajaxCrossDomain(QueryImageAPI, "imgurl=" + Tagtoo.imgurlProcess(imgurl) + "&secret=" + Tagtoo.pageOwnerKey + "&trace_code=" + Tagtoo.pageOwnerTraceCode + "&imgID=" + imgID, "Tagtoo.setPreloadTagData");
    }
}
Tagtoo.setPreloadTagData = function(response){
    var status = response.status;
    if(status == true){
        var imgID = response.imgID;
        //alert("setPreloadTagData--imgID:"+response.imgID);
        var imgObj = Tagtoo.getImgObjByID(imgID);
        var top = imgObj.offset().top;
        var left = imgObj.offset().left;
        if(response.tags.length > 0 && tagtoo_jQuery("#tagtoo_tag_hint"+imgID).length == 0){
             tagtoo_jQuery("body").append("<div id='tagtoo_tag_hint"+imgID+"' class='tagtoo_tag_hint' style='left: "+left+"px; top: "+top+"px'></div>");
             var interval = window.setInterval(function(){Tagtoo.setPalseEffect(tagtoo_jQuery("#tagtoo_tag_hint"+imgID))}, 1500);
             tagtoo_jQuery("#tagtoo_imgobj"+imgID).data('setInterval', interval);
             
             //alert("setPreloadTagData:"+tagtoo_jQuery("#tagtoo_imgobj"+imgID).data('setInterval'));
             //tagtoo_jQuery("#tagtoo_tag_hint"+imgID).data('setInterval', setInterval(function(){Tagtoo.setPalseEffect(tagtoo_jQuery("#tagtoo_tag_hint"+imgID))}, 1000))
        }
        Tagtoo.putTagDataToCatch(imgID, response);
        imgObj.data('loaded', 'loaded');
        tagtoo_jQuery("#tagtoo_tag_load"+imgID).fadeOut();
    }
    else{
        alert("讀取標籤資訊失敗!");
    }
}
Tagtoo.LoadTagData = function(option, imgID){
	//var imgurl = tagtoo_jQuery(".tagtoo_plugin_active_img").attr('src');
	// force to reload
	if(option == 'reload'){
        var QueryImageAPI = TagtooRequestSite + "/api/QueryImage/";
        var imgObj = Tagtoo.getImgObjByID(imgID);
        var imgurl = imgObj.attr('src');
        Tagtoo.ajaxCrossDomain(QueryImageAPI, "imgurl=" + Tagtoo.imgurlProcess(imgurl) + "&secret=" + Tagtoo.pageOwnerKey + "&trace_code=" + Tagtoo.pageOwnerTraceCode + "&imgID=" + imgID, "Tagtoo.SetHotTags");
		//Tagtoo.ajaxCrossDomain(QueryImageAPI, "imgurl=" + decodeURIComponent(imgurl) + "&secret=" + Tagtoo.pageOwnerKey, "Tagtoo.SetHotTags");
	}
	// normal case, I checkout the catch first
	else{
        //alert("LoadTagData:" + imgID);
		// if there is data about this image in catch
        // if tags already created
        if(tagtoo_jQuery(".tagtoo_regional_tag_content" + imgID).length > 0){
            //alert("tag already exist!");
            tagtoo_jQuery(".tagtoo_regional_tag_content" + imgID).show();
        }
        else{
            //alert("need to create tag first!");
            var result = Tagtoo.queryTagCatch(imgID);
            // if catch data != undefined(which means data already loaded in catch), create the tags, otherwise check catch at the next time mouseover image
            // if we don't do this check, when excute CreateTags function, will cause (result)undefine error
            if(result){
                Tagtoo.CreateTags(result['data']);
            }
            else{
                // try 5 times, then give up to avoid unlimit block by abnormal ajax request!
                var times = 0;
                var intervalID = setInterval(function(){
                    result = Tagtoo.queryTagCatch(imgID);
                    if(result){
                        Tagtoo.CreateTags(result['data']);
                        clearInterval(intervalID);
                    }
                    if(times > 5){
                        // give up!
                        clearInterval(intervalID);
                        // try to load data again!
                        Tagtoo.preloadTagData(imgID);
                    }
                    times++;
                }, 1300);
            }
        }
        /*
		if(result != false){
            //alert("result is not false");
			//var tag_data = result['data'];
			//Tagtoo.SetHotTags(tag_data);
            
		}
		// if no data about this image, get it from server
		else{
            Tagtoo.SetHotTags();
            //alert("result is false");
            Tagtoo.ajaxCrossDomain(QueryImageAPI, "imgurl=" + Tagtoo.imgurlProcess(imgurl) + "&secret=" + Tagtoo.pageOwnerKey + "&imgID=" + imgID, "Tagtoo.SetHotTags");
		}*/
	}
}

Tagtoo.AddImage = function(mode, data){
	var tagtext = data['tagtext'];
	var AddImageAPI = TagtooRequestSite + "/api/AddImage/";
    // there is no race condition when add image mode(mousemove won't disturb the .tagtoo_plugin_active_img class)
	var imgID = tagtoo_jQuery(".tagtoo_plugin_active_img").data('tagtoo_imgobj');
    
	if(tagtext == ''){
		alert(Tagtoo.queryDictionary('PLEASE_INPUT_TAG'));
		return;
	}
	else{
		if(mode == 'description'){
			ajaxCrossDomain(AddImageAPI, "imgurl=" + Tagtoo.imgurlProcess(Tagtoo.imgurl) + "&tag=" + encodeURIComponent(tagtext) + "&secret=" + Tagtoo.pageOwnerKey + "&imgID=" + imgID, "Tagtoo.AddImageCallback");
		}
		else if(mode == 'dot'){
			var refer_url = data['refer_url'];
            // url replace rule No.1
            if(refer_url.indexOf('http://buy.yahoo.com.tw/gdsale/gdsale.asp?gdid=') >= 0){
                refer_url = refer_url.replace("http://buy.yahoo.com.tw/gdsale/gdsale.asp?gdid=", "");
                var gdid = refer_url.replace(/([0-9]*)([&]*)(.*)/, "$1");
                refer_url = "http://tw.partner.buy.yahoo.com/gd/buy?gdid=" + gdid + "&mcode=MV8vNXpySXhldmhhMUkxUmRiZXV6NElqVitUZjZibndjVWo5ZFp4VW9tUEQwPQ==";
            }
            // url replace rule No.2
            else if(refer_url.indexOf('http://buy.yahoo.com.tw/gdsale/gdnsm.asp?gdid=') >= 0){
                refer_url = refer_url.replace("http://buy.yahoo.com.tw/gdsale/gdnsm.asp?gdid=", "");
                var gdid = refer_url.replace(/([0-9]*)([&]*)(.*)/, "$1");
                refer_url = "http://tw.partner.buy.yahoo.com/gd/buy?gdid=" + gdid + "&mcode=MV8vNXpySXhldmhhMUkxUmRiZXV6NElqVitUZjZibndjVWo5ZFp4VW9tUEQwPQ==";
            }
			var desp = Tagtoo.calculateDotPosString();
			Tagtoo.ajaxCrossDomain(AddImageAPI, "imgurl=" + Tagtoo.imgurlProcess(Tagtoo.imgurl) + "&tag=" + encodeURIComponent(tagtext) + "&desp=" + encodeURIComponent(desp) + "&referurl=" + encodeURIComponent(refer_url) + "&secret=" + Tagtoo.pageOwnerKey + "&imgID=" + imgID, "Tagtoo.AddImageCallback");
		}
	}
}

Tagtoo.rewriteDotPos = function(data){
	var imgurl = Tagtoo.imgurl;
	var tag = data[0];
	var referurl = data[2];
	var desp = data[3];
	var secret = Tagtoo.pageOwnerKey;
	desp = Tagtoo.reCalculateDotDesp(desp);
	var AddImageAPI = TagtooRequestSite + "/api/AddImage/";
	Tagtoo.ajaxCrossDomain(AddImageAPI, "imgurl=" + Tagtoo.imgurlProcess(imgurl) + "&tag=" + encodeURIComponent(tag) + "&desp=" + encodeURIComponent(desp) + "&referurl=" + encodeURIComponent(referurl) + "&secret=" + secret, "");
}

Tagtoo.reCalculateDotDesp = function(desp){
	var cords = desp.split(",");
	var upperLeftX = parseInt(cords[2]);
	var upperLeftY = parseInt(cords[3]);
	var lowerRightX = parseInt(cords[4]);
	var lowerRightY = parseInt(cords[5]);
	var middleX = (upperLeftX + lowerRightX) / 2;
	var middleY = (upperLeftY + lowerRightY) / 2;
	// calculate the correct ratio, then save it back to db
	var ratioX = parseInt(middleX / Tagtoo.imgWidth * 1000);
	var ratioY = parseInt(middleY / Tagtoo.imgHeight * 1000);
	desp = ratioX + "," + ratioY;
	return desp;
}

Tagtoo.getDotPos = function(){
	var dotPos = new Array();
	dotPos[0] = tagtoo_jQuery("#tagtoo_temp_dot").offset().left;
	dotPos[1] = tagtoo_jQuery("#tagtoo_temp_dot").offset().top;
	return dotPos;
}

Tagtoo.calculateDotPosString = function(){
	var dotPos = new Array();
	dotPos = Tagtoo.getDotPos();
	
	var dot_relative_corX = dotPos[0] - Tagtoo.imgLeft;
	var dot_relative_corY = dotPos[1] - Tagtoo.imgTop;
	var ratioX = (dot_relative_corX / Tagtoo.imgWidth) * 1000;
	var ratioY = (dot_relative_corY / Tagtoo.imgHeight) * 1000;
	ratioX = ratioX.toString().substring(0,3);
	ratioY = ratioY.toString().substring(0,3);
	return ratioX + "," + ratioY;
}

Tagtoo.AddImageCallback = function(response){
	var status = response.status;
    var imgID = response.imgID;
	if(status == false){
		var msg = response.msg;
		if(msg == "PERMISSION_ERROR")
			alert(Tagtoo.queryDictionary('ADDTAG_ACCESS_DENY'));
		else
			alert(msg);
	}
	else{
        Tagtoo.resetFriendlist();
		Tagtoo.LoadTagData("reload", imgID);
		// if add tag successful, return to the edit mode
		Tagtoo.EnterReadMode();
	}
}

Tagtoo.calculateDotPos = function(desp,imgID){
    var imgclass = "tagtoo_imgobj" + imgID;
	var imgobj = tagtoo_jQuery('img[class*="'+imgclass+'"]');
	var img_left_top_cordX = imgobj.offset().left;
	var img_left_top_cordY = imgobj.offset().top;
    var imgWidth = imgobj.width();
    var imgHeight = imgobj.height();
	var ratioX = 0;
	var ratioY = 0;
	var tag_cor = new Array();
	
	var ratios = desp.split(",");
	if(ratios.length == 6){
		// calculate the new dot "desp" format(from old dot desp)
		var desp_string = Tagtoo.reCalculateDotDesp(desp);
		var desps = desp_string.split(",");
		ratioX = parseFloat(desps[0])/1000;
		ratioY = parseFloat(desps[1])/1000;
	}
	else{
		ratioX = parseFloat(ratios[0])/1000;
		ratioY = parseFloat(ratios[1])/1000;	
	}
	// calculate the absolute coordinate of this reginonal tag(dot)
	tag_cor[0] = ratioX * imgWidth + img_left_top_cordX;
	tag_cor[1] = ratioY * imgHeight + img_left_top_cordY;
	return tag_cor;
}

Tagtoo.decideDotClass = function(refer_url){
	var dot_class;
	if(Tagtoo.isFBLink(refer_url))
		dot_class = "person";
	else if(Tagtoo.isProductLink(refer_url))
		dot_class = "product";
	else if(refer_url == null || refer_url == "")
		dot_class = "null";
	else
		dot_class = "item";
	
	return dot_class;
}

Tagtoo.createDot = function(tagNumber, tagtext, refer_url, tag_cor, imgID){
	// decide which kind of dot
	var dot_class = Tagtoo.decideDotClass(refer_url);
    // every tag has class tagtoo_regional_tag_content + imgID, imgID is to identify which image is this tag belongs to.
	if(dot_class == "null")
		tagtoo_jQuery("body").append("<div id='tagtoo_regional_tag_content" + imgID + "_" +tagNumber+"' class='"+dot_class+" tagtoo_regional_tag_content tagtoo_regional_tag_content"+imgID+" tagtoo_regional_tag"+imgID+"' name='"+tagtext+"'></div>");
	else
		tagtoo_jQuery("body").append("<a id='tagtoo_regional_tag" + imgID + "_" + tagNumber+"' target='_blank' href='"+refer_url+"' class='tagtoo_regional_tag"+imgID+"'><div id='tagtoo_regional_tag_content" + imgID + "_" +tagNumber+"' class='"+dot_class+" tagtoo_regional_tag_content tagtoo_regional_tag_content"+imgID+"' name='"+tagtext+"'></div></a>");
	
	tagtoo_jQuery("#tagtoo_regional_tag_content" + imgID + "_" +tagNumber).css({'left': tag_cor[0]+'px', 'top': tag_cor[1]+'px'});
    
    var dot = tagtoo_jQuery("#tagtoo_regional_tag_content" + imgID + "_" +tagNumber);
    if(dot.hasClass('person')){
        dot.css({'background': 'url('+TagtooFileSite+'/plugin/img/new/person_dot.png) no-repeat'});
    }
    else if(dot.hasClass('product')){
        dot.css({'background': 'url('+TagtooFileSite+'/plugin/img/new/product_dot.png) no-repeat'});
    }
    // no link
    else if(dot.hasClass('null')){
        dot.css({'background': 'url('+TagtooFileSite+'/plugin/img/new/null_dot.png) no-repeat', 'cursor': 'auto'});
    }
    // item
    else{
        dot.css({'background': 'url('+TagtooFileSite+'/plugin/img/new/item_dot.png) no-repeat'});
    }
}
// Note: After experiment, if bottom is greater then 300px, the DOM element won't appear in the screen. 
Tagtoo.updateStyle = function(el){
    var offset=tagtoo_jQuery(el).offset();
    var top=offset.top;
    var left=offset.left;
    tagtoo_jQuery('#tagtoo-tooltip')
    .css({
        top:top - tagtoo_jQuery('#tagtoo-tooltip').height()-20,
        left:left-tagtoo_jQuery('#tagtoo-tooltip').width()/2
    })
	.children()
	.fadeTo(300,1);
    var offset=tagtoo_jQuery('#tagtoo-tooltip').offset();
    if(offset.left<0){
        tagtoo_jQuery('#tagtoo-tooltip').css('left',10);
    }else if(offset.left+tagtoo_jQuery('#tagtoo-tooltip').innerWidth()>tagtoo_jQuery(document).width()){
        tagtoo_jQuery('#tagtoo-tooltip').css('left',offset.left-10);
    }
}

Tagtoo.setDotEffect = function(tagNumber,imgID){
    // prevent redirect to another page when clicked, which is the default behavior of html <a> element
    tagtoo_jQuery("#tagtoo_regional_tag"+ imgID + "_" + tagNumber).live('click', function(e){
        e.preventDefault();
    });
	tagtoo_jQuery("#tagtoo_regional_tag_content"+ imgID + "_" + tagNumber).live('mouseover', function(){
        
        //$(".tagtoo_regional_tag_content").hide();
        //$(".tagtoo_regional_tag_content"+imgID).show();
		if(tagtoo_jQuery(this).hasClass('person')){
			tagtoo_jQuery(this).css({'background': 'url('+TagtooFileSite+'/plugin/img/new/person_dot_h.png) no-repeat'});
		}
		else if(tagtoo_jQuery(this).hasClass('product')){
			tagtoo_jQuery(this).css({'background': 'url('+TagtooFileSite+'/plugin/img/new/product_dot_h.png) no-repeat'});
		}
        // no link
		else if(tagtoo_jQuery(this).hasClass('null')){
			tagtoo_jQuery(this).css({'background': 'url('+TagtooFileSite+'/plugin/img/new/null_dot_h.png) no-repeat', 'cursor': 'auto'});
		}
		// item
		else{
			tagtoo_jQuery(this).css({'background': 'url('+TagtooFileSite+'/plugin/img/new/item_dot_h.png) no-repeat'});
        }
	
        var offset=tagtoo_jQuery(this).offset();
        var top=offset.top;
        var left=offset.left;
        tagtoo_jQuery('#tagtoo-tooltip')
        .html('<img src="'+ TagtooFileSite + '/plugin/img/new/ajax-loader.gif" style="display:block;margin:0 auto;height:20px;" />')
        .css({
            display:'block',
            top: top - tagtoo_jQuery('#tagtoo-tooltip').height()-17,
            left:left-tagtoo_jQuery('#tagtoo-tooltip').width()/2
        });
        // the structure of dot, the outer layer is <a>, the inner layer is <div>
        var hrefStr=tagtoo_jQuery(this).parent().attr('href');
        
        if(tagtoo_jQuery(this).hasClass('person')){
            function fbProfileCallback(data,el){
                tagtoo_jQuery('#tagtoo-tooltip').html(
                    '<div id="tagtoo-tooltip-fb-profile">'+
                        '<a class="tagtoo_tag_link" name="'+el.attr('name')+'" target="blank" href="http://www.facebook.com/profile.php?id='+data.id+'">'+
                            '<img src="http://graph.facebook.com/'+data.id+'/picture" alt="'+data.name+'" id="facebook-profile-image" style="margin-right" />'+
                        '</a>'+
                        '<a class="tagtoo_tag_link" name="'+el.attr('name')+'" target="blank" href="http://www.facebook.com/profile.php?id='+data.id+'">'+data.name+'</a>'+   
                    '</div>'
                )
				.children()
				.fadeTo(0,0);
				tagtoo_jQuery('#facebook-profile-image').fadeTo(0,0).load(function(){
					tagtoo_jQuery(this).fadeTo(200,1);	
				});
                Tagtoo.updateStyle(el);
            }
            
            var $this=tagtoo_jQuery(this);
            if(tagtoo_jQuery(this).data('profile')!=undefined){
                fbProfileCallback(tagtoo_jQuery(this).data('profile'),$this);
            }else{
                var index=hrefStr.indexOf('=');
                var uid=hrefStr.substr(index+1);
                
                tagtoo_jQuery.getJSON('http://graph.facebook.com/'+uid+'?callback=?',function(response){
                    fbProfileCallback(response,$this);
                    $this.data('profile',response);
                });
            }
        }else if(tagtoo_jQuery(this).hasClass('product')){
			function sitetagCallback(response,el){
                if(response.total_num>0){
                    var domain;    
                    var data=tagtoo_jQuery.parseJSON(response.information.replace("WOMANY","").replace("NOWNEWS_STORE",""));
					var Title = "--",Subtitle = "--",Store_price = "--",Price = "--",Description = "--";
					
                    if(hrefStr.indexOf("http://tw.partner.buy.yahoo.com/") > -1 || hrefStr.indexOf("http://buy.yahoo.com.tw/") > -1)
					    domain = 'tagtoo-tooltip-content-wraper';
					else if(hrefStr.indexOf("http://www.womany.net/") > -1 || hrefStr.indexOf("http://www.tamode.com.tw/") > -1)
					    domain = 'tagtoo-content-wraper';
						
					if(data.title)Title = data.title;
					if(data.subtitle)Subtitle = data.subtitle;
					if(data.store_price)Store_price = data.store_price;
					if(data.price)Price = data.price;
					if(data.description)Description = data.description;
					
                    tagtoo_jQuery('#tagtoo-tooltip').html(
                        '<div class="clearfix">'+
                          '<a target="_blank" class="tagtoo_tag_link" name="'+el.attr('name')+'" href="'+hrefStr+'"><img style="border: none" id="data-img" src="'+data.image_url+'" alt="'+data.title+'" /></a>'+
                          '<div id="'+domain+'">'+
                            '<table>'+
                                '<tr>'+
                                    '<th>產品:</th>'+
                                    '<td>'+Title+'</td>'+
                                '</tr>'+
                                '<tr>'+
                                    '<th id="tagtoo-tooltip-product-desc">描述:</th>'+
                                    '<td><div>'+Description+'</div></td>'+
                                '</tr>'+
                                '<tr>'+
                                    '<th>特點:</th>'+
                                    '<td>'+Subtitle+'</td>'+
                                '</tr>'+
                                '<tr>'+
                                    '<th>售價:</th>'+
                                    '<td>'+Store_price+'</td>'+
                                '</tr>'+
                                '<tr>'+
                                    '<th>特價:</th>'+
                                    '<td>'+Price+'</td>'+
                                '</tr>'+
                                '<tr>'+
                                    '<th>網址:</th>'+
                                    '<td><a class="tagtoo_tag_link" name="'+el.attr('name')+'" target="_blank" href="'+hrefStr+'">前往</a></td>'+
                                '</tr>'+
                            '</table>'+
                          '</div>'+
                        '</div>'
                    )
					.children()
					.fadeTo(0,0);
                }else{
                    tagtoo_jQuery('#tagtoo-tooltip').html(
                        '<div id="tagtoo-tooltip-link">'+
                            '<a target="_blank" name="'+el.attr('name')+'" class="tagtoo_tag_link" href="'+hrefStr+'" title="前往商品頁">'+
                                el.attr('name')+   
                            '</a>'+ 
                        '</div>'
                    )
					.children()
					.fadeTo(0,0);
                }
                Tagtoo.updateStyle(el);
            }
            $this=tagtoo_jQuery(this);
            
            if($this.data('product')!=undefined){
                sitetagCallback($this.data('product'),$this);
            }else{
			    var BuyHref;
			    if(hrefStr.indexOf("http://tw.partner.buy.yahoo.com/") > -1 || hrefStr.indexOf("http://buy.yahoo.com.tw/") > -1){
                    var index = hrefStr.indexOf('&mcode');
                    var ybuyHref = hrefStr.substring(0,index);
                    var gdid = ybuyHref.replace("http://tw.partner.buy.yahoo.com/gd/buy?gdid=", "");
                    // Must transform http://tw.partner.buy.yahoo.com/gd/buy?gdid=xxx format to http://buy.yahoo.com.tw/gdsale/gdsale.asp?gdid=xxx, otherwise you can't get data response.
                    ybuyHref = "http://buy.yahoo.com.tw/gdsale/gdsale.asp?gdid=" + gdid + "&act=gdsearch";
					BuyHref = ybuyHref;
				}
                else{
                    BuyHref = hrefStr;
                }
                tagtoo_jQuery.getJSON('http://tagtoo-ec.appspot.com/query_item?url='+encodeURIComponent(BuyHref)+'&callback=?',function(response){
                    sitetagCallback(response,$this);
                    $this.data('product',response);
                });
				// protect mechanism, to avoid there is no response from remote API
				tagtoo_jQuery('#tagtoo-tooltip')
				.html(
					  '<div id="tagtoo-tooltip-link">'+
						'<a target="_blank" name="'+$this.attr('name')+'" class="tagtoo_tag_link" href="'+hrefStr+'" title="鏈接到商品頁">'+$this.attr('name')+ '</a>'+
					  '</div>'
				)
				.children()
				.fadeTo(0,0);
				Tagtoo.updateStyle($this);
			}
		}
        else{
            var prompt="";
            if(tagtoo_jQuery(this).parent().attr('href') == undefined){
                prompt = '<div>' + tagtoo_jQuery(this).attr('name') + '</div>';
            }
            else{
                prompt = '<div id="tagtoo-tooltip-link"><a target="_blank" name="'+tagtoo_jQuery(this).attr('name')+'" class="tagtoo_tag_link" href="'+tagtoo_jQuery(this).parent().attr('href')+'">'+tagtoo_jQuery(this).attr('name')+ '</a></div>';
            }
            tagtoo_jQuery('#tagtoo-tooltip').html(prompt).children().fadeTo(0,0);
            Tagtoo.updateStyle(tagtoo_jQuery(this));
        }
    });
	tagtoo_jQuery("#tagtoo_regional_tag_content"+ imgID + "_" + tagNumber).live('mouseout', function(){
		if(tagtoo_jQuery(this).hasClass('person')){
			tagtoo_jQuery(this).css({'background': 'url('+TagtooFileSite+'/plugin/img/new/person_dot.png) no-repeat'});
		}
		else if(tagtoo_jQuery(this).hasClass('product')){
			tagtoo_jQuery(this).css({'background': 'url('+TagtooFileSite+'/plugin/img/new/product_dot.png) no-repeat'});
		}
        // no link
		else if(tagtoo_jQuery(this).hasClass('null')){
			tagtoo_jQuery(this).css({'background': 'url('+TagtooFileSite+'/plugin/img/new/null_dot.png) no-repeat', 'cursor': 'auto'});
		}
		// item
		else{
			tagtoo_jQuery(this).css({'background': 'url('+TagtooFileSite+'/plugin/img/new/item_dot.png) no-repeat'});
		}
        //tagtoo_jQuery("#tagtoo-tooltip").fadeOut();
	});
}

Tagtoo.prepareAddDot = function(event){
	var x = event.pageX;
	var y = event.pageY;
	Tagtoo.callFriendlist(x,y);
	Tagtoo.showTempDot(x,y);
}

Tagtoo.callFriendlist = function(x,y){
	tagtoo_jQuery("#tagtoo_friendlist").css({'left': x+'px', 'top': y+'px', 'display': 'block'});
	tagtoo_jQuery("#regional_tag_input_field").focus();
}

Tagtoo.showTempDot = function(x,y){
	tagtoo_jQuery("#tagtoo_temp_dot").css({'left': (x-10)+'px', 'top': (y-10)+'px', 'display': 'block'});
}
// given tag information pack, this function draw them on screen
Tagtoo.CreateTags = function(data){
	var imgID = data.imgID;
    //alert("CreateTags--imgID:"+imgID);
    // reset all tag which has the same imgID
    tagtoo_jQuery(".tagtoo_regional_tag"+imgID).remove();
		
	//tagtoo_jQuery(".tagtoo_regional_tag_content").remove();
	var status = data.status;
	var tags = data.tags;
	var content ="";
    
	for(var i in tags) {
		// the first field of a single tag array is tagtext
		var tagtext = tags[i][0];
		// the second field of a single tag array is facebook uid(who add this tag)
		var uid = tags[i][1];
		// the third field of a single tag array is refer_url
		var refer_url = tags[i][2];
		// unpack the coordinate information
		var desp = tags[i][3];

		if(Tagtoo.uid == uid)
			Tagtoo.deletable = true;
		
		// if this tag is regional tag(in new UI version, we only display this kind of tags)
		if(desp != null && desp != ""){
			// calculate the absolute coordinate of this reginonal tag(dot)
			var cords = desp.split(",");
			//if(cords.length == 6){
				// to modify tag desp string generated by old structure to new format
				//Tagtoo.rewriteDotPos(tags[i]);
			//}
			
			var tag_cor = new Array();
			tag_cor = Tagtoo.calculateDotPos(desp,imgID);
			
			// create dot
			Tagtoo.createDot(i, tagtext, refer_url, tag_cor, imgID);
			Tagtoo.setDotEffect(i,imgID);
		}
	}
}
// reset or set(the first time) the tag of certain image
Tagtoo.SetHotTags = function(response){
	// put the response data in catch, the response contain imgID to identify which image should this tag been attached.
	var imgID = response.imgID;
    //alert("SetHotTags: "+imgID);
    // reset all tag which has the same imgID
    tagtoo_jQuery(".tagtoo_regional_tag"+imgID).remove();
    Tagtoo.putTagDataToCatch(imgID, response);
		
	//tagtoo_jQuery(".tagtoo_regional_tag_content").remove();
	var status = response.status;
	var tags = response.tags;
	var content ="";
    
    
	for(var i in tags) {
		// the first field of a single tag array is tagtext
		var tagtext = tags[i][0];
		// the second field of a single tag array is facebook uid(who add this tag)
		var uid = tags[i][1];
		// the third field of a single tag array is refer_url
		var refer_url = tags[i][2];
		// unpack the coordinate information
		var desp = tags[i][3];

		if(Tagtoo.uid == uid)
			Tagtoo.deletable = true;
		
		// if this tag is regional tag(in new UI version, we only display this kind of tags)
		if(desp != null && desp != ""){
			// calculate the absolute coordinate of this reginonal tag(dot)
			var cords = desp.split(",");
			//if(cords.length == 6){
				// to modify tag desp string generated by old structure to new format
				//Tagtoo.rewriteDotPos(tags[i]);
			//}
			
			var tag_cor = new Array();
			tag_cor = Tagtoo.calculateDotPos(desp,imgID);
			
			// create dot
			Tagtoo.createDot(i, tagtext, refer_url, tag_cor, imgID);
			Tagtoo.setDotEffect(i,imgID);
		}
	}
	
	//var tag_display_area_width = 0;
	//tagtoo_jQuery("#tag_display_area").html("<table id='inner_tag_display_area'><tr><td>" + content + "</td></tr></table>");
	//tag_display_area_width = tagtoo_jQuery("#tag_display_area").width();
	//tagtoo_jQuery("#inner_tag_display_area").width(tag_display_area_width);
	
	// to ensure there is only one tags register of this image
	tagtoo_jQuery("#"+Tagtoo.imgurl+"_tag").remove();
	tagtoo_jQuery("body").append("<input type='hidden' id='"+Tagtoo.imgurl+"_tag' />");
	// put the tag data into catch to avoid load it again
	tagtoo_jQuery('input[id="'+Tagtoo.imgurl+'_tag"]').val(content);
	
	tagtoo_jQuery('img[src="'+Tagtoo.imgurl+'"]').addClass('tag_queried');
	
	Tagtoo.TagDataLoaded = true;
}

Tagtoo.prepareDelDot = function(){
	var tagtext = tagtoo_jQuery(this).attr('name');
	Tagtoo.RemoveImage(tagtext, Tagtoo.imgurl);
}

Tagtoo.RemoveImage = function(tagtext, imgurl){
	var RemoveImageAPI = TagtooRequestSite + "/api/RemoveImage/";
    var imgID = tagtoo_jQuery(".tagtoo_plugin_active_img").data('tagtoo_imgobj');
	Tagtoo.ajaxCrossDomain(RemoveImageAPI, "imgurl=" + Tagtoo.imgurlProcess(imgurl) + "&tag=" + encodeURIComponent(tagtext) + "&secret=" + Tagtoo.pageOwnerKey + "&imgID=" + imgID, "Tagtoo.RemoveImageCallback");
}

Tagtoo.RemoveImageCallback = function(response){
	var status = response.status;
	if(status == false){
		var msg = response.msg;
		if(msg == "PERMISSION_ERROR")
			alert(Tagtoo.queryDictionary('REMOVETAG_ACCESS_DENY'));
		else
			alert(msg);
	}
	else{
        var imgID = response.imgID;
		Tagtoo.LoadTagData("reload", imgID);
		tagtoo_jQuery(".tagtoo_regional_tag_content_mask").remove();
		Tagtoo.EnterReadMode();
	}
}
Tagtoo.LogActionCallback = function(){
}
Tagtoo.createCoreElements = function (){
	Tagtoo.createTagtooPanel();
	Tagtoo.createFriendlistPanel();
	Tagtoo.createTempDot();
	Tagtoo.createPromptPanel();
    Tagtoo.createImgMask();
    Tagtoo.createTagPanel();
}

Tagtoo.createTagtooPanel = function(){
	tagtoo_jQuery("body").append("<div id='tagtoo_panel' class='tagtoo_panel' style='display: none'></div>");
}
// and tag_display_area which contained in #main_panel
Tagtoo.resetPanel = function(){
    // if not login
	if(!Tagtoo.ifLogin()){
        if( tagtoo_jQuery('#tagtoo-sidebar-container').size() != 1 || Tagtoo.isYamLink(Tagtoo.weburl)){
		    tagtoo_jQuery("#tagtoo_panel").css({'width': '127px'});
		    tagtoo_jQuery("#tagtoo_panel").html(Tagtoo.panel);
		    Tagtoo.PanelWidth = 127;
		}
        else{
            // if the website owner let everyone can edit, then show the login panel when mouseover the image even if user doesn't login.
            if(Tagtoo.checkPrivacy() == "public"){
                tagtoo_jQuery("#tagtoo_panel").css({'width': '127px'});
                tagtoo_jQuery("#tagtoo_panel").html(Tagtoo.panel);
                Tagtoo.PanelWidth = 127;
            }
            else{
                tagtoo_jQuery("#tagtoo_panel").css({'width': '0px'});
                tagtoo_jQuery("#tagtoo_panel").html("");
                Tagtoo.PanelWidth = 0;
            }
        }
	}
    // if login
	else{
        // if current user have authority to tag
        if(Tagtoo.Editable()){
            tagtoo_jQuery("#tagtoo_panel").css({'width': '300px'});
            tagtoo_jQuery("#tagtoo_panel").html(Tagtoo.panel_loggined);
            Tagtoo.PanelWidth = 300;
        }
        // if not...
        else{
            if( tagtoo_jQuery('#tagtoo-sidebar-container').size() != 1 || Tagtoo.isYamLink(Tagtoo.weburl)){ 
                tagtoo_jQuery("#tagtoo_panel").css({'width': '127px'});
                tagtoo_jQuery("#tagtoo_panel").html(Tagtoo.panel_loggined_short);
                Tagtoo.PanelWidth = 127;
            }
			else{
                tagtoo_jQuery("#tagtoo_panel").css({'width': '0px'});
                tagtoo_jQuery("#tagtoo_panel").html("");
                Tagtoo.PanelWidth = 0;
			}
        }
	}
    // to work fine with various browser
    Tagtoo.cssModify();
}

Tagtoo.createFriendlistPanel = function(){
	tagtoo_jQuery("body").append(Tagtoo.friendlist_panel);
	tagtoo_jQuery("#tagtoo_friendlist").css({'display': 'none'});
}

Tagtoo.createTempDot = function(){
	tagtoo_jQuery("body").append(Tagtoo.temp_dot);
	tagtoo_jQuery("#tagtoo_temp_dot").css({'display': 'none'});
}

Tagtoo.createPromptPanel = function(){
	tagtoo_jQuery("body").append(Tagtoo.prompt_panel);
}

Tagtoo.createImgMask = function(){
    tagtoo_jQuery("body").append(Tagtoo.img_mask);
}

Tagtoo.createTagPanel = function(){
    tagtoo_jQuery('body').append('<div id="tagtoo-tooltip"></div>');
}

Tagtoo.getFriendlistItem = function(name, uid){
	var html = '<div id="tagtoo_friend_item'+uid+'" class="tagtoo_friend_item" style="color: black; font-size: 9pt; cursor: pointer; width: 200px; height: 40px; border-bottom: 1px dotted black; padding-left: 5px">';
	html += '<div class="friend_checkbox" style="background: url('+TagtooFileSite+'/plugin/img/new/checkbox-unclicked.png); float: left; width: 13px; height: 13px; margin-top: 13px; margin-left: 8px"></div>';
	html += '<input title="'+name+'" style="display: none; margin-top: 14px; float: left" type="radio" class="friend" name="friend" value="'+uid+'" />';
	html += '<a style="display: none" href="http://www.facebook.com/profile.php?id='+uid+'">'+name+'</a>';
	html += '<div title="'+name+'" style="float: left; width: 110px; height: 17px; margin-top: 13px; margin-left: 15px; font-size: 8pt; overflow: hidden">'+name+'</div>';
	html += '<div class="fb_thumb_window" style="display: block; float: left; width: 32px; height: 32px; margin-top: 4px; margin-left: 8px; border: 0px solid black"></div>';
	html += '</div>';
	return html;
}

Tagtoo.getFriendlistNextBtn = function(){
    var html = '<div id="tagtoo_friend_item_next"  style="text-align: center; color: black; font-size: 9pt; cursor: pointer; width: 200px; height: 40px; border-bottom: 1px dotted black; padding-left: 5px; margin-top: 14px">' + Tagtoo.queryDictionary("NEXT_PAGE") + '(' + Tagtoo.querySentence("YOU_ARE_IN_PAGE", {'now_page': Tagtoo.nowFriendPage, 'total_page': Tagtoo.FriendPageAmount}) + ')</div>';
	return html;
}

Tagtoo.getFriendlistPrevBtn = function(){
    var html = '<div id="tagtoo_friend_item_prev"  style="text-align: center; color: black; font-size: 9pt; cursor: pointer; width: 200px; height: 40px; border-bottom: 1px dotted black; padding-left: 5px; margin-top: 14px">' + Tagtoo.queryDictionary("PREV_PAGE") + '(' + Tagtoo.querySentence("YOU_ARE_IN_PAGE", {'now_page': Tagtoo.nowFriendPage, 'total_page': Tagtoo.FriendPageAmount}) + ')</div>';
	return html;
}

Tagtoo.setButtonHighlightEffect = function(){
	tagtoo_jQuery("#add_tag_button").live('mouseover', function(){
		if(Tagtoo.state == 'read'){
			tagtoo_jQuery(this).css({'background': 'url('+TagtooFileSite+'/plugin/img/new/add_tag_button_highlight.png) no-repeat'});
			tagtoo_jQuery(this).children(".tagtoo_button_text_area").css({'font-weight': '600'});
		}
	});
	tagtoo_jQuery("#add_tag_button").live('mouseout', function(){
		if(Tagtoo.state == 'read'){
			tagtoo_jQuery(this).css({'background': 'url('+TagtooFileSite+'/plugin/img/new/add_tag_button.png) no-repeat'});
			tagtoo_jQuery(this).children(".tagtoo_button_text_area").css({'font-weight': '400'});
		}
	});
	
	tagtoo_jQuery("#del_tag_button").live('mouseover', function(){
		if(Tagtoo.state == 'read'){
			tagtoo_jQuery(this).css({'background': 'url('+TagtooFileSite+'/plugin/img/new/del_tag_button_highlight.png) no-repeat'});
			tagtoo_jQuery(this).children(".tagtoo_button_text_area").css({'font-weight': '600'});
		}
	});
	tagtoo_jQuery("#del_tag_button").live('mouseout', function(){
		if(Tagtoo.state == 'read'){
			tagtoo_jQuery(this).css({'background': 'url('+TagtooFileSite+'/plugin/img/new/del_tag_button.png) no-repeat'});
			tagtoo_jQuery(this).children(".tagtoo_button_text_area").css({'font-weight': '400'});
		}
	});
	
	tagtoo_jQuery("#fb_button").live('mouseover', function(){
		tagtoo_jQuery(".fb_button-text").css({'font-weight': '600', 'text-decoration': 'underline'});
	});
	tagtoo_jQuery("#fb_button").live('mouseout', function(){
		tagtoo_jQuery(".fb_button-text").css({'font-weight': '400', 'text-decoration': 'none'});
	});
	
	tagtoo_jQuery("#tag_submit_button").live('mouseover', function(){
		tagtoo_jQuery(this).css({'background': 'url('+TagtooFileSite+'/plugin/img/new/addtag_submit_btn_highlight.png) no-repeat'});
	});
	tagtoo_jQuery("#tag_submit_button").live('mouseout', function(){
		tagtoo_jQuery(this).css({'background': 'url('+TagtooFileSite+'/plugin/img/new/addtag_submit_btn.png) no-repeat'});
	});
	
	tagtoo_jQuery("#friendlist_submit").live('mouseover', function(){
		tagtoo_jQuery(this).css({'background': 'url('+TagtooFileSite+'/plugin/img/new/'+Tagtoo.Lang+'/friendlist_submit_highlight.png) no-repeat'});
	});
	tagtoo_jQuery("#friendlist_submit").live('mouseout', function(){
		tagtoo_jQuery(this).css({'background': 'url('+TagtooFileSite+'/plugin/img/new/'+Tagtoo.Lang+'/friendlist_submit.png) no-repeat'});
	});
	tagtoo_jQuery("#friendlist_cancel").live('mouseover', function(){
		tagtoo_jQuery(this).css({'background': 'url('+TagtooFileSite+'/plugin/img/new/'+Tagtoo.Lang+'/friendlist_cancel_highlight.png) no-repeat'});
	});
	tagtoo_jQuery("#friendlist_cancel").live('mouseout', function(){
		tagtoo_jQuery(this).css({'background': 'url('+TagtooFileSite+'/plugin/img/new/'+Tagtoo.Lang+'/friendlist_cancel.png) no-repeat'});
	});
}
Tagtoo.setButtonActions = function(){
	tagtoo_jQuery("#logo_button").live('click', function(){
        // google analytics, record this action
        _gaq.push(['_setAccount', 'UA-18757665-1']);
        _gaq.push(['_trackEvent', 'Tagtoo buttons', 'Clicked', 'Tagtoo logo button']);
		window.open('http://www.tagtoo.org/');
	});
	tagtoo_jQuery("#tag_submit_button").live('click', function(){
		var tagtext = tagtoo_jQuery("#tag_input_field").val();
		Tagtoo.AddImage('description', {'tagtext': tagtext});
	});
    tagtoo_jQuery("#refer_url_input_field").live('keyup', function(e){
        var code = (e.keyCode ? e.keyCode : e.which);
        if(code == 13) { //Enter keycode
            tagtoo_jQuery("#friendlist_submit").click();
        }
    });
    
	tagtoo_jQuery("#friendlist_submit").live('click', function(){
        // google analytics, record this action
        _gaq.push(['_setAccount', 'UA-18757665-1']);
        _gaq.push(['_trackEvent', 'Tagtoo buttons', 'Clicked', 'Submit tag button']);
        
		var tagtext = tagtoo_jQuery("#regional_tag_input_field").val();
		var refer_url = tagtoo_jQuery("#refer_url_input_field").val();
		if(tagtext == ''){
			alert(Tagtoo.queryDictionary('PLEASE_INPUT_TAG'));
		}
		else{
			Tagtoo.AddImage('dot', {'tagtext': tagtext, 'refer_url': refer_url});
			tagtoo_jQuery("#tagtoo_friendlist").css({'display': 'none'});
			tagtoo_jQuery("#tagtoo_temp_dot").css({'display': 'none'});
		}
		if(tagtoo_jQuery(".tagtoo_clicked_friend").length >= 1){
			var uid = tagtoo_jQuery(".tagtoo_clicked_friend").children(".friend").val();
			Tagtoo.notifyFacebookFriend(uid);
		}
        else{
            if(refer_url.indexOf('http://www.facebook.com/') > -1){
                if(refer_url.indexOf('pages') > -1){
                    var substr = refer_url.replace("http://www.facebook.com/pages/", "");
                    var part = substr.split("/");
                    var page_id = part[1];
                    Tagtoo.notifyFacebookFriend(page_id);
                }
                else{
                    var page_name = refer_url.replace("http://www.facebook.com/", "");
                    Tagtoo.notifyFacebookFriend(page_name);
                }
            }
        }
	});
	tagtoo_jQuery("#del_tag_button").live('click', function(){
        // google analytics, record this action
        _gaq.push(['_setAccount', 'UA-18757665-1']);
        _gaq.push(['_trackEvent', 'Tagtoo buttons', 'Clicked', 'Remove tag button']);
        
        /*if(Tagtoo.deletable == false){
            alert(Tagtoo.queryDictionary('DELTAG_ACCESS_DENY'));
            return;
        }*/
		// if already in remove mode, switch to read mode
		if(Tagtoo.state == 'remove'){
			Tagtoo.EnterReadMode();
			return;
		}
        var imgID = tagtoo_jQuery(".tagtoo_plugin_active_img").data('tagtoo_imgobj');
		// otherwise enter remove mode
		Tagtoo.EnterReadMode();
		Tagtoo.EnterRemoveMode(imgID);
	});
	
	tagtoo_jQuery("#facebook_logout_button").live('click', function(){
        // google analytics, record this action
        _gaq.push(['_setAccount', 'UA-18757665-1']);
        _gaq.push(['_trackEvent', 'Tagtoo buttons', 'Clicked', 'Logout button']);
		Tagtoo.doFacebookLogout();
	});
	
	tagtoo_jQuery("#facebook_login_button").live('click', function(){
        // google analytics, record this action
        _gaq.push(['_setAccount', 'UA-18757665-1']);
        _gaq.push(['_trackEvent', 'Tagtoo buttons', 'Clicked', 'Login button']);
		Tagtoo.doFacebookLogin();
	});
	tagtoo_jQuery(".tag").live('click', function(){
		var tagtext = tagtoo_jQuery(this).text();
		Tagtoo.RemoveImage(tagtext);
	});
	tagtoo_jQuery("#add_tag_button").live('click', function(e){
        // google analytics, record this action
        _gaq.push(['_setAccount', 'UA-18757665-1']);
        _gaq.push(['_trackEvent', 'Tagtoo buttons', 'Clicked', 'AddTag button']);
        
		if(!Tagtoo.ifLogin()){
			alert(Tagtoo.queryDictionary('LOGIN_FIRST'));
			return;
		}
		// only page owner can edit tag
		if(Tagtoo.authority == 'private'){
            if(Tagtoo.pageOwnerKey == 'tagtoo'){
                // pass, if name attribute of script tag is 'tagtoo', then anyone can edit
            }
            else{
                if(!Tagtoo.Editable()){
                    alert(Tagtoo.queryDictionary('ADDTAG_ACCESS_DENY'));
                    return;
                }
            }
		}
		// if already in write mode, switch to read mode
		if(Tagtoo.state == 'write'){
			Tagtoo.EnterReadMode();
			return;
		}
		// otherwise enter write mode
		Tagtoo.EnterReadMode();
		Tagtoo.EnterAddMode();
	});
	
	tagtoo_jQuery("#friendlist_cancel").live('click', function(){
        // google analytics, record this action
        _gaq.push(['_setAccount', 'UA-18757665-1']);
        _gaq.push(['_trackEvent', 'Tagtoo buttons', 'Clicked', 'Cancel tag submit button']);
        
		Tagtoo.EnterReadMode();
	});
	tagtoo_jQuery(".del_tag").live('click', function(){
		var tagtext = tagtoo_jQuery(this).attr('title');
		Tagtoo.RemoveImage(tagtext, Tagtoo.imgurl);
	});
    tagtoo_jQuery("#tagtoo_friend_item_next").live("click", function(){
        // Tagtoo.nowFriendPage count from 1
        Tagtoo.nextFriendlistSegment();
    });
    tagtoo_jQuery("#tagtoo_friend_item_prev").live("click", function(){
        // Tagtoo.nowFriendPage count from 1
        Tagtoo.prevFriendlistSegment();
    });
}
Tagtoo.setPromptPanel = function(type){
	var imgUpperLeftCorX = tagtoo_jQuery(".tagtoo_plugin_active_img").offset().left;
	var imgUpperLeftCorY = tagtoo_jQuery(".tagtoo_plugin_active_img").offset().top;
	var imgCenterCorX = imgUpperLeftCorX + Tagtoo.imgWidth/2;
	var imgCenterCorY = imgUpperLeftCorY + Tagtoo.imgHeight/2;
	
	if(type == 'add'){
		tagtoo_jQuery("#prompt_panel").html(Tagtoo.queryDictionary('ENTER_ADD_MODE'));
	}
	// type == 'remove'
	else{
		tagtoo_jQuery("#prompt_panel").html(Tagtoo.queryDictionary('ENTER_DEL_MODE'));
	}
	
	var panelX = imgCenterCorX - tagtoo_jQuery("#prompt_panel").width()/2;
	var panelY = imgCenterCorY - tagtoo_jQuery("#prompt_panel").height()/2;
	tagtoo_jQuery("#prompt_panel").css({'top': panelY+'px', 'left': panelX+'px'});
	tagtoo_jQuery("#prompt_panel").fadeIn(300).delay(2500).fadeOut(300);
}
// set Panel interactions
Tagtoo.setCoreElementInteractions = function(){
	// define action when mouseover the tagtoo panel
	tagtoo_jQuery("#tagtoo_panel").live('mouseover', function(){
		tagtoo_jQuery(".tagtoo_panel").css({'display': 'block'});
        var imgID = tagtoo_jQuery(".tagtoo_plugin_active_img").data('tagtoo_imgobj');
		tagtoo_jQuery(".tagtoo_regional_tag_content"+imgID).css({'display': 'block'});
	});
	tagtoo_jQuery("#tagtoo_panel").live('mouseleave', function(){
		if(Tagtoo.state == 'read'){
			tagtoo_jQuery(".tagtoo_panel").css({'display': 'none'});
            tagtoo_jQuery(".tagtoo_regional_tag_content").css({'display': 'none'});
        }
	});
	tagtoo_jQuery(".tagtoo_regional_tag_content").live('mouseover', function(){
		tagtoo_jQuery(".tagtoo_panel").css({'display': 'block'});
        tagtoo_jQuery(".tagtoo_current_regional_tag").removeClass("tagtoo_current_regional_tag");
        tagtoo_jQuery(this).addClass("tagtoo_current_regional_tag");
        var tagtext = tagtoo_jQuery(this).attr('name');
        
        // our log static system(mouseover event record)
        var LogActionAPI = TagtooRequestSite + "/api/LogAction/";
        Tagtoo.ajaxCrossDomain(LogActionAPI, "action=" + "mouseover" + "&tag=" + encodeURIComponent(tagtext) + "&url=" + encodeURIComponent(Tagtoo.imgurl) + "&secret=" + Tagtoo.pageOwnerKey + "&trace_code=" + Tagtoo.pageOwnerTraceCode, "Tagtoo.LogActionCallback");
				
	});
	tagtoo_jQuery("#tagtoo_friendlist").live('mouseover', function(){
		tagtoo_jQuery(".tagtoo_panel").css({'display': 'block'});
	});
	
	tagtoo_jQuery(".tagtoo_regional_tag_content_mask").live('mouseover', function(){
		tagtoo_jQuery(".tagtoo_panel").css({'display': 'block'});
	});
	tagtoo_jQuery("#tagtoo_regional_tag_content_mask").live('mouseover', function(){
		tagtoo_jQuery(".tagtoo_panel").css({'display': 'block'});
	});
    tagtoo_jQuery("#tagtoo_img_mask").live('mouseover', function(){
		tagtoo_jQuery(".tagtoo_panel").css({'display': 'block'});
        var imgID = tagtoo_jQuery(".tagtoo_plugin_active_img").data('tagtoo_imgobj');
		tagtoo_jQuery(".tagtoo_regional_tag_content"+imgID).css({'display': 'block'});
	});
    tagtoo_jQuery('#tagtoo-tooltip').live('mouseover', function(){
    //    tagtoo_jQuery(".tagtoo_regional_tag_content").hide();
        tagtoo_jQuery(".tagtoo_current_regional_tag").show();
        tagtoo_jQuery(".tagtoo_panel").show();
        tagtoo_jQuery(this).stop(true,true);
    });
    tagtoo_jQuery('#tagtoo-tooltip').live('mouseleave',function(){
        tagtoo_jQuery(this).fadeOut(200);
        tagtoo_jQuery(".tagtoo_regional_tag_content").hide();
        tagtoo_jQuery(".tagtoo_panel").hide();
    });
}
Tagtoo.setCoreElementActions = function(){
	//tagtoo_jQuery("#tagtoo_friendlist").draggable({ handle: '#tagtoo_friendlist_top' });
	//tagtoo_jQuery("#tagtoo_friendlist_top").css({'cursor': 'move'});
}
Tagtoo.setTagActions = function(){
	// corresponding tag action
	tagtoo_jQuery(".tags").live('mouseover', function(){
		var id = tagtoo_jQuery(this).attr('id');
		var dot_id = "tagtoo_regional_tag_content" + id;
		tagtoo_jQuery("#"+dot_id).trigger('mouseover');
	});
	tagtoo_jQuery(".tags").live('mouseout', function(){
		var id = tagtoo_jQuery(this).attr('id');
		var dot_id = "tagtoo_regional_tag_content" + id;
		tagtoo_jQuery("#"+dot_id).trigger('mouseout');
	});
    tagtoo_jQuery(".tagtoo_regional_tag_content").live('click', function(){
        _gaq.push(['_setAccount', 'UA-18757665-1']);
        if(tagtoo_jQuery(this).hasClass('person')){
            _gaq.push(['_trackEvent', 'Tagtoo dots', 'Clicked', 'person dot']);
        }
        else if(tagtoo_jQuery(this).hasClass('product')){
            _gaq.push(['_trackEvent', 'Tagtoo dots', 'Clicked', 'product dot']);
        }
        else if(tagtoo_jQuery(this).hasClass('item')){
            _gaq.push(['_trackEvent', 'Tagtoo dots', 'Clicked', 'item dot']);
        }
        else{
            _gaq.push(['_trackEvent', 'Tagtoo dots', 'Clicked', 'null dot']);
        }
    });
	tagtoo_jQuery(".tagtoo_regional_tag_content").live('mouseenter', function(){
        var id = tagtoo_jQuery(this).attr('id');
        var last_index = id.lastIndexOf("_");
        var dot_class = id.substring(0,last_index);
        
		tagtoo_jQuery('#tagtoo-tooltip').stop(true,true);
		tagtoo_jQuery("."+dot_class).css({'display': 'block'});

		//var tag_id = id.replace("tagtoo_regional_tag_content", "");	
		//tagtoo_jQuery("#"+tag_id).css({'font-weight': '600'});
        // google analytics, record this action
        _gaq.push(['_setAccount', 'UA-18757665-1']);
        if(tagtoo_jQuery(this).hasClass('person')){
            _gaq.push(['_trackEvent', 'Tagtoo dots', 'Mouseover', 'person dot']);
        }
        else if(tagtoo_jQuery(this).hasClass('product')){
            _gaq.push(['_trackEvent', 'Tagtoo dots', 'Mouseover', 'product dot']);
        }
        else if(tagtoo_jQuery(this).hasClass('item')){
            _gaq.push(['_trackEvent', 'Tagtoo dots', 'Mouseover', 'item dot']);
        }
        else{
            _gaq.push(['_trackEvent', 'Tagtoo dots', 'Mouseover', 'null dot']);
        }
	});
	tagtoo_jQuery(".tagtoo_regional_tag_content").live('mouseleave', function(){
		tagtoo_jQuery(".tagtoo_regional_tag_content").css({'display': 'none'});
		var id = tagtoo_jQuery(this).attr('id');
		var tag_id = id.replace("tagtoo_regional_tag_content", "");
		tagtoo_jQuery("#"+tag_id).css({'font-weight': '400'});
        tagtoo_jQuery('#tagtoo-tooltip').delay(500).fadeOut(200);
	});
    tagtoo_jQuery(".tagtoo_tag_link").live('click', function(){
        var tagtext = tagtoo_jQuery(this).attr('name');
        var link = tagtoo_jQuery(this).attr('href');
        // our log static system
        var LogActionAPI = TagtooRequestSite + "/api/LogAction/";
        Tagtoo.ajaxCrossDomain(LogActionAPI, "action=" + "click" + "&url=" + encodeURIComponent(Tagtoo.imgurl) + "&secret=" + Tagtoo.pageOwnerKey + "&trace_code=" + Tagtoo.pageOwnerTraceCode + "&tag=" + encodeURIComponent(tagtext) + "&referurl=" + encodeURIComponent(link), "Tagtoo.LogActionCallback");
    });
}
Tagtoo.inputFeildSetting = function(){
	tagtoo_jQuery("#regional_tag_input_field").live('keyup', function(event){
		var str = tagtoo_jQuery(this).val();
		Tagtoo.searchFriendlist(str);
	});
}
Tagtoo.friendItemEffects = function(){
	tagtoo_jQuery(".tagtoo_friend_item").live('mouseover', function(){
		if(tagtoo_jQuery(this).hasClass('tagtoo_clicked_friend'))
			tagtoo_jQuery(this).children(".friend_checkbox").css({'background': 'url('+TagtooFileSite+'/plugin/img/new/checkbox-clicked-highlight.png)'});
		else
			tagtoo_jQuery(this).children(".friend_checkbox").css({'background': 'url('+TagtooFileSite+'/plugin/img/new/checkbox-unclicked-highlight.png)'});
	});
	tagtoo_jQuery(".tagtoo_friend_item").live('mouseout', function(){
		if(tagtoo_jQuery(this).hasClass('tagtoo_clicked_friend'))
			tagtoo_jQuery(this).children(".friend_checkbox").css({'background': 'url('+TagtooFileSite+'/plugin/img/new/checkbox-clicked.png)'});
		else
			tagtoo_jQuery(this).children(".friend_checkbox").css({'background': 'url('+TagtooFileSite+'/plugin/img/new/checkbox-unclicked.png)'});
	});
	tagtoo_jQuery(".tagtoo_friend_item").live('click', function(){
        // google analytics, record this action
        _gaq.push(['_setAccount', 'UA-18757665-1']);
        _gaq.push(['_trackEvent', 'Tagtoo buttons', 'Clicked', 'Friendlist item']);
        // if the item already clicked once, click again will cause the click been canceled
        if(tagtoo_jQuery(this).hasClass('tagtoo_clicked_friend')){
            tagtoo_jQuery(this).children(".friend_checkbox").css({'background': 'url('+TagtooFileSite+'/plugin/img/new/checkbox-unclicked.png)'});
            tagtoo_jQuery(this).removeClass('tagtoo_clicked_friend');
            Tagtoo.cleanInputField();
        }
        else{
            tagtoo_jQuery(".tagtoo_clicked_friend").children('.friend_checkbox').css({'background': 'url('+TagtooFileSite+'/plugin/img/new/checkbox-unclicked.png)'});
            tagtoo_jQuery(".tagtoo_clicked_friend").removeClass('tagtoo_clicked_friend');
            tagtoo_jQuery(this).addClass('tagtoo_clicked_friend');
            var name = tagtoo_jQuery(this).children('.friend').attr('title');
            var id = tagtoo_jQuery(this).children('.friend').val();
            var refer_url = 'http://www.facebook.com/profile.php?id='+id;
            tagtoo_jQuery(this).children(".friend_checkbox").css({'background': 'url('+TagtooFileSite+'/plugin/img/new/checkbox-clicked.png)'});
            tagtoo_jQuery("#regional_tag_input_field").val(name);
            tagtoo_jQuery("#refer_url_input_field").val(refer_url);
        }
	});
	tagtoo_jQuery(".tagtoo_friend_item").live('mouseover', function(){		
		if(tagtoo_jQuery(this).children(".fb_thumb_window").html() == ''){
			var uid = tagtoo_jQuery(this).children(".friend").val();
			tagtoo_jQuery(this).children(".fb_thumb_window").html('<img width="32" hieght="32" src="http://graph.facebook.com/'+uid+'/picture?type=square" />');
		}
		tagtoo_jQuery(this).children(".fb_thumb_window").css({'display': 'block'});
	});

	tagtoo_jQuery(".tagtoo_friend_item").live('mouseout', function(){
		tagtoo_jQuery(this).children(".fb_thumb_window").css({'display': 'none'});
	});
}
Tagtoo.decideTagtooPanelPos = function(){
	var obj = tagtoo_jQuery(".tagtoo_plugin_active_img");
	var offset = Tagtoo.getPanelOffset();
	var offsetTop = offset['top'];
	var offsetLeft = offset['left'];
		
	var mainPanelPos = new Array();
	mainPanelPos['tagtooPanelTop'] = Tagtoo.imgTop + offsetTop;
	mainPanelPos['tagtooPanelLeft'] = Tagtoo.imgLeft + offsetLeft;
	return mainPanelPos;
}
Tagtoo.getPanelOffset = function(){
	var obj = tagtoo_jQuery(".tagtoo_plugin_active_img");
	var padding_left = obj.css('paddingLeft');
	var padding_top = obj.css('paddingTop');
	var border_left_width = obj.css('borderLeftWidth');
	var border_top_width = obj.css('borderTopWidth');
    if(border_left_width == "medium"){
        border_left_width = "0px";
    }
    if(border_top_width == "medium"){
        border_top_width = "0px";
    }
	
	padding_left = Tagtoo.switchMeasureToInt(padding_left);
	padding_top = Tagtoo.switchMeasureToInt(padding_top);
	border_left_width = Tagtoo.switchMeasureToInt(border_left_width);
	border_top_width = Tagtoo.switchMeasureToInt(border_top_width);
	
	var offset = new Array();
	offset['top'] = padding_top + border_top_width;
	offset['left'] = padding_left + border_left_width;
	return offset;
}
Tagtoo.enableImageMask = function(){
    var offset = Tagtoo.getPanelOffset();
	var offsetTop = offset['top'];
	var offsetLeft = offset['left'];
	var maskPos = new Array();
	maskPos['tagtooPanelTop'] = Tagtoo.imgTop + offsetTop;
	maskPos['tagtooPanelLeft'] = Tagtoo.imgLeft + offsetLeft;
    tagtoo_jQuery("#tagtoo_img_mask").css({'top': maskPos['tagtooPanelTop'] + 'px', 'left': maskPos['tagtooPanelLeft'] + 'px', 'width': Tagtoo.imgWidth + 'px', 'height': Tagtoo.imgHeight + 'px', 'display': 'block'});
}
Tagtoo.disableImageMask = function(){
    tagtoo_jQuery("#tagtoo_img_mask").css({'display': 'none'});
}
Tagtoo.cleanInputField = function(){
    tagtoo_jQuery("#regional_tag_input_field").val("");
    tagtoo_jQuery("#refer_url_input_field").val("");
}
Tagtoo.resetFriendlist = function(){
    Tagtoo.cleanInputField();
    Tagtoo.setFriendlist();
}

Tagtoo.facebookAppId = {
	"http://www.tagtoo.org": "133943183290889",
	"http://tagtool.appspot.com": "165004316866799",
	"http://tagtoobeta.appspot.com": "140268946006741",
	"http://tagtoozouber.appspot.com": "131545976871586",
	"http://tagtootest.appspot.com": "117063174975384",
    "http://tagtoov1.appspot.com": "201738173190526",
	"http://www.tagtoo.co": "180690281958411",
	"http://www.tagtoo.cc": "182813721746917",
	"http://tagtoo-hhhuang.appspot.com": "127651297306230",
	"http://tagtoo.skywatchertelescope.net": "150746868320405",
	"http://yam.tagtoo.org": "213794001977104",
	"http://tagtoo-gary.appspot.com": "203647349686468",
    "http://tagtoo-now-news.appspot.com": "204103952989609",
    "http://tagtoofg.appspot.com": "233380976695387",
    "http://news.tagtoo.co": "145306172236278",
    "http://tagtoo2.appspot.com": "220097874726175"
}
Tagtoo.queryFacebookAppId = function(hostDomain){
    return Tagtoo.facebookAppId[hostDomain];
}

// if login, return true
Tagtoo.ifLogin = function(){
	if(Tagtoo.username == '')
		// not login
		return false;
	else
		return true;
}

Tagtoo.setPageOwnerParas = function(){
    var key = "";
    var trace_code = "";
    var paras = tagtoo_jQuery("#tagtoo_plugin_seed").attr('name');
    if(paras == undefined){
        key = "tagtoo";
        trace_code = "tagtoo";
        return;
    }
    // there is only secret in paras string
    if(paras.indexOf(";") == -1){
        key = paras;
        trace_code = "tagtoo";
    }
    else{
        paras = paras.split(";");
        key = paras[0];
        trace_code = paras[1];
    }
    
    Tagtoo.pageOwnerKey = key;
    Tagtoo.pageOwnerTraceCode = trace_code;
}

Tagtoo.checkPrivacy = function(){
    if(tagtoo_jQuery("#tagtoo_plugin_seed").attr('name') == undefined)
        return "public";
	if(tagtoo_jQuery("#tagtoo_plugin_seed").hasClass('edit_auth'))
		return "private";
	else
		return "public";
}

Tagtoo.Editable = function(){
	// if this website is public, it must editable!
    if(Tagtoo.checkPrivacy() == "public"){
        return true;
    }
    else{
        // USER_ADD_IMAGE is not in permission list, user can't edit image, those buttons won't appear
        if(tagtoo_jQuery.inArray("USER_ADD_IMAGE", Tagtoo.permission) == -1){
            return false;
        }
        else{
            return true;
        }
    }
}

Tagtoo.doFacebookLogin = function(){
	// check the dictionary defined above to decide appId
    var appId = Tagtoo.queryFacebookAppId(TagtooRequestSite);
    // A Landing page for facebook login
    var DomainLoginPage = TagtooRequestSite + "/facebook_login_page";
    //alert(appId + "/" + DomainLoginPage);
    
	my_window = window.open("https://www.facebook.com/dialog/oauth?client_id=" + appId + "&redirect_uri=" + DomainLoginPage + "&scope=email,publish_stream", 'FacebookLoginWindow', 'height=550, width=750, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no, fullscreen=no');// + "&response_type=token");
	var intervalId = setInterval(function() {
		if (my_window.closed) {
			clearInterval(intervalId);
			var LoginAPI = TagtooRequestSite + "/api/Login/" ;
			Tagtoo.ajaxCrossDomain(LoginAPI, "secret=" + Tagtoo.pageOwnerKey, "Tagtoo.LoginCallback");
		}
	}, 750);
}
Tagtoo.LoginCallback = function(response){
	var status = response.status;
	if(status == true){
		var name = response.name;
		var permission = response.permission;
		alert(Tagtoo.queryDictionary('FACEBOOK_LOGINED'));
        if(tagtoo_jQuery.inArray("USER_ADD_IMAGE", permission) != -1){
            alert(Tagtoo.queryDictionary("NOTIFICATION"));
        }
		// reset the login status after login successful!
		Tagtoo.CheckLoginStatus();
	}
	else{
		var msg = response.msg;
		alert(Tagtoo.queryDictionary('LOGIN_FAIL'));
	}
}
Tagtoo.sidebarLoginCallback = function(response){
    var status = response.status;
	if(status == true){
		var permission = response.permission;
        var prompt = Tagtoo.queryDictionary('FACEBOOK_LOGINED');
        if(tagtoo_jQuery.inArray("USER_ADD_IMAGE", permission) != -1){
            prompt += ' 現在只要把滑鼠移到欲加標籤的圖片上, 您便可使用塔圖圖片標籤功能!';
        }
        else{
            prompt += ' 但您不是網站擁有者, 故無法編輯標籤資訊!';
        }
        alert(prompt);
		// reset the login status after login successful!
		Tagtoo.CheckLoginStatus();
	}
	else{
		var msg = response.msg;
		alert(Tagtoo.queryDictionary('LOGIN_FAIL'));
	}
}
Tagtoo.doFacebookLogout = function(){
	//var TagtooSite2 = "http://www.tagtoo.org"
	//var LogoutAPI = TagtooSite2 + "/api/Logout/";
	Tagtoo.EnterReadMode();
	var LogoutAPI = TagtooRequestSite + "/api/Logout/";
	Tagtoo.ajaxCrossDomain(LogoutAPI, "", "Tagtoo.LogoutCallback");
}
Tagtoo.LogoutCallback = function(response){
	var status = response.status;
	var user = response.user;
	if(status == true)
		alert(Tagtoo.queryDictionary('FACEBOOK_LOGOUT'));
	// reset the login status after logout!
	Tagtoo.CheckLoginStatus();
}

Tagtoo.notifyFacebookFriend = function(uid){
	if(Tagtoo.ifLogin()){
		var message = "";
		var attachment_name = Tagtoo.webtitle;
		var attachment_caption = Tagtoo.querySentence("NOTIFY_FRIEND", {"fb_username": Tagtoo.username});
		var attachment_link = TagtooRequestSite + "/redirect/?tagtoo_url=" + decodeURIComponent(Tagtoo.weburl);
		var attachment_description = Tagtoo.queryDictionary("POWERED_BY_TAGTOO");
		var attachment_picture = Tagtoo.imgurl;
		var data = "message=" + message + "&profile_id=" + uid + "&attachment_name=" + encodeURIComponent(attachment_name) + "&attachment_caption=" + encodeURIComponent(attachment_caption) + "&attachment_link=" + encodeURIComponent(attachment_link) + "&attachment_description=" + encodeURIComponent(attachment_description) + "&attachment_picture=" + encodeURIComponent(attachment_picture);
		Tagtoo.postWall(data);
	}
}

Tagtoo.CheckLoginStatus = function(){
	var LoginAPI = TagtooRequestSite + "/api/Login/";
	Tagtoo.ajaxCrossDomain(LoginAPI, "secret=" + Tagtoo.pageOwnerKey, "Tagtoo.SetLoginStatus");
}

Tagtoo.CheckLoginStatusWithImgID = function(imgID){
	var LoginAPI = TagtooRequestSite + "/api/Login/";
	Tagtoo.ajaxCrossDomain(LoginAPI, "secret=" + Tagtoo.pageOwnerKey + "&imgID=" + imgID, "Tagtoo.SetLoginStatus");
}

// first let all friend item invisible, then let those item which partially match user's input reveal.
Tagtoo.searchFriendlist = function(str){
    Tagtoo.nowFriendPage = 1;
    if(str == ''){
        Tagtoo.setFriendlist();
    }
    else{
        tagtoo_jQuery("#friendlist_middle").html("");
        var html = "";
        var counter = 0;
        
        str = str.toLowerCase();
        for(var i in Tagtoo.friendlist){
            if(counter >= Tagtoo.FriendPageItemAmount)
                break;
            var name = Tagtoo.friendlist[i]['name'];
            var id = Tagtoo.friendlist[i]['id'];
            if(name.toLowerCase().indexOf(str) > -1){
                html += Tagtoo.getFriendlistItem(name, id);
                counter++;
                // only display the first 200 matching items, we assume that the autocomplete list won't contain too much elements
            }
        }
        
        tagtoo_jQuery("#friendlist_middle").append(html);
        tagtoo_jQuery("#friendlist_middle").scrollTop(0);
    }
}

Tagtoo.setFriendlist = function(){
	tagtoo_jQuery("#friendlist_middle").html("");
	var html = "";
    var counter = 0;
    Tagtoo.FriendPageAmount = parseInt(Tagtoo.friendlist.length / Tagtoo.FriendPageItemAmount) + 1;
	for(var i in Tagtoo.friendlist){
        var name = Tagtoo.friendlist[i]['name'];
		var id = Tagtoo.friendlist[i]['id'];
		html += Tagtoo.getFriendlistItem(name, id);
        counter++;
        if(counter > Tagtoo.FriendPageItemAmount){
            html += Tagtoo.getFriendlistNextBtn();
            break;
        }
	}
	tagtoo_jQuery("#friendlist_middle").append(html);
    tagtoo_jQuery("#friendlist_middle").scrollTop(0);
	Tagtoo.friendlistSettled = true;
}
Tagtoo.nextFriendlistSegment = function(){
    tagtoo_jQuery("#friendlist_middle").html("");
    var html = "";
    Tagtoo.nowFriendPage++;
    
    if(Tagtoo.nowFriendPage != 1){
        html += Tagtoo.getFriendlistPrevBtn();
    }
    
    var startPos = (Tagtoo.nowFriendPage-1) * Tagtoo.FriendPageItemAmount;
    var endPos = startPos + Tagtoo.FriendPageItemAmount;
    var name = "";
    var id = 0;
    
    for(var i in Tagtoo.friendlist){
        if(i >= startPos && i < endPos){
            name = Tagtoo.friendlist[i]['name'];
            id = Tagtoo.friendlist[i]['id'];
            html += Tagtoo.getFriendlistItem(name, id);
        }
    }
    
    if(Tagtoo.FriendPageAmount != Tagtoo.nowFriendPage){
        // there should have "more..." button
        html += Tagtoo.getFriendlistNextBtn();
    }
    
    tagtoo_jQuery("#friendlist_middle").append(html);
    tagtoo_jQuery("#friendlist_middle").scrollTop(0);
}

Tagtoo.prevFriendlistSegment = function(){
    tagtoo_jQuery("#friendlist_middle").html("");
    var html = "";
    Tagtoo.nowFriendPage--;
    
    if(Tagtoo.nowFriendPage != 1){
        // there should have "previous..." button
        html += Tagtoo.getFriendlistPrevBtn();
    }

    var startPos = (Tagtoo.nowFriendPage-1) * Tagtoo.FriendPageItemAmount;
    var endPos = startPos + Tagtoo.FriendPageItemAmount;
    var name = "";
    var id = 0;
    
    for(var i in Tagtoo.friendlist){
        if(i >= startPos && i < endPos){
            name = Tagtoo.friendlist[i]['name'];
            id = Tagtoo.friendlist[i]['id'];
            html += Tagtoo.getFriendlistItem(name, id);
        }
    }

    if(Tagtoo.FriendPageAmount != Tagtoo.nowFriendPage){
        // there should have "next..." button
        html += Tagtoo.getFriendlistNextBtn();
    }
    
    tagtoo_jQuery("#friendlist_middle").append(html);
    tagtoo_jQuery("#friendlist_middle").scrollTop(0);
}

Tagtoo.SetUserParas = function(uid, username, userkey, permission){
	Tagtoo.username = username;
	Tagtoo.uid = uid;
	Tagtoo.userkey = userkey;
    Tagtoo.permission = permission;
}
Tagtoo.ResetUserParas = function(){
	Tagtoo.username = "";
	Tagtoo.uid = "";
	Tagtoo.userkey = "";
	Tagtoo.friendlist = new Array();
	tagtoo_jQuery("#friendlist_middle").html("");
	Tagtoo.friendlistSettled = false;
    Tagtoo.deletable = false;
    Tagtoo.nowFriendPage = 1;
    Tagtoo.FriendPageAmount = 0;
    Tagtoo.permission = new Array();
}

Tagtoo.getFriendListCallback=function(response){

	Tagtoo.friendlist.push({"name": response.user, "id": response.uid});
	for(var i in response.friends.data){
		var name = response.friends.data[i]['name'];
		var id = response.friends.data[i]['id'];
		Tagtoo.friendlist.push({"name": name, "id": id});
	}
	Tagtoo.setFriendlist();
}

Tagtoo.getFriendList=function(){

	var getFriendsAPI = TagtooRequestSite + "/api/GetUserInfo/?callback=?";
    tagtoo_jQuery.getJSON(getFriendsAPI,Tagtoo.getFriendListCallback);
}

// set the facebook panel content and variables which about authority
// all the relative setting should only shown here
Tagtoo.SetLoginStatus = function(response){
	var status = response.status;
	// login
	if(status == true){
		Tagtoo.SetUserParas(response.uid, response.user, response.secret, response.permission);

		tagtoo_jQuery("#tagtoo_facebook_username").text("Hello, " + Tagtoo.username);
		// put the friendlist into catch, if it is not set before
		if(Tagtoo.friendlistSettled == false){
			Tagtoo.getFriendList();
		}
	}
	// not yet login in
	else{
		Tagtoo.ResetUserParas();
	}
    var imgID = response.imgID;
	// load tag data to tag_display_area after decide the login status
	// no tag data changed, no need to reload
	Tagtoo.resetPanel();
	//Tagtoo.LoadTagData("", imgID);
	//SetFacebookLike();
}
Tagtoo.SetFacebookLike = function(){
	if(initFB == false)
		initFacebookAPI();
	//tagtoo_jQuery("#facebook_like_button").html('<iframe src="http://www.facebook.com/plugins/like.php?href='+TagtooFileSite+'/facebook/image/?imgurl='+encodeURIComponent(Tagtoo.imgurl)+'&weburl='+encodeURIComponent(Tagtoo.weburl)+'&webtitle='+encodeURIComponent(Tagtoo.webtitle)+'&amp;layout=button_count&amp;show_faces=true&amp;width=100&amp;action=like&amp;font=lucida+grande&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:21px;" allowTransparency="true"></iframe>');
	tagtoo_jQuery("#facebook_like_button").html('<fb:like href="'+TagtooFileSite+'/facebook/image/?imgurl='+encodeURIComponent(Tagtoo.imgurl)+'&weburl='+encodeURIComponent(Tagtoo.weburl)+'&webtitle='+encodeURIComponent(Tagtoo.webtitle)+'" layout="button_count" width="100" font="lucida grande"></fb:like>');
	FB.XFBML.parse(document.getElementById('facebook_like_button'));
}
Tagtoo.fetchImgByProxy = function(imgurl){
    var fatcowAPI = "http://tagtooorg.fatcow.com/getpicfile.php";
    var transmit = "url=" + imgurl;
    Tagtoo.ajaxCrossDomain(fatcowAPI, transmit, "");
}
Tagtoo.postWall = function(data){
	var dictionary = new Array();
    var imgurl = "";
    Tagtoo.proxyServerTransmit = "";
	var pairs = data.split("&");
	for( i=0; i< pairs.length; ++i){
		var pos = pairs[i].indexOf("=");
		var substr1 = pairs[i].substring(0,pos);
		var substr2 = pairs[i].substring(pos+1);
        
        if(substr1 == 'attachment_picture'){
            imgurl = substr2;
            var resultImgurl = "";
            
            // if img come from special source, their hosting server will block the outside server get this image, so we should initiate our proxy server to get it.
            if(Tagtoo.isWretchImg(imgurl) || Tagtoo.isYamImg(imgurl) || Tagtoo.isSinaImg(imgurl)){
                //resultImgurl = "http://tagtooorg.fatcow.com/fetch_img.php?url=" + imgurl;
                resultImgurl = "http://tagtooorg.fatcow.com/getpicfile2.php?url=" + imgurl;
                resultImgurl = encodeURIComponent(resultImgurl);
            }
            // not special case of imgurl, tranditional way to handle
            else{
                resultImgurl = substr2;
            }
            Tagtoo.proxyServerTransmit += "&" + substr1 + "=" + resultImgurl;
        }
        else{
            Tagtoo.proxyServerTransmit += "&" + substr1 + "=" + substr2;
        }
	}
    Tagtoo.proxyServerTransmit = Tagtoo.proxyServerTransmit.substr(1);
    var PostWallAPI = TagtooRequestSite + "/api/PostWall/";
    Tagtoo.ajaxCrossDomain(PostWallAPI, Tagtoo.proxyServerTransmit, "");
}
Tagtoo.EnterReadMode = function(){
	Tagtoo.state = "read";
	tagtoo_jQuery("#tagtoo_friendlist").css({'display': 'none'});
	tagtoo_jQuery("#tagtoo_temp_dot").css({'display': 'none'});
	tagtoo_jQuery(".tagtoo_plugin_active_img").unbind('click', Tagtoo.prepareAddDot).css({'cursor': 'default'});
	tagtoo_jQuery("#add_tag_button").css({'background': 'url('+TagtooFileSite+'/plugin/img/new/add_tag_button.png)'}).children(".tagtoo_button_text_area").css({'font-weight': '400'});
	tagtoo_jQuery("#del_tag_button").css({'background': 'url('+TagtooFileSite+'/plugin/img/new/del_tag_button.png)'}).children(".tagtoo_button_text_area").css({'font-weight': '400'});
	tagtoo_jQuery(".tagtoo_regional_tag_content_mask").remove();
	tagtoo_jQuery(".tagtoo_plugin_active_img").unbind('click', Tagtoo.EnterReadMode);
    Tagtoo.disableImageMask();
}
Tagtoo.EnterAddMode = function(){
	Tagtoo.state = "write";
	Tagtoo.setPromptPanel('add');
	tagtoo_jQuery("#add_tag_button").css({'background': 'url('+TagtooFileSite+'/plugin/img/new/add_tag_button_highlight.png)'}).children(".tagtoo_button_text_area").css({'font-weight': '600'});
    Tagtoo.enableImageMask();
	tagtoo_jQuery("#tagtoo_img_mask").css({'cursor': 'crosshair'});
	tagtoo_jQuery("#tagtoo_img_mask").bind('click', Tagtoo.prepareAddDot);
}
Tagtoo.EnterRemoveMode = function(imgID){
	Tagtoo.state = 'remove';
	Tagtoo.setPromptPanel('remove');
	tagtoo_jQuery("#del_tag_button").css({'background': 'url('+TagtooFileSite+'/plugin/img/new/del_tag_button_highlight.png)'}).children(".tagtoo_button_text_area").css({'font-weight': '600'});;
	tagtoo_jQuery(".tagtoo_regional_tag_content"+imgID).each(function(){
		var top = tagtoo_jQuery(this).css('top');
		var left = tagtoo_jQuery(this).css('left');
		var background = tagtoo_jQuery(this).css('background-image');
		var title = tagtoo_jQuery(this).attr('name');
		var id = tagtoo_jQuery(this).attr('id');
		// clone mouseover action to the mask dots
		var dotClass = "";
		if(tagtoo_jQuery(this).hasClass('person')){
			dotClass = "person";
		}
		else if(tagtoo_jQuery(this).hasClass('product')){
			dotClass = "product";
		}
		else if(tagtoo_jQuery(this).hasClass('null')){
			dotClass = "null";
		}
		// item
		else{
			dotClass = "item";
		}
		
		tagtoo_jQuery("body").append("<div id='tagtoo_regional_tag_content_mask"+id+"' class='tagtoo_regional_tag_content_mask' title='" + Tagtoo.queryDictionary('DELETE') + " - " + title + "' name='"+title+"'></div>");
		tagtoo_jQuery("#tagtoo_regional_tag_content_mask"+id).css({'position': 'absolute', 'width': '22px', 'height': '22px', 'top': top, 'left': left, 'background': background, 'z-index': '99999998'});
		tagtoo_jQuery("#tagtoo_regional_tag_content_mask"+id).live('mouseover', function(){
			tagtoo_jQuery(this).css({'background': 'url('+TagtooFileSite+'/plugin/img/new/'+dotClass+'_dot_h.png) no-repeat'});
		});
		tagtoo_jQuery("#tagtoo_regional_tag_content_mask"+id).live('mouseout', function(){
			tagtoo_jQuery(this).css({'background': 'url('+TagtooFileSite+'/plugin/img/new/'+dotClass+'_dot.png) no-repeat'});
		});
		tagtoo_jQuery("#tagtoo_regional_tag_content_mask"+id).css({'cursor': 'url(' + TagtooFileSite + '/plugin/img/new/eraser_button.cur), default'});
	});
	tagtoo_jQuery(".tagtoo_regional_tag_content_mask").bind('click', Tagtoo.prepareDelDot);
	tagtoo_jQuery(".tagtoo_regional_tag_content_mask").css({'cursor': 'url(' + TagtooFileSite + '/plugin/img/new/eraser_button.cur), default'});
    Tagtoo.enableImageMask();
	tagtoo_jQuery("#tagtoo_img_mask").css({'cursor': 'url(' + TagtooFileSite + '/plugin/img/new/eraser_button.cur), default'});
	tagtoo_jQuery("#tagtoo_img_mask").one('click', Tagtoo.EnterReadMode);
}
// support window shopping fan page, added in 2011/5/19
// if user click the event dots, send a msg to his/her fb wall
tagtoo_jQuery(".tagtoo_regional_tag_content").live('click', function(){
	var this_refer_url = tagtoo_jQuery(this).parent().attr('href');
	if(this_refer_url == "http://www.facebook.com/winshopping")
		Tagtoo.supportWindowShopEvent();
});

Tagtoo.supportWindowShopEvent = function(){
	if(Tagtoo.ifLogin()){
		var message = "";
		var attachment_name = "就是愛購物粉絲獨享好康!";
		var attachment_caption = "【活動時間】週週抽出幸運得獎者 【獎項內容】每週一物Yahoo購物商品(價值$100~$500) 【活動辦法】當妳看到妳在粉絲團留下這段訊息時就表示妳已經參加抽獎了，並祝您幸運中獎";
		var attachment_link = Tagtoo.weburl;
		var attachment_description = Tagtoo.queryDictionary('POWERED_BY_TAGTOO');
		var attachment_picture = "https://lh6.googleusercontent.com/-WjsbESkcuOc/TdgjL53OfkI/AAAAAAAAAeU/e1IvFqzud4I/s288/228717_131435490265355_127177320691172_213473_6861891_n.jpg";
		// fan page id
		var fid = "127177320691172";
		// post msg to wall of fan page and the current facebook user
		var data = "message=" + message + "&profile_id=" + fid + "&attachment_name=" + encodeURIComponent(attachment_name) + "&attachment_caption=" + attachment_caption + "&attachment_link=" + attachment_link + "&attachment_description=" + encodeURIComponent(attachment_description) + "&attachment_picture=" + attachment_picture;
		Tagtoo.postWall(data);
		
		data = "message=" + message + "&attachment_name=" + encodeURIComponent(attachment_name) + "&attachment_caption=" + attachment_caption + "&attachment_link=" + attachment_link + "&attachment_description=" + encodeURIComponent(attachment_description) + "&attachment_picture=" + attachment_picture;
		Tagtoo.postWall(data);
	}
}
// specail requirement added in 2011/5/22, to solve the storage error which cause by imgurl to long(over 500 chars).
Tagtoo.truncateOverLengthImageUrl = function(imgurl){
	if(imgurl.indexOf("googleusercontent") > -1){
		var pos = imgurl.lastIndexOf("/");
		imgurl = imgurl.substr(0, pos+1);
	}
	return imgurl;
}

// to solve position of text of div.tagtoo_button_text_area
Tagtoo.cssModify = function(){
    if(tagtoo_jQuery.browser.msie){
        tagtoo_jQuery(".tagtoo_button_text_area").css({'paddingTop': '4px'});
    }
}
;(function(){
	var scripts = document.getElementsByTagName('script');
	var width = false;
	for( var i = 0; i< scripts.length ; i++ ){
		if( scripts[i].src.indexOf( 'tagtoo_plugin.js' ) >= 0 ){
			var src = scripts[i].src;
            if(Tagtoo.weburl.indexOf("http://tagtooorg.fatcow.com/index.php") >= 0)
                return false;
			if(TagtooRequestSite != "http://yam.tagtoo.org"){
				if(tagtoo_jQuery(scripts[i]).parent().prop('tagName') == 'HEAD'){
					return false;
				}
			}
			if(scripts[i].src.indexOf( 'width=' )>0){
				width = src.substring(src.lastIndexOf('width=')+6);
			}
			break;
		}
	}
	document.write('<div id="tagtoo-sidebar-container"></div>');
	window.onload =function(){
		width = width ? width : '180px';
		tagtoo_jQuery('#tagtoo-sidebar-container').html(
			'<div style="position:absolute;z-index:99999;height:30px;cursor:pointer" id="tagtoo-sidebar-login"></div><iframe id="tagtoo-sidebar-iframe" frameborder="0" marginheight="0" marginwidth = "0" scrolling = "no" style="z-index:999;width:'+width+';height:250px;margin:0 auto;position:relative" src="'+TagtooRequestSite+'/sidebar.html"></iframe>'
		);

		
		tagtoo_jQuery('#tagtoo-sidebar-login').width(tagtoo_jQuery('#tagtoo-sidebar-iframe').width()/2).offset({
		   'top' : tagtoo_jQuery('#tagtoo-sidebar-iframe').offset().top + (tagtoo_jQuery('#tagtoo-sidebar-iframe').height() - 35),
		   'left' : tagtoo_jQuery('#tagtoo-sidebar-iframe').offset().left + (tagtoo_jQuery('#tagtoo-sidebar-iframe').width() /2)
		}).click(function(){
			// check the dictionary defined above to decide appId
			var appId = Tagtoo.queryFacebookAppId(TagtooRequestSite);
			// A Landing page for facebook login
			var DomainLoginPage = TagtooRequestSite + "/facebook_login_page";
			//alert(appId + "/" + DomainLoginPage);
			
			my_window = window.open("https://www.facebook.com/dialog/oauth?client_id=" + appId + "&redirect_uri=" + DomainLoginPage + "&scope=email,publish_stream", 'FacebookLoginWindow', 'height=550, width=750, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no, fullscreen=no');// + "&response_type=token");
			var intervalId = setInterval(function() {
				if (my_window.closed) {
					clearInterval(intervalId);
					var LoginAPI = TagtooRequestSite + "/api/Login/" ;
					Tagtoo.ajaxCrossDomain(LoginAPI, "secret=" + Tagtoo.pageOwnerKey, "Tagtoo.sidebarLoginCallback");
				}
			}, 750);
		});
	}
})();
// Check which image is seeable and load tag data of seeable image 
Tagtoo.checkImageseeable = function(){
    tagtoo_jQuery("img").each(function(){
        var imgobj = tagtoo_jQuery(this);
        if(Tagtoo.isInsideVisableArea(imgobj)){
            if(imgobj.width() > 300 || imgobj.height() > 300){
                if(!imgobj.data('tagtoo_imgobj')){
                    var imgID =  new Date().getTime()
                    imgobj.data('tagtoo_imgobj', imgID);
                    imgobj.addClass("tagtoo_imgobj"+imgID);
                }
                if(imgobj.data('loaded') != 'loaded')
                    Tagtoo.preloadTagData(imgobj.data('tagtoo_imgobj'));
            }
        }
    });
}

// for cmoremap, embed the old version ui
if(Tagtoo.weburl.indexOf("http://www.cmoremap.com.tw/") != -1){
	Tagtoo.importFile(TagtooFileSite+"/site_media/plugin/tagtoo.css", "css", document, "head");
	Tagtoo.importFile(TagtooFileSite+"/site_media/plugin/fetch.js", "js", document, "head");
}
else{
	tagtoo_jQuery(document).ready(function(){
		Tagtoo.setPageOwnerParas();
		Tagtoo.authority = Tagtoo.checkPrivacy(); // if authority == private, then it need to check authority during addImage
		Tagtoo.createCoreElements(); // create #tagtoo_panel #tagtoo_friendlist and #tagtoo_temp_dot before image is mouseovered to save creation time
        
        // check at the first time to avoid user don't scroll the screen
        var counter = 0;
        // try five times
        var intervalId = setInterval(function() {
            if(counter == 5){
                clearInterval(intervalId);
            }
            else{
                Tagtoo.checkImageseeable();
                counter++;
            }
        }, 2000);
        
        
		tagtoo_jQuery("img").live('mouseenter', function(){
            var obj = tagtoo_jQuery(this);
            if(obj.hasClass('avoid_tagtooPlugin'))
                return;
                
            // check image size limitation
            if(obj.width() < 300 && obj.height() < 300)
                return;
                
            if(!Tagtoo.doInitPlugin(obj)){
                return;
            }

            
            // google analytics, record this action
            _gaq.push(['_setAccount', 'UA-18757665-1']);
            _gaq.push(['_trackEvent', 'Tagtoo plugin', 'Displayed', ''])
			
			//tagtoo_jQuery(".tagtoo_regional_tag_content").hide();
            
            var imgID;
            if(obj.data('tagtoo_imgobj')){
                imgID = obj.data('tagtoo_imgobj');
            }
            else{
                imgID =  new Date().getTime()
                obj.data('tagtoo_imgobj', imgID);
                obj.addClass("tagtoo_imgobj"+imgID);
            }
            //alert("remove the hint");
            tagtoo_jQuery("#tagtoo_tag_hint"+imgID).remove();
            
            // in other mode, when mouseover the image, no any action will be taken
			if(Tagtoo.state != "read"){
				tagtoo_jQuery(".tagtoo_regional_tag_content" + imgID).css({'display': 'block'});
				return;
			}
			
			// if this image is already active(there is only one active image at a time), don't execute those standard processes again
			if(obj.hasClass('tagtoo_plugin_active_img')){
				// set css attributes of tagtoo_panel
				tagtoo_jQuery("#tagtoo_panel").css({'left': Tagtoo.PanelLeft+"px", 'top': Tagtoo.PanelTop+"px", 'width': Tagtoo.PanelWidth+"px", 'display': 'block'});
				//alert("image already active! It's imgID: "+imgID);
                // reveal those dot data
				tagtoo_jQuery(".tagtoo_regional_tag_content" + imgID).css({'display': 'block'});
				return;
			}
			else{
				// reset the class attribute to ensure their is only one image has 'tagtoo_plugin_active_img'
				tagtoo_jQuery('.tagtoo_plugin_active_img').removeClass('tagtoo_plugin_active_img');
				obj.addClass('tagtoo_plugin_active_img');
				// set the "Tagtoo global" variables, including imgurl imgsize imgpos
				Tagtoo.imgParasSetting(obj);

				// check image size limitation
				if(Tagtoo.imgWidth < 300 && Tagtoo.imgHeight < 300){return;}
				//alert("image not active yet! It's imgID: "+imgID);
                
                // our log static system
                var LogActionAPI = TagtooRequestSite + "/api/LogAction/";
                //Tagtoo.ajaxCrossDomain(LogActionAPI, "action=" + "display" + "&url=" + encodeURIComponent(Tagtoo.imgurl) + "&secret=" + Tagtoo.pageOwnerKey + "&trace_code=" + Tagtoo.pageOwnerTraceCode, "Tagtoo.LogActionCallback");
                
				// set width and height of div#tagtoo_panel
				Tagtoo.panelPosSetting();
				// set current state
				Tagtoo.state = "read";
			
				// set content of facebook_panel incording to the login status
				// after determine the login status, load tag data to tag_display_area accroding to login status
				// do Tagtoo.LoadTagData() at here!
				Tagtoo.CheckLoginStatusWithImgID(tagtoo_jQuery(this).data('tagtoo_imgobj'));
				
				
				// set position of tagtoo_panel and display it!
				tagtoo_jQuery("#tagtoo_panel").css({'left': Tagtoo.PanelLeft+"px", 'top': Tagtoo.PanelTop+"px", 'display': 'block'});
                Tagtoo.LoadTagData("", imgID);
                tagtoo_jQuery(".tagtoo_regional_tag_content" + imgID).css({'display': 'block'});
                //alert(tagtoo_jQuery(".tagtoo_regional_tag_content" + imgID).length);
			}
		});
		tagtoo_jQuery("img").live('mouseout', function(){
			if(Tagtoo.state == "read"){
                var imgID = tagtoo_jQuery(this).data('tagtoo_imgobj');
				tagtoo_jQuery("#tagtoo_panel").hide();
				tagtoo_jQuery(".tagtoo_regional_tag_content"+imgID).hide();
			}
		});
		
		// set once, not everytime mouse over the image to avoid bind several times
		Tagtoo.setCoreElementInteractions();
		Tagtoo.setButtonActions();
		Tagtoo.setButtonHighlightEffect();
		Tagtoo.setTagActions();
		Tagtoo.inputFeildSetting();
		Tagtoo.friendItemEffects();
		Tagtoo.setCoreElementActions();
        Tagtoo.setGoogleAnalytics();
        
        
        tagtoo_jQuery(window).scroll(function (){
            Tagtoo.checkImageseeable();
        });
        tagtoo_jQuery(window).click(function (){
            Tagtoo.checkImageseeable();
        });
	});
}

Tagtoo.setGoogleAnalytics = function(){
    var ga = document.createElement('script');
    ga.type = 'text/javascript';
    ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
}
Tagtoo.imgParasSetting = function(imgObj){
	Tagtoo.imgWidth = imgObj.width();
	Tagtoo.imgHeight = imgObj.height();
	Tagtoo.imgTop = imgObj.offset().top;
	Tagtoo.imgLeft = imgObj.offset().left;
	Tagtoo.imgurl = imgObj.attr('src');
}
Tagtoo.panelPosSetting = function(){
	var tagtooPanelPos = Tagtoo.decideTagtooPanelPos();
	Tagtoo.PanelTop = tagtooPanelPos['tagtooPanelTop'];
	Tagtoo.PanelLeft = tagtooPanelPos['tagtooPanelLeft'];
}
Tagtoo.weatherABelongsToB = function(A, B){
    if (B.find('*').index(A) != -1) {
        return true;
    }
    else{
        return false;
    }
}
// true if imgObj is in our Init list(or not in Yam domain), false if imgObj is not in Init list(Yam provide this list)!
Tagtoo.doInitPlugin = function(imgObj){
    var avoidDomList = new Array("#mainContent","#articleBlock","#bodyFrame","#rightBlock");
    if(Tagtoo.isYamLink(Tagtoo.weburl)){
        for(var i=0; i<avoidDomList.length; ++i){
            if(Tagtoo.weatherABelongsToB(imgObj, tagtoo_jQuery(avoidDomList[i])) == true){
                return true;
            }
        }
        return false;
    }
    else{
        return true;
    }
}
