// diff-match-patch 20080310 (c) 2008 Neil Fraser (http://code.google.com/p/google-diff-match-patch/)
function diff_match_patch(){this.Diff_Timeout=1.0;this.Diff_EditCost=4;this.Diff_DualThreshold=32;this.Match_Balance=0.5;this.Match_Threshold=0.5;this.Match_MinLength=100;this.Match_MaxLength=1000;this.Patch_Margin=4;function getMaxBits(){var a=0;var b=1;var c=2;while(b!=c){a++;b=c;c=c<<1}return a}this.Match_MaxBits=getMaxBits()}var DIFF_DELETE=-1;var DIFF_INSERT=1;var DIFF_EQUAL=0;diff_match_patch.prototype.diff_main=function(a,b,c){if(a==b){return[[DIFF_EQUAL,a]]}if(typeof c=='undefined'){c=true}var d=c;var e=this.diff_commonPrefix(a,b);var f=a.substring(0,e);a=a.substring(e);b=b.substring(e);e=this.diff_commonSuffix(a,b);var g=a.substring(a.length-e);a=a.substring(0,a.length-e);b=b.substring(0,b.length-e);var h=this.diff_compute(a,b,d);if(f){h.unshift([DIFF_EQUAL,f])}if(g){h.push([DIFF_EQUAL,g])}this.diff_cleanupMerge(h);return h};diff_match_patch.prototype.diff_compute=function(b,c,d){var e;if(!b){return[[DIFF_INSERT,c]]}if(!c){return[[DIFF_DELETE,b]]}var f=b.length>c.length?b:c;var g=b.length>c.length?c:b;var i=f.indexOf(g);if(i!=-1){e=[[DIFF_INSERT,f.substring(0,i)],[DIFF_EQUAL,g],[DIFF_INSERT,f.substring(i+g.length)]];if(b.length>c.length){e[0][0]=e[2][0]=DIFF_DELETE}return e}f=g=null;var h=this.diff_halfMatch(b,c);if(h){var k=h[0];var l=h[1];var m=h[2];var n=h[3];var o=h[4];var p=this.diff_main(k,m,d);var q=this.diff_main(l,n,d);return p.concat([[DIFF_EQUAL,o]],q)}if(d&&(b.length<100||c.length<100)){d=false}var r;if(d){var a=this.diff_linesToChars(b,c);b=a[0];c=a[1];r=a[2]}e=this.diff_map(b,c);if(!e){e=[[DIFF_DELETE,b],[DIFF_INSERT,c]]}if(d){this.diff_charsToLines(e,r);this.diff_cleanupSemantic(e);e.push([DIFF_EQUAL,'']);var s=0;var t=0;var u=0;var v='';var w='';while(s<e.length){switch(e[s][0]){case DIFF_INSERT:u++;w+=e[s][1];break;case DIFF_DELETE:t++;v+=e[s][1];break;case DIFF_EQUAL:if(t>=1&&u>=1){var a=this.diff_main(v,w,false);e.splice(s-t-u,t+u);s=s-t-u;for(var j=a.length-1;j>=0;j--){e.splice(s,0,a[j])}s=s+a.length}u=0;t=0;v='';w='';break}s++}e.pop()}return e};diff_match_patch.prototype.diff_linesToChars=function(g,h){var i=[];var j={};i[0]='';function diff_linesToCharsMunge(a){var b='';var c=0;var d=-1;var e=i.length;while(d<a.length-1){d=a.indexOf('\n',c);if(d==-1){d=a.length-1}var f=a.substring(c,d+1);c=d+1;if(j.hasOwnProperty?j.hasOwnProperty(f):(j[f]!==undefined)){b+=String.fromCharCode(j[f])}else{b+=String.fromCharCode(e);j[f]=e;i[e++]=f}}return b}var k=diff_linesToCharsMunge(g);var l=diff_linesToCharsMunge(h);return[k,l,i]};diff_match_patch.prototype.diff_charsToLines=function(a,b){for(var x=0;x<a.length;x++){var c=a[x][1];var d=[];for(var y=0;y<c.length;y++){d[y]=b[c.charCodeAt(y)]}a[x][1]=d.join('')}};diff_match_patch.prototype.diff_map=function(b,c){var e=(new Date()).getTime()+this.Diff_Timeout*1000;var f=b.length+c.length-1;var g=this.Diff_DualThreshold*2<f;var h=[];var i=[];var j={};var l={};j[1]=0;l[1]=0;var x,y;var m;var n={};var o=false;var hasOwnProperty=!!(n.hasOwnProperty);var p=(b.length+c.length)%2;for(var d=0;d<f;d++){if(this.Diff_Timeout>0&&(new Date()).getTime()>e){return null}h[d]={};for(var k=-d;k<=d;k+=2){if(k==-d||k!=d&&j[k-1]<j[k+1]){x=j[k+1]}else{x=j[k-1]+1}y=x-k;if(g){m=x+','+y;if(p&&(hasOwnProperty?n.hasOwnProperty(m):(n[m]!==undefined))){o=true}if(!p){n[m]=d}}while(!o&&x<b.length&&y<c.length&&b.charAt(x)==c.charAt(y)){x++;y++;if(g){m=x+','+y;if(p&&(hasOwnProperty?n.hasOwnProperty(m):(n[m]!==undefined))){o=true}if(!p){n[m]=d}}}j[k]=x;h[d][x+','+y]=true;if(x==b.length&&y==c.length){return this.diff_path1(h,b,c)}else if(o){i=i.slice(0,n[m]+1);var a=this.diff_path1(h,b.substring(0,x),c.substring(0,y));return a.concat(this.diff_path2(i,b.substring(x),c.substring(y)))}}if(g){i[d]={};for(var k=-d;k<=d;k+=2){if(k==-d||k!=d&&l[k-1]<l[k+1]){x=l[k+1]}else{x=l[k-1]+1}y=x-k;m=(b.length-x)+','+(c.length-y);if(!p&&(hasOwnProperty?n.hasOwnProperty(m):(n[m]!==undefined))){o=true}if(p){n[m]=d}while(!o&&x<b.length&&y<c.length&&b.charAt(b.length-x-1)==c.charAt(c.length-y-1)){x++;y++;m=(b.length-x)+','+(c.length-y);if(!p&&(hasOwnProperty?n.hasOwnProperty(m):(n[m]!==undefined))){o=true}if(p){n[m]=d}}l[k]=x;i[d][x+','+y]=true;if(o){h=h.slice(0,n[m]+1);var a=this.diff_path1(h,b.substring(0,b.length-x),c.substring(0,c.length-y));return a.concat(this.diff_path2(i,b.substring(b.length-x),c.substring(c.length-y)))}}}}return null};diff_match_patch.prototype.diff_path1=function(a,b,c){var e=[];var x=b.length;var y=c.length;var f=null;for(var d=a.length-2;d>=0;d--){while(1){if(a[d].hasOwnProperty?a[d].hasOwnProperty((x-1)+','+y):(a[d][(x-1)+','+y]!==undefined)){x--;if(f===DIFF_DELETE){e[0][1]=b.charAt(x)+e[0][1]}else{e.unshift([DIFF_DELETE,b.charAt(x)])}f=DIFF_DELETE;break}else if(a[d].hasOwnProperty?a[d].hasOwnProperty(x+','+(y-1)):(a[d][x+','+(y-1)]!==undefined)){y--;if(f===DIFF_INSERT){e[0][1]=c.charAt(y)+e[0][1]}else{e.unshift([DIFF_INSERT,c.charAt(y)])}f=DIFF_INSERT;break}else{x--;y--;if(f===DIFF_EQUAL){e[0][1]=b.charAt(x)+e[0][1]}else{e.unshift([DIFF_EQUAL,b.charAt(x)])}f=DIFF_EQUAL}}}return e};diff_match_patch.prototype.diff_path2=function(a,b,c){var e=[];var f=0;var x=b.length;var y=c.length;var g=null;for(var d=a.length-2;d>=0;d--){while(1){if(a[d].hasOwnProperty?a[d].hasOwnProperty((x-1)+','+y):(a[d][(x-1)+','+y]!==undefined)){x--;if(g===DIFF_DELETE){e[f-1][1]+=b.charAt(b.length-x-1)}else{e[f++]=[DIFF_DELETE,b.charAt(b.length-x-1)]}g=DIFF_DELETE;break}else if(a[d].hasOwnProperty?a[d].hasOwnProperty(x+','+(y-1)):(a[d][x+','+(y-1)]!==undefined)){y--;if(g===DIFF_INSERT){e[f-1][1]+=c.charAt(c.length-y-1)}else{e[f++]=[DIFF_INSERT,c.charAt(c.length-y-1)]}g=DIFF_INSERT;break}else{x--;y--;if(g===DIFF_EQUAL){e[f-1][1]+=b.charAt(b.length-x-1)}else{e[f++]=[DIFF_EQUAL,b.charAt(b.length-x-1)]}g=DIFF_EQUAL}}}return e};diff_match_patch.prototype.diff_commonPrefix=function(a,b){if(!a||!b||a.charCodeAt(0)!==b.charCodeAt(0)){return 0}var c=0;var d=Math.min(a.length,b.length);var e=d;var f=0;while(c<e){if(a.substring(f,e)==b.substring(f,e)){c=e;f=c}else{d=e}e=Math.floor((d-c)/2+c)}return e};diff_match_patch.prototype.diff_commonSuffix=function(a,b){if(!a||!b||a.charCodeAt(a.length-1)!==b.charCodeAt(b.length-1)){return 0}var c=0;var d=Math.min(a.length,b.length);var e=d;var f=0;while(c<e){if(a.substring(a.length-e,a.length-f)==b.substring(b.length-e,b.length-f)){c=e;f=c}else{d=e}e=Math.floor((d-c)/2+c)}return e};diff_match_patch.prototype.diff_halfMatch=function(h,k){var l=h.length>k.length?h:k;var m=h.length>k.length?k:h;if(l.length<10||m.length<1){return null}var n=this;function diff_halfMatchI(a,b,i){var c=a.substring(i,i+Math.floor(a.length/4));var j=-1;var d='';var e,best_longtext_b,best_shorttext_a,best_shorttext_b;while((j=b.indexOf(c,j+1))!=-1){var f=n.diff_commonPrefix(a.substring(i),b.substring(j));var g=n.diff_commonSuffix(a.substring(0,i),b.substring(0,j));if(d.length<g+f){d=b.substring(j-g,j)+b.substring(j,j+f);e=a.substring(0,i-g);best_longtext_b=a.substring(i+f);best_shorttext_a=b.substring(0,j-g);best_shorttext_b=b.substring(j+f)}}if(d.length>=a.length/2){return[e,best_longtext_b,best_shorttext_a,best_shorttext_b,d]}else{return null}}var o=diff_halfMatchI(l,m,Math.ceil(l.length/4));var p=diff_halfMatchI(l,m,Math.ceil(l.length/2));var q;if(!o&&!p){return null}else if(!p){q=o}else if(!o){q=p}else{q=o[4].length>p[4].length?o:p}var r,text1_b,text2_a,text2_b;if(h.length>k.length){r=q[0];text1_b=q[1];text2_a=q[2];text2_b=q[3]}else{text2_a=q[0];text2_b=q[1];r=q[2];text1_b=q[3]}var s=q[4];return[r,text1_b,text2_a,text2_b,s]};diff_match_patch.prototype.diff_cleanupSemantic=function(a){var b=false;var c=[];var d=0;var e=null;var f=0;var g=0;var h=0;while(f<a.length){if(a[f][0]==DIFF_EQUAL){c[d++]=f;g=h;h=0;e=a[f][1]}else{h+=a[f][1].length;if(e!==null&&(e.length<=g)&&(e.length<=h)){a.splice(c[d-1],0,[DIFF_DELETE,e]);a[c[d-1]+1][0]=DIFF_INSERT;d--;d--;f=d?c[d-1]:-1;g=0;h=0;e=null;b=true}}f++}if(b){this.diff_cleanupMerge(a)}this.diff_cleanupSemanticLossless(a)};diff_match_patch.prototype.diff_cleanupSemanticLossless=function(f){function diff_cleanupSemanticScore(a,b,c){var d=/\s/;var e=0;if(a.charAt(a.length-1).match(d)||b.charAt(0).match(d)){e++}if(b.charAt(b.length-1).match(d)||c.charAt(0).match(d)){e++}return e}var g=1;while(g<f.length-1){if(f[g-1][0]==DIFF_EQUAL&&f[g+1][0]==DIFF_EQUAL){var h=f[g-1][1];var i=f[g][1];var j=f[g+1][1];var k=this.diff_commonSuffix(h,i);if(k){var l=i.substring(i.length-k);h=h.substring(0,h.length-k);i=l+i.substring(0,i.length-k);j=l+j}var m=h;var n=i;var o=j;var p=diff_cleanupSemanticScore(h,i,j);while(i.charAt(0)===j.charAt(0)){h+=i.charAt(0);i=i.substring(1)+j.charAt(0);j=j.substring(1);var q=diff_cleanupSemanticScore(h,i,j);if(q>=p){p=q;m=h;n=i;o=j}}if(f[g-1][1]!=m){f[g-1][1]=m;f[g][1]=n;f[g+1][1]=o}}g++}};diff_match_patch.prototype.diff_cleanupEfficiency=function(a){var b=false;var c=[];var d=0;var e='';var f=0;var g=false;var h=false;var i=false;var j=false;while(f<a.length){if(a[f][0]==DIFF_EQUAL){if(a[f][1].length<this.Diff_EditCost&&(i||j)){c[d++]=f;g=i;h=j;e=a[f][1]}else{d=0;e=''}i=j=false}else{if(a[f][0]==DIFF_DELETE){j=true}else{i=true}if(e&&((g&&h&&i&&j)||((e.length<this.Diff_EditCost/2)&&(g+h+i+j)==3))){a.splice(c[d-1],0,[DIFF_DELETE,e]);a[c[d-1]+1][0]=DIFF_INSERT;d--;e='';if(g&&h){i=j=true;d=0}else{d--;f=d?c[d-1]:-1;i=j=false}b=true}}f++}if(b){this.diff_cleanupMerge(a)}};diff_match_patch.prototype.diff_cleanupMerge=function(a){a.push([DIFF_EQUAL,'']);var b=0;var c=0;var d=0;var e='';var f='';var g;while(b<a.length){switch(a[b][0]){case DIFF_INSERT:d++;f+=a[b][1];b++;break;case DIFF_DELETE:c++;e+=a[b][1];b++;break;case DIFF_EQUAL:if(c!==0||d!==0){if(c!==0&&d!==0){g=this.diff_commonPrefix(f,e);if(g!==0){if((b-c-d)>0&&a[b-c-d-1][0]==DIFF_EQUAL){a[b-c-d-1][1]+=f.substring(0,g)}else{a.splice(0,0,[DIFF_EQUAL,f.substring(0,g)]);b++}f=f.substring(g);e=e.substring(g)}g=this.diff_commonSuffix(f,e);if(g!==0){a[b][1]=f.substring(f.length-g)+a[b][1];f=f.substring(0,f.length-g);e=e.substring(0,e.length-g)}}if(c===0){a.splice(b-c-d,c+d,[DIFF_INSERT,f])}else if(d===0){a.splice(b-c-d,c+d,[DIFF_DELETE,e])}else{a.splice(b-c-d,c+d,[DIFF_DELETE,e],[DIFF_INSERT,f])}b=b-c-d+(c?1:0)+(d?1:0)+1}else if(b!==0&&a[b-1][0]==DIFF_EQUAL){a[b-1][1]+=a[b][1];a.splice(b,1)}else{b++}d=0;c=0;e='';f='';break}}if(a[a.length-1][1]===''){a.pop()}var h=false;b=1;while(b<a.length-1){if(a[b-1][0]==DIFF_EQUAL&&a[b+1][0]==DIFF_EQUAL){if(a[b][1].substring(a[b][1].length-a[b-1][1].length)==a[b-1][1]){a[b][1]=a[b-1][1]+a[b][1].substring(0,a[b][1].length-a[b-1][1].length);a[b+1][1]=a[b-1][1]+a[b+1][1];a.splice(b-1,1);h=true}else if(a[b][1].substring(0,a[b+1][1].length)==a[b+1][1]){a[b-1][1]+=a[b+1][1];a[b][1]=a[b][1].substring(a[b+1][1].length)+a[b+1][1];a.splice(b+1,1);h=true}}b++}if(h){this.diff_cleanupMerge(a)}};diff_match_patch.prototype.diff_addIndex=function(a){var i=0;for(var x=0;x<a.length;x++){a[x][2]=i;if(a[x][0]!==DIFF_DELETE){i+=a[x][1].length}}};diff_match_patch.prototype.diff_xIndex=function(a,b){var c=0;var d=0;var e=0;var f=0;var x;for(x=0;x<a.length;x++){if(a[x][0]!==DIFF_INSERT){c+=a[x][1].length}if(a[x][0]!==DIFF_DELETE){d+=a[x][1].length}if(c>b){break}e=c;f=d}if(a.length!=x&&a[x][0]===DIFF_DELETE){return f}return f+(b-e)};diff_match_patch.prototype.diff_prettyHtml=function(a){this.diff_addIndex(a);var b=[];for(var x=0;x<a.length;x++){var m=a[x][0];var t=a[x][1];var i=a[x][2];t=t.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');t=t.replace(/\n/g,'&para;<BR>');switch(m){case DIFF_INSERT:b[x]='<INS STYLE="background:#E6FFE6;" TITLE="i='+i+'">'+t+'</INS>';break;case DIFF_DELETE:b[x]='<DEL STYLE="background:#FFE6E6;" TITLE="i='+i+'">'+t+'</DEL>';break;case DIFF_EQUAL:b[x]='<SPAN TITLE="i='+i+'">'+t+'</SPAN>';break}}return b.join('')};diff_match_patch.prototype.diff_text1=function(a){var b=[];for(var x=0;x<a.length;x++){if(a[x][0]!==DIFF_INSERT){b[x]=a[x][1]}}return b.join('')};diff_match_patch.prototype.diff_text2=function(a){var b=[];for(var x=0;x<a.length;x++){if(a[x][0]!==DIFF_DELETE){b[x]=a[x][1]}}return b.join('')};diff_match_patch.prototype.diff_toDelta=function(a){var b=[];for(var x=0;x<a.length;x++){switch(a[x][0]){case DIFF_INSERT:b[x]='+'+encodeURI(a[x][1]);break;case DIFF_DELETE:b[x]='-'+a[x][1].length;break;case DIFF_EQUAL:b[x]='='+a[x][1].length;break}}return b.join('\t').replace(/%20/g,' ')};diff_match_patch.prototype.diff_fromDelta=function(a,b){var c=[];var d=0;var e=0;var f=b.split(/\t/g);for(var x=0;x<f.length;x++){var g=f[x].substring(1);switch(f[x].charAt(0)){case'+':try{c[d++]=[DIFF_INSERT,decodeURI(g)]}catch(ex){throw new Error('Illegal escape in diff_fromDelta: '+g);}break;case'-':case'=':var n=parseInt(g,10);if(isNaN(n)||n<0){throw new Error('Invalid number in diff_fromDelta: '+g);}var h=a.substring(e,e+=n);if(f[x].charAt(0)=='='){c[d++]=[DIFF_EQUAL,h]}else{c[d++]=[DIFF_DELETE,h]}break;default:if(f[x]){throw new Error('Invalid diff operation in diff_fromDelta: '+f[x]);}}}if(e!=a.length){throw new Error('Delta length ('+e+') does not equal source text length ('+a.length+').');}return c};diff_match_patch.prototype.match_main=function(a,b,c){c=Math.max(0,Math.min(c,a.length-b.length));if(a==b){return 0}else if(a.length===0){return null}else if(a.substring(c,c+b.length)==b){return c}else{return this.match_bitap(a,b,c)}};diff_match_patch.prototype.match_bitap=function(a,b,c){if(b.length>this.Match_MaxBits){throw new Error('Pattern too long for this browser.');}var s=this.match_alphabet(b);var f=a.length;f=Math.max(f,this.Match_MinLength);f=Math.min(f,this.Match_MaxLength);var g=this;function match_bitapScore(e,x){var d=Math.abs(c-x);return(e/b.length/g.Match_Balance)+(d/f/(1.0-g.Match_Balance))}var h=this.Match_Threshold;var i=a.indexOf(b,c);if(i!=-1){h=Math.min(match_bitapScore(0,i),h)}i=a.lastIndexOf(b,c+b.length);if(i!=-1){h=Math.min(match_bitapScore(0,i),h)}var k=1<<(b.length-1);i=null;var l,bin_mid;var m=Math.max(c+c,a.length);var n;for(var d=0;d<b.length;d++){var o=Array(a.length);l=c;bin_mid=m;while(l<bin_mid){if(match_bitapScore(d,bin_mid)<h){l=bin_mid}else{m=bin_mid}bin_mid=Math.floor((m-l)/2+l)}m=bin_mid;var p=Math.max(0,c-(bin_mid-c)-1);var q=Math.min(a.length-1,b.length+bin_mid);if(a.charAt(q)==b.charAt(b.length-1)){o[q]=(1<<(d+1))-1}else{o[q]=(1<<d)-1}for(var j=q-1;j>=p;j--){if(d===0){o[j]=((o[j+1]<<1)|1)&s[a.charAt(j)]}else{o[j]=((o[j+1]<<1)|1)&s[a.charAt(j)]|((n[j+1]<<1)|1)|((n[j]<<1)|1)|n[j+1]}if(o[j]&k){var r=match_bitapScore(d,j);if(r<=h){h=r;i=j;if(j>c){p=Math.max(0,c-(j-c))}else{break}}}}if(match_bitapScore(d+1,c)>h){break}n=o}return i};diff_match_patch.prototype.match_alphabet=function(a){var s=Object();for(var i=0;i<a.length;i++){s[a.charAt(i)]=0}for(var i=0;i<a.length;i++){s[a.charAt(i)]|=1<<(a.length-i-1)}return s};diff_match_patch.prototype.patch_addContext=function(a,b){var c=b.substring(a.start2,a.start2+a.length1);var d=0;while(b.indexOf(c)!=b.lastIndexOf(c)&&c.length<this.Match_MaxBits-this.Patch_Margin-this.Patch_Margin){d+=this.Patch_Margin;c=b.substring(a.start2-d,a.start2+a.length1+d)}d+=this.Patch_Margin;var e=b.substring(a.start2-d,a.start2);if(e!==''){a.diffs.unshift([DIFF_EQUAL,e])}var f=b.substring(a.start2+a.length1,a.start2+a.length1+d);if(f!==''){a.diffs.push([DIFF_EQUAL,f])}a.start1-=e.length;a.start2-=e.length;a.length1+=e.length+f.length;a.length2+=e.length+f.length};diff_match_patch.prototype.patch_make=function(a,b,c){var d,text2,diffs;if(typeof b=='undefined'){diffs=a;d=this.diff_text1(diffs);text2=''}else{d=a;text2=b;if(typeof c!='undefined'){diffs=c}else{diffs=this.diff_main(d,text2,true);if(diffs.length>2){this.diff_cleanupSemantic(diffs);this.diff_cleanupEfficiency(diffs)}}}if(diffs.length===0){return[]}var e=[];var f=new patch_obj();var g=0;var h=0;var i=0;var j=d;var k=d;for(var x=0;x<diffs.length;x++){var l=diffs[x][0];var m=diffs[x][1];if(!g&&l!==DIFF_EQUAL){f.start1=h;f.start2=i}switch(l){case DIFF_INSERT:f.diffs[g++]=diffs[x];f.length2+=m.length;k=k.substring(0,i)+m+k.substring(i);break;case DIFF_DELETE:f.length1+=m.length;f.diffs[g++]=diffs[x];k=k.substring(0,i)+k.substring(i+m.length);break;case DIFF_EQUAL:if(m.length<=2*this.Patch_Margin&&g&&diffs.length!=x+1){f.diffs[g++]=diffs[x];f.length1+=m.length;f.length2+=m.length}else if(m.length>=2*this.Patch_Margin){if(g){this.patch_addContext(f,j);e.push(f);f=new patch_obj();g=0;j=k}}break}if(l!==DIFF_INSERT){h+=m.length}if(l!==DIFF_DELETE){i+=m.length}}if(g){this.patch_addContext(f,j);e.push(f)}return e};diff_match_patch.prototype.patch_apply=function(a,b){this.patch_splitMax(a);var c=[];var d=0;for(var x=0;x<a.length;x++){var e=a[x].start2+d;var f=this.diff_text1(a[x].diffs);var g=this.match_main(b,f,e);if(g===null){c[x]=false}else{c[x]=true;d=g-e;var h=b.substring(g,g+f.length);if(f==h){b=b.substring(0,g)+this.diff_text2(a[x].diffs)+b.substring(g+f.length)}else{var i=this.diff_main(f,h,false);this.diff_cleanupSemanticLossless(i);var j=0;var k;for(var y=0;y<a[x].diffs.length;y++){var l=a[x].diffs[y];if(l[0]!==DIFF_EQUAL){k=this.diff_xIndex(i,j)}if(l[0]===DIFF_INSERT){b=b.substring(0,g+k)+l[1]+b.substring(g+k)}else if(l[0]===DIFF_DELETE){b=b.substring(0,g+k)+b.substring(g+this.diff_xIndex(i,j+l[1].length))}if(l[0]!==DIFF_DELETE){j+=l[1].length}}}}}return[b,c]};diff_match_patch.prototype.patch_splitMax=function(a){for(var x=0;x<a.length;x++){if(a[x].length1>this.Match_MaxBits){var b=a[x];a.splice(x,1);var c=this.Match_MaxBits;var d=b.start1;var e=b.start2;var f='';while(b.diffs.length!==0){var g=new patch_obj();var h=true;g.start1=d-f.length;g.start2=e-f.length;if(f!==''){g.length1=g.length2=f.length;g.diffs.push([DIFF_EQUAL,f])}while(b.diffs.length!==0&&g.length1<c-this.Patch_Margin){var i=b.diffs[0][0];var j=b.diffs[0][1];if(i===DIFF_INSERT){g.length2+=j.length;e+=j.length;g.diffs.push(b.diffs.shift());h=false}else{j=j.substring(0,c-g.length1-this.Patch_Margin);g.length1+=j.length;d+=j.length;if(i===DIFF_EQUAL){g.length2+=j.length;e+=j.length}else{h=false}g.diffs.push([i,j]);if(j==b.diffs[0][1]){b.diffs.shift()}else{b.diffs[0][1]=b.diffs[0][1].substring(j.length)}}}f=this.diff_text2(g.diffs);f=f.substring(f.length-this.Patch_Margin);var k=this.diff_text1(b.diffs).substring(0,this.Patch_Margin);if(k!==''){g.length1+=k.length;g.length2+=k.length;if(g.diffs.length!==0&&g.diffs[g.diffs.length-1][0]===DIFF_EQUAL){g.diffs[g.diffs.length-1][1]+=k}else{g.diffs.push([DIFF_EQUAL,k])}}if(!h){a.splice(x++,0,g)}}}}};diff_match_patch.prototype.patch_toText=function(a){var b=[];for(var x=0;x<a.length;x++){b[x]=a[x]}return b.join('')};diff_match_patch.prototype.patch_fromText=function(a){var b=[];var c=a.split('\n');var d=0;while(d<c.length){var m=c[d].match(/^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$/);if(!m){throw new Error('Invalid patch string: '+c[d]);}var e=new patch_obj();b.push(e);e.start1=parseInt(m[1],10);if(m[2]===''){e.start1--;e.length1=1}else if(m[2]=='0'){e.length1=0}else{e.start1--;e.length1=parseInt(m[2],10)}e.start2=parseInt(m[3],10);if(m[4]===''){e.start2--;e.length2=1}else if(m[4]=='0'){e.length2=0}else{e.start2--;e.length2=parseInt(m[4],10)}d++;while(d<c.length){var f=c[d].charAt(0);try{var g=decodeURIComponent(c[d].substring(1))}catch(ex){throw new Error('Illegal escape in patch_fromText: '+g);}if(f=='-'){e.diffs.push([DIFF_DELETE,g])}else if(f=='+'){e.diffs.push([DIFF_INSERT,g])}else if(f==' '){e.diffs.push([DIFF_EQUAL,g])}else if(f=='@'){break}else if(f===''){}else{throw new Error('Invalid patch mode "'+f+'" in: '+g);}d++}}return b};function patch_obj(){this.diffs=[];this.start1=null;this.start2=null;this.length1=0;this.length2=0}patch_obj.prototype.toString=function(){var a,coords2;if(this.length1===0){a=this.start1+',0'}else if(this.length1==1){a=this.start1+1}else{a=(this.start1+1)+','+this.length1}if(this.length2===0){coords2=this.start2+',0'}else if(this.length2==1){coords2=this.start2+1}else{coords2=(this.start2+1)+','+this.length2}var b=['@@ -'+a+' +'+coords2+' @@\n'];var c;for(var x=0;x<this.diffs.length;x++){switch(this.diffs[x][0]){case DIFF_INSERT:c='+';break;case DIFF_DELETE:c='-';break;case DIFF_EQUAL:c=' ';break}b[x+1]=c+encodeURI(this.diffs[x][1])+'\n'}return b.join('').replace(/%20/g,' ')};

// jQuery 1.2.3 - New Wave Javascript - Copyright (c) 2008 John Resig (jquery.com) - Dual licensed under the MIT (MIT-LICENSE.txt) and GPL (GPL-LICENSE.txt) licenses.
(function(){if(window.jQuery)var u=window.jQuery;var v=window.jQuery=function(a,b){return new v.prototype.init(a,b)};if(window.$)var w=window.$;window.$=v;var x=/^[^<]*(<(.|\s)+>)[^>]*$|^#(\w+)$/;var y=/^.[^:#\[\.]*$/;v.fn=v.prototype={init:function(a,b){a=a||document;if(a.nodeType){this[0]=a;this.length=1;return this}else if(typeof a=="string"){var c=x.exec(a);if(c&&(c[1]||!b)){if(c[1])a=v.clean([c[1]],b);else{var d=document.getElementById(c[3]);if(d)if(d.id!=c[3])return v().find(a);else{this[0]=d;this.length=1;return this}else a=[]}}else return new v(b).find(a)}else if(v.isFunction(a))return new v(document)[v.fn.ready?"ready":"load"](a);return this.setArray(a.constructor==Array&&a||(a.jquery||a.length&&a!=window&&!a.nodeType&&a[0]!=undefined&&a[0].nodeType)&&v.makeArray(a)||[a])},jquery:"1.2.3",size:function(){return this.length},length:0,get:function(a){return a==undefined?v.makeArray(this):this[a]},pushStack:function(a){var b=v(a);b.prevObject=this;return b},setArray:function(a){this.length=0;Array.prototype.push.apply(this,a);return this},each:function(a,b){return v.each(this,a,b)},index:function(a){var b=-1;this.each(function(i){if(this==a)b=i});return b},attr:function(a,b,c){var d=a;if(a.constructor==String)if(b==undefined)return this.length&&v[c||"attr"](this[0],a)||undefined;else{d={};d[a]=b}return this.each(function(i){for(a in d)v.attr(c?this.style:this,a,v.prop(this,d[a],c,i,a))})},css:function(a,b){if((a=='width'||a=='height')&&parseFloat(b)<0)b=undefined;return this.attr(a,b,"curCSS")},text:function(a){if(typeof a!="object"&&a!=null)return this.empty().append((this[0]&&this[0].ownerDocument||document).createTextNode(a));var b="";v.each(a||this,function(){v.each(this.childNodes,function(){if(this.nodeType!=8)b+=this.nodeType!=1?this.nodeValue:v.fn.text([this])})});return b},wrapAll:function(b){if(this[0])v(b,this[0].ownerDocument).clone().insertBefore(this[0]).map(function(){var a=this;while(a.firstChild)a=a.firstChild;return a}).append(this);return this},wrapInner:function(a){return this.each(function(){v(this).contents().wrapAll(a)})},wrap:function(a){return this.each(function(){v(this).wrapAll(a)})},append:function(){return this.domManip(arguments,true,false,function(a){if(this.nodeType==1)this.appendChild(a)})},prepend:function(){return this.domManip(arguments,true,true,function(a){if(this.nodeType==1)this.insertBefore(a,this.firstChild)})},before:function(){return this.domManip(arguments,false,false,function(a){this.parentNode.insertBefore(a,this)})},after:function(){return this.domManip(arguments,false,true,function(a){this.parentNode.insertBefore(a,this.nextSibling)})},end:function(){return this.prevObject||v([])},find:function(b){var c=v.map(this,function(a){return v.find(b,a)});return this.pushStack(/[^+>] [^+>]/.test(b)||b.indexOf("..")>-1?v.unique(c):c)},clone:function(d){var e=this.map(function(){if(v.browser.msie&&!v.isXMLDoc(this)){var a=this.cloneNode(true),container=document.createElement("div");container.appendChild(a);return v.clean([container.innerHTML])[0]}else return this.cloneNode(true)});var f=e.find("*").andSelf().each(function(){if(this[A]!=undefined)this[A]=null});if(d===true)this.find("*").andSelf().each(function(i){if(this.nodeType==3)return;var a=v.data(this,"events");for(var b in a)for(var c in a[b])v.event.add(f[i],b,a[b][c],a[b][c].data)});return e},filter:function(b){return this.pushStack(v.isFunction(b)&&v.grep(this,function(a,i){return b.call(a,i)})||v.multiFilter(b,this))},not:function(a){if(a.constructor==String)if(y.test(a))return this.pushStack(v.multiFilter(a,this,true));else a=v.multiFilter(a,this);var b=a.length&&a[a.length-1]!==undefined&&!a.nodeType;return this.filter(function(){return b?v.inArray(this,a)<0:this!=a})},add:function(a){return!a?this:this.pushStack(v.merge(this.get(),a.constructor==String?v(a).get():a.length!=undefined&&(!a.nodeName||v.nodeName(a,"form"))?a:[a]))},is:function(a){return a?v.multiFilter(a,this).length>0:false},hasClass:function(a){return this.is("."+a)},val:function(b){if(b==undefined){if(this.length){var c=this[0];if(v.nodeName(c,"select")){var d=c.selectedIndex,values=[],options=c.options,one=c.type=="select-one";if(d<0)return null;for(var i=one?d:0,max=one?d+1:options.length;i<max;i++){var e=options[i];if(e.selected){b=v.browser.msie&&!e.attributes.value.specified?e.text:e.value;if(one)return b;values.push(b)}}return values}else return(this[0].value||"").replace(/\r/g,"")}return undefined}return this.each(function(){if(this.nodeType!=1)return;if(b.constructor==Array&&/radio|checkbox/.test(this.type))this.checked=(v.inArray(this.value,b)>=0||v.inArray(this.name,b)>=0);else if(v.nodeName(this,"select")){var a=b.constructor==Array?b:[b];v("option",this).each(function(){this.selected=(v.inArray(this.value,a)>=0||v.inArray(this.text,a)>=0)});if(!a.length)this.selectedIndex=-1}else this.value=b})},html:function(a){return a==undefined?(this.length?this[0].innerHTML:null):this.empty().append(a)},replaceWith:function(a){return this.after(a).remove()},eq:function(i){return this.slice(i,i+1)},slice:function(){return this.pushStack(Array.prototype.slice.apply(this,arguments))},map:function(b){return this.pushStack(v.map(this,function(a,i){return b.call(a,i,a)}))},andSelf:function(){return this.add(this.prevObject)},data:function(a,b){var c=a.split(".");c[1]=c[1]?"."+c[1]:"";if(b==null){var d=this.triggerHandler("getData"+c[1]+"!",[c[0]]);if(d==undefined&&this.length)d=v.data(this[0],a);return d==null&&c[1]?this.data(c[0]):d}else return this.trigger("setData"+c[1]+"!",[c[0],b]).each(function(){v.data(this,a,b)})},removeData:function(a){return this.each(function(){v.removeData(this,a)})},domManip:function(d,e,f,g){var h=this.length>1,elems;return this.each(function(){if(!elems){elems=v.clean(d,this.ownerDocument);if(f)elems.reverse()}var b=this;if(e&&v.nodeName(this,"table")&&v.nodeName(elems[0],"tr"))b=this.getElementsByTagName("tbody")[0]||this.appendChild(this.ownerDocument.createElement("tbody"));var c=v([]);v.each(elems,function(){var a=h?v(this).clone(true)[0]:this;if(v.nodeName(a,"script")){c=c.add(a)}else{if(a.nodeType==1)c=c.add(v("script",a).remove());g.call(b,a)}});c.each(evalScript)})}};v.prototype.init.prototype=v.prototype;function evalScript(i,a){if(a.src)v.ajax({url:a.src,async:false,dataType:"script"});else v.globalEval(a.text||a.textContent||a.innerHTML||"");if(a.parentNode)a.parentNode.removeChild(a)}v.extend=v.fn.extend=function(){var a=arguments[0]||{},i=1,length=arguments.length,deep=false,options;if(a.constructor==Boolean){deep=a;a=arguments[1]||{};i=2}if(typeof a!="object"&&typeof a!="function")a={};if(length==1){a=this;i=0}for(;i<length;i++)if((options=arguments[i])!=null)for(var b in options){if(a===options[b])continue;if(deep&&options[b]&&typeof options[b]=="object"&&a[b]&&!options[b].nodeType)a[b]=v.extend(a[b],options[b]);else if(options[b]!=undefined)a[b]=options[b]}return a};var A="jQuery"+(new Date()).getTime(),uuid=0,windowData={};var B=/z-?index|font-?weight|opacity|zoom|line-?height/i;v.extend({noConflict:function(a){window.$=w;if(a)window.jQuery=u;return v},isFunction:function(a){return!!a&&typeof a!="string"&&!a.nodeName&&a.constructor!=Array&&/function/i.test(a+"")},isXMLDoc:function(a){return a.documentElement&&!a.body||a.tagName&&a.ownerDocument&&!a.ownerDocument.body},globalEval:function(a){a=v.trim(a);if(a){var b=document.getElementsByTagName("head")[0]||document.documentElement,script=document.createElement("script");script.type="text/javascript";if(v.browser.msie)script.text=a;else script.appendChild(document.createTextNode(a));b.appendChild(script);b.removeChild(script)}},nodeName:function(a,b){return a.nodeName&&a.nodeName.toUpperCase()==b.toUpperCase()},cache:{},data:function(a,b,c){a=a==window?windowData:a;var d=a[A];if(!d)d=a[A]=++uuid;if(b&&!v.cache[d])v.cache[d]={};if(c!=undefined)v.cache[d][b]=c;return b?v.cache[d][b]:d},removeData:function(a,b){a=a==window?windowData:a;var c=a[A];if(b){if(v.cache[c]){delete v.cache[c][b];b="";for(b in v.cache[c])break;if(!b)v.removeData(a)}}else{try{delete a[A]}catch(e){if(a.removeAttribute)a.removeAttribute(A)}delete v.cache[c]}},each:function(a,b,c){if(c){if(a.length==undefined){for(var d in a)if(b.apply(a[d],c)===false)break}else for(var i=0,length=a.length;i<length;i++)if(b.apply(a[i],c)===false)break}else{if(a.length==undefined){for(var d in a)if(b.call(a[d],d,a[d])===false)break}else for(var i=0,length=a.length,value=a[0];i<length&&b.call(value,i,value)!==false;value=a[++i]){}}return a},prop:function(a,b,c,i,d){if(v.isFunction(b))b=b.call(a,i);return b&&b.constructor==Number&&c=="curCSS"&&!B.test(d)?b+"px":b},className:{add:function(b,c){v.each((c||"").split(/\s+/),function(i,a){if(b.nodeType==1&&!v.className.has(b.className,a))b.className+=(b.className?" ":"")+a})},remove:function(b,c){if(b.nodeType==1)b.className=c!=undefined?v.grep(b.className.split(/\s+/),function(a){return!v.className.has(c,a)}).join(" "):""},has:function(a,b){return v.inArray(b,(a.className||a).toString().split(/\s+/))>-1}},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(var e in b)a.style[e]=d[e]},css:function(b,c,d){if(c=="width"||c=="height"){var e,props={position:"absolute",visibility:"hidden",display:"block"},which=c=="width"?["Left","Right"]:["Top","Bottom"];function getWH(){e=c=="width"?b.offsetWidth:b.offsetHeight;var a=0,border=0;v.each(which,function(){a+=parseFloat(v.curCSS(b,"padding"+this,true))||0;border+=parseFloat(v.curCSS(b,"border"+this+"Width",true))||0});e-=Math.round(a+border)}if(v(b).is(":visible"))getWH();else v.swap(b,props,getWH);return Math.max(0,e)}return v.curCSS(b,c,d)},curCSS:function(c,d,e){var f;function color(a){if(!v.browser.safari)return false;var b=document.defaultView.getComputedStyle(a,null);return!b||b.getPropertyValue("color")==""}if(d=="opacity"&&v.browser.msie){f=v.attr(c.style,"opacity");return f==""?"1":f}if(v.browser.opera&&d=="display"){var g=c.style.outline;c.style.outline="0 solid black";c.style.outline=g}if(d.match(/float/i))d=D;if(!e&&c.style&&c.style[d])f=c.style[d];else if(document.defaultView&&document.defaultView.getComputedStyle){if(d.match(/float/i))d="float";d=d.replace(/([A-Z])/g,"-$1").toLowerCase();var h=document.defaultView.getComputedStyle(c,null);if(h&&!color(c))f=h.getPropertyValue(d);else{var j=[],stack=[];for(var a=c;a&&color(a);a=a.parentNode)stack.unshift(a);for(var i=0;i<stack.length;i++)if(color(stack[i])){j[i]=stack[i].style.display;stack[i].style.display="block"}f=d=="display"&&j[stack.length-1]!=null?"none":(h&&h.getPropertyValue(d))||"";for(var i=0;i<j.length;i++)if(j[i]!=null)stack[i].style.display=j[i]}if(d=="opacity"&&f=="")f="1"}else if(c.currentStyle){var k=d.replace(/\-(\w)/g,function(a,b){return b.toUpperCase()});f=c.currentStyle[d]||c.currentStyle[k];if(!/^\d+(px)?$/i.test(f)&&/^\d/.test(f)){var l=c.style.left,runtimeStyle=c.runtimeStyle.left;c.runtimeStyle.left=c.currentStyle.left;c.style.left=f||0;f=c.style.pixelLeft+"px";c.style.left=l;c.runtimeStyle.left=runtimeStyle}}return f},clean:function(h,k){var l=[];k=k||document;if(typeof k.createElement=='undefined')k=k.ownerDocument||k[0]&&k[0].ownerDocument||document;v.each(h,function(i,d){if(!d)return;if(d.constructor==Number)d=d.toString();if(typeof d=="string"){d=d.replace(/(<(\w+)[^>]*?)\/>/g,function(a,b,c){return c.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i)?a:b+"></"+c+">"});var e=v.trim(d).toLowerCase(),div=k.createElement("div");var f=!e.indexOf("<opt")&&[1,"<select multiple='multiple'>","</select>"]||!e.indexOf("<leg")&&[1,"<fieldset>","</fieldset>"]||e.match(/^<(thead|tbody|tfoot|colg|cap)/)&&[1,"<table>","</table>"]||!e.indexOf("<tr")&&[2,"<table><tbody>","</tbody></table>"]||(!e.indexOf("<td")||!e.indexOf("<th"))&&[3,"<table><tbody><tr>","</tr></tbody></table>"]||!e.indexOf("<col")&&[2,"<table><tbody></tbody><colgroup>","</colgroup></table>"]||v.browser.msie&&[1,"div<div>","</div>"]||[0,"",""];div.innerHTML=f[1]+d+f[2];while(f[0]--)div=div.lastChild;if(v.browser.msie){var g=!e.indexOf("<table")&&e.indexOf("<tbody")<0?div.firstChild&&div.firstChild.childNodes:f[1]=="<table>"&&e.indexOf("<tbody")<0?div.childNodes:[];for(var j=g.length-1;j>=0;--j)if(v.nodeName(g[j],"tbody")&&!g[j].childNodes.length)g[j].parentNode.removeChild(g[j]);if(/^\s/.test(d))div.insertBefore(k.createTextNode(d.match(/^\s*/)[0]),div.firstChild)}d=v.makeArray(div.childNodes)}if(d.length===0&&(!v.nodeName(d,"form")&&!v.nodeName(d,"select")))return;if(d[0]==undefined||v.nodeName(d,"form")||d.options)l.push(d);else l=v.merge(l,d)});return l},attr:function(c,d,e){if(!c||c.nodeType==3||c.nodeType==8)return undefined;var f=v.isXMLDoc(c)?{}:v.props;if(d=="selected"&&v.browser.safari)c.parentNode.selectedIndex;if(f[d]){if(e!=undefined)c[f[d]]=e;return c[f[d]]}else if(v.browser.msie&&d=="style")return v.attr(c.style,"cssText",e);else if(e==undefined&&v.browser.msie&&v.nodeName(c,"form")&&(d=="action"||d=="method"))return c.getAttributeNode(d).nodeValue;else if(c.tagName){if(e!=undefined){if(d=="type"&&v.nodeName(c,"input")&&c.parentNode)throw"type property can't be changed";c.setAttribute(d,""+e)}if(v.browser.msie&&/href|src/.test(d)&&!v.isXMLDoc(c))return c.getAttribute(d,2);return c.getAttribute(d)}else{if(d=="opacity"&&v.browser.msie){if(e!=undefined){c.zoom=1;c.filter=(c.filter||"").replace(/alpha\([^)]*\)/,"")+(parseFloat(e).toString()=="NaN"?"":"alpha(opacity="+e*100+")")}return c.filter&&c.filter.indexOf("opacity=")>=0?(parseFloat(c.filter.match(/opacity=([^)]*)/)[1])/100).toString():""}d=d.replace(/-([a-z])/ig,function(a,b){return b.toUpperCase()});if(e!=undefined)c[d]=e;return c[d]}},trim:function(a){return(a||"").replace(/^\s+|\s+$/g,"")},makeArray:function(a){var b=[];if(typeof a!="array")for(var i=0,length=a.length;i<length;i++)b.push(a[i]);else b=a.slice(0);return b},inArray:function(a,b){for(var i=0,length=b.length;i<length;i++)if(b[i]==a)return i;return-1},merge:function(a,b){if(v.browser.msie){for(var i=0;b[i];i++)if(b[i].nodeType!=8)a.push(b[i])}else for(var i=0;b[i];i++)a.push(b[i]);return a},unique:function(a){var b=[],done={};try{for(var i=0,length=a.length;i<length;i++){var c=v.data(a[i]);if(!done[c]){done[c]=true;b.push(a[i])}}}catch(e){b=a}return b},grep:function(a,b,c){var d=[];for(var i=0,length=a.length;i<length;i++)if(!c&&b(a[i],i)||c&&!b(a[i],i))d.push(a[i]);return d},map:function(a,b){var c=[];for(var i=0,length=a.length;i<length;i++){var d=b(a[i],i);if(d!==null&&d!=undefined){if(d.constructor!=Array)d=[d];c=c.concat(d)}}return c}});var C=navigator.userAgent.toLowerCase();v.browser={version:(C.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/)||[])[1],safari:/webkit/.test(C),opera:/opera/.test(C),msie:/msie/.test(C)&&!/opera/.test(C),mozilla:/mozilla/.test(C)&&!/(compatible|webkit)/.test(C)};var D=v.browser.msie?"styleFloat":"cssFloat";v.extend({boxModel:!v.browser.msie||document.compatMode=="CSS1Compat",props:{"for":"htmlFor","class":"className","float":D,cssFloat:D,styleFloat:D,innerHTML:"innerHTML",className:"className",value:"value",disabled:"disabled",checked:"checked",readonly:"readOnly",selected:"selected",maxlength:"maxLength",selectedIndex:"selectedIndex",defaultValue:"defaultValue",tagName:"tagName",nodeName:"nodeName"}});v.each({parent:function(a){return a.parentNode},parents:function(a){return v.dir(a,"parentNode")},next:function(a){return v.nth(a,2,"nextSibling")},prev:function(a){return v.nth(a,2,"previousSibling")},nextAll:function(a){return v.dir(a,"nextSibling")},prevAll:function(a){return v.dir(a,"previousSibling")},siblings:function(a){return v.sibling(a.parentNode.firstChild,a)},children:function(a){return v.sibling(a.firstChild)},contents:function(a){return v.nodeName(a,"iframe")?a.contentDocument||a.contentWindow.document:v.makeArray(a.childNodes)}},function(c,d){v.fn[c]=function(a){var b=v.map(this,d);if(a&&typeof a=="string")b=v.multiFilter(a,b);return this.pushStack(v.unique(b))}});v.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(b,c){v.fn[b]=function(){var a=arguments;return this.each(function(){for(var i=0,length=a.length;i<length;i++)v(a[i])[c](this)})}});v.each({removeAttr:function(a){v.attr(this,a,"");if(this.nodeType==1)this.removeAttribute(a)},addClass:function(a){v.className.add(this,a)},removeClass:function(a){v.className.remove(this,a)},toggleClass:function(a){v.className[v.className.has(this,a)?"remove":"add"](this,a)},remove:function(a){if(!a||v.filter(a,[this]).r.length){v("*",this).add(this).each(function(){v.event.remove(this);v.removeData(this)});if(this.parentNode)this.parentNode.removeChild(this)}},empty:function(){v(">*",this).remove();while(this.firstChild)this.removeChild(this.firstChild)}},function(a,b){v.fn[a]=function(){return this.each(b,arguments)}});v.each(["Height","Width"],function(i,b){var c=b.toLowerCase();v.fn[c]=function(a){return this[0]==window?v.browser.opera&&document.body["client"+b]||v.browser.safari&&window["inner"+b]||document.compatMode=="CSS1Compat"&&document.documentElement["client"+b]||document.body["client"+b]:this[0]==document?Math.max(Math.max(document.body["scroll"+b],document.documentElement["scroll"+b]),Math.max(document.body["offset"+b],document.documentElement["offset"+b])):a==undefined?(this.length?v.css(this[0],c):null):this.css(c,a.constructor==String?a:a+"px")}});var E=v.browser.safari&&parseInt(v.browser.version)<417?"(?:[\\w*_-]|\\\\.)":"(?:[\\w\u0128-\uFFFF*_-]|\\\\.)",quickChild=new RegExp("^>\\s*("+E+"+)"),quickID=new RegExp("^("+E+"+)(#)("+E+"+)"),quickClass=new RegExp("^([#.]?)("+E+"*)");v.extend({expr:{"":function(a,i,m){return m[2]=="*"||v.nodeName(a,m[2])},"#":function(a,i,m){return a.getAttribute("id")==m[2]},":":{lt:function(a,i,m){return i<m[3]-0},gt:function(a,i,m){return i>m[3]-0},nth:function(a,i,m){return m[3]-0==i},eq:function(a,i,m){return m[3]-0==i},first:function(a,i){return i==0},last:function(a,i,m,r){return i==r.length-1},even:function(a,i){return i%2==0},odd:function(a,i){return i%2},"first-child":function(a){return a.parentNode.getElementsByTagName("*")[0]==a},"last-child":function(a){return v.nth(a.parentNode.lastChild,1,"previousSibling")==a},"only-child":function(a){return!v.nth(a.parentNode.lastChild,2,"previousSibling")},parent:function(a){return a.firstChild},empty:function(a){return!a.firstChild},contains:function(a,i,m){return(a.textContent||a.innerText||v(a).text()||"").indexOf(m[3])>=0},visible:function(a){return"hidden"!=a.type&&v.css(a,"display")!="none"&&v.css(a,"visibility")!="hidden"},hidden:function(a){return"hidden"==a.type||v.css(a,"display")=="none"||v.css(a,"visibility")=="hidden"},enabled:function(a){return!a.disabled},disabled:function(a){return a.disabled},checked:function(a){return a.checked},selected:function(a){return a.selected||v.attr(a,"selected")},text:function(a){return"text"==a.type},radio:function(a){return"radio"==a.type},checkbox:function(a){return"checkbox"==a.type},file:function(a){return"file"==a.type},password:function(a){return"password"==a.type},submit:function(a){return"submit"==a.type},image:function(a){return"image"==a.type},reset:function(a){return"reset"==a.type},button:function(a){return"button"==a.type||v.nodeName(a,"button")},input:function(a){return/input|select|textarea|button/i.test(a.nodeName)},has:function(a,i,m){return v.find(m[3],a).length},header:function(a){return/h\d/i.test(a.nodeName)},animated:function(a){return v.grep(v.timers,function(b){return a==b.elem}).length}}},parse:[/^(\[) *@?([\w-]+) *([!*$^~=]*) *('?"?)(.*?)\4 *\]/,/^(:)([\w-]+)\("?'?(.*?(\(.*?\))?[^(]*?)"?'?\)/,new RegExp("^([:.#]*)("+E+"+)")],multiFilter:function(a,b,c){var d,cur=[];while(a&&a!=d){d=a;var f=v.filter(a,b,c);a=f.t.replace(/^\s*,\s*/,"");cur=c?b=f.r:v.merge(cur,f.r)}return cur},find:function(t,a){if(typeof t!="string")return[t];if(a&&a.nodeType!=1&&a.nodeType!=9)return[];a=a||document;var b=[a],done=[],last,nodeName;while(t&&last!=t){var r=[];last=t;t=v.trim(t);var d=false;var e=quickChild;var m=e.exec(t);if(m){nodeName=m[1].toUpperCase();for(var i=0;b[i];i++)for(var c=b[i].firstChild;c;c=c.nextSibling)if(c.nodeType==1&&(nodeName=="*"||c.nodeName.toUpperCase()==nodeName))r.push(c);b=r;t=t.replace(e,"");if(t.indexOf(" ")==0)continue;d=true}else{e=/^([>+~])\s*(\w*)/i;if((m=e.exec(t))!=null){r=[];var f={};nodeName=m[2].toUpperCase();m=m[1];for(var j=0,rl=b.length;j<rl;j++){var n=m=="~"||m=="+"?b[j].nextSibling:b[j].firstChild;for(;n;n=n.nextSibling)if(n.nodeType==1){var g=v.data(n);if(m=="~"&&f[g])break;if(!nodeName||n.nodeName.toUpperCase()==nodeName){if(m=="~")f[g]=true;r.push(n)}if(m=="+")break}}b=r;t=v.trim(t.replace(e,""));d=true}}if(t&&!d){if(!t.indexOf(",")){if(a==b[0])b.shift();done=v.merge(done,b);r=b=[a];t=" "+t.substr(1,t.length)}else{var h=quickID;var m=h.exec(t);if(m){m=[0,m[2],m[3],m[1]]}else{h=quickClass;m=h.exec(t)}m[2]=m[2].replace(/\\/g,"");var k=b[b.length-1];if(m[1]=="#"&&k&&k.getElementById&&!v.isXMLDoc(k)){var l=k.getElementById(m[2]);if((v.browser.msie||v.browser.opera)&&l&&typeof l.id=="string"&&l.id!=m[2])l=v('[@id="'+m[2]+'"]',k)[0];b=r=l&&(!m[3]||v.nodeName(l,m[3]))?[l]:[]}else{for(var i=0;b[i];i++){var o=m[1]=="#"&&m[3]?m[3]:m[1]!=""||m[0]==""?"*":m[2];if(o=="*"&&b[i].nodeName.toLowerCase()=="object")o="param";r=v.merge(r,b[i].getElementsByTagName(o))}if(m[1]==".")r=v.classFilter(r,m[2]);if(m[1]=="#"){var p=[];for(var i=0;r[i];i++)if(r[i].getAttribute("id")==m[2]){p=[r[i]];break}r=p}b=r}t=t.replace(h,"")}}if(t){var q=v.filter(t,r);b=r=q.r;t=v.trim(q.t)}}if(t)b=[];if(b&&a==b[0])b.shift();done=v.merge(done,b);return done},classFilter:function(r,m,a){m=" "+m+" ";var b=[];for(var i=0;r[i];i++){var c=(" "+r[i].className+" ").indexOf(m)>=0;if(!a&&c||a&&!c)b.push(r[i])}return b},filter:function(t,r,b){var d;while(t&&t!=d){d=t;var p=v.parse,m;for(var i=0;p[i];i++){m=p[i].exec(t);if(m){t=t.substring(m[0].length);m[2]=m[2].replace(/\\/g,"");break}}if(!m)break;if(m[1]==":"&&m[2]=="not")r=y.test(m[3])?v.filter(m[3],r,true).r:v(r).not(m[3]);else if(m[1]==".")r=v.classFilter(r,m[2],b);else if(m[1]=="["){var e=[],type=m[3];for(var i=0,rl=r.length;i<rl;i++){var a=r[i],z=a[v.props[m[2]]||m[2]];if(z==null||/href|src|selected/.test(m[2]))z=v.attr(a,m[2])||'';if((type==""&&!!z||type=="="&&z==m[5]||type=="!="&&z!=m[5]||type=="^="&&z&&!z.indexOf(m[5])||type=="$="&&z.substr(z.length-m[5].length)==m[5]||(type=="*="||type=="~=")&&z.indexOf(m[5])>=0)^b)e.push(a)}r=e}else if(m[1]==":"&&m[2]=="nth-child"){var f={},e=[],test=/(-?)(\d*)n((?:\+|-)?\d*)/.exec(m[3]=="even"&&"2n"||m[3]=="odd"&&"2n+1"||!/\D/.test(m[3])&&"0n+"+m[3]||m[3]),first=(test[1]+(test[2]||1))-0,d=test[3]-0;for(var i=0,rl=r.length;i<rl;i++){var g=r[i],parentNode=g.parentNode,id=v.data(parentNode);if(!f[id]){var c=1;for(var n=parentNode.firstChild;n;n=n.nextSibling)if(n.nodeType==1)n.nodeIndex=c++;f[id]=true}var h=false;if(first==0){if(g.nodeIndex==d)h=true}else if((g.nodeIndex-d)%first==0&&(g.nodeIndex-d)/first>=0)h=true;if(h^b)e.push(g)}r=e}else{var j=v.expr[m[1]];if(typeof j=="object")j=j[m[2]];if(typeof j=="string")j=eval("false||function(a,i){return "+j+";}");r=v.grep(r,function(a,i){return j(a,i,m,r)},b)}}return{r:r,t:t}},dir:function(a,b){var c=[];var d=a[b];while(d&&d!=document){if(d.nodeType==1)c.push(d);d=d[b]}return c},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(n,a){var r=[];for(;n;n=n.nextSibling){if(n.nodeType==1&&(!a||n!=a))r.push(n)}return r}});v.event={add:function(e,f,g,h){if(e.nodeType==3||e.nodeType==8)return;if(v.browser.msie&&e.setInterval!=undefined)e=window;if(!g.guid)g.guid=this.guid++;if(h!=undefined){var i=g;g=function(){return i.apply(this,arguments)};g.data=h;g.guid=i.guid}var j=v.data(e,"events")||v.data(e,"events",{}),handle=v.data(e,"handle")||v.data(e,"handle",function(){var a;if(typeof v=="undefined"||v.event.triggered)return a;a=v.event.handle.apply(arguments.callee.elem,arguments);return a});handle.elem=e;v.each(f.split(/\s+/),function(a,b){var c=b.split(".");b=c[0];g.type=c[1];var d=j[b];if(!d){d=j[b]={};if(!v.event.special[b]||v.event.special[b].setup.call(e)===false){if(e.addEventListener)e.addEventListener(b,handle,false);else if(e.attachEvent)e.attachEvent("on"+b,handle)}}d[g.guid]=g;v.event.global[b]=true});e=null},guid:1,global:{},remove:function(d,e,f){if(d.nodeType==3||d.nodeType==8)return;var g=v.data(d,"events"),ret,index;if(g){if(e==undefined||(typeof e=="string"&&e.charAt(0)=="."))for(var h in g)this.remove(d,h+(e||""));else{if(e.type){f=e.handler;e=e.type}v.each(e.split(/\s+/),function(a,b){var c=b.split(".");b=c[0];if(g[b]){if(f)delete g[b][f.guid];else for(f in g[b])if(!c[1]||g[b][f].type==c[1])delete g[b][f];for(ret in g[b])break;if(!ret){if(!v.event.special[b]||v.event.special[b].teardown.call(d)===false){if(d.removeEventListener)d.removeEventListener(b,v.data(d,"handle"),false);else if(d.detachEvent)d.detachEvent("on"+b,v.data(d,"handle"))}ret=null;delete g[b]}}})}for(ret in g)break;if(!ret){var i=v.data(d,"handle");if(i)i.elem=null;v.removeData(d,"events");v.removeData(d,"handle")}}},trigger:function(a,b,c,d,f){b=v.makeArray(b||[]);if(a.indexOf("!")>=0){a=a.slice(0,-1);var g=true}if(!c){if(this.global[a])v("*").add([window,document]).trigger(a,b)}else{if(c.nodeType==3||c.nodeType==8)return undefined;var h,ret,fn=v.isFunction(c[a]||null),event=!b[0]||!b[0].preventDefault;if(event)b.unshift(this.fix({type:a,target:c}));b[0].type=a;if(g)b[0].exclusive=true;if(v.isFunction(v.data(c,"handle")))h=v.data(c,"handle").apply(c,b);if(!fn&&c["on"+a]&&c["on"+a].apply(c,b)===false)h=false;if(event)b.shift();if(f&&v.isFunction(f)){ret=f.apply(c,h==null?b:b.concat(h));if(ret!==undefined)h=ret}if(fn&&d!==false&&h!==false&&!(v.nodeName(c,'a')&&a=="click")){this.triggered=true;try{c[a]()}catch(e){}}this.triggered=false}return h},handle:function(a){var b;a=v.event.fix(a||window.event||{});var c=a.type.split(".");a.type=c[0];var d=v.data(this,"events")&&v.data(this,"events")[a.type],args=Array.prototype.slice.call(arguments,1);args.unshift(a);for(var j in d){var e=d[j];args[0].handler=e;args[0].data=e.data;if(!c[1]&&!a.exclusive||e.type==c[1]){var f=e.apply(this,args);if(b!==false)b=f;if(f===false){a.preventDefault();a.stopPropagation()}}}if(v.browser.msie)a.target=a.preventDefault=a.stopPropagation=a.handler=a.data=null;return b},fix:function(a){var b=a;a=v.extend({},b);a.preventDefault=function(){if(b.preventDefault)b.preventDefault();b.returnValue=false};a.stopPropagation=function(){if(b.stopPropagation)b.stopPropagation();b.cancelBubble=true};if(!a.target)a.target=a.srcElement||document;if(a.target.nodeType==3)a.target=b.target.parentNode;if(!a.relatedTarget&&a.fromElement)a.relatedTarget=a.fromElement==a.target?a.toElement:a.fromElement;if(a.pageX==null&&a.clientX!=null){var c=document.documentElement,body=document.body;a.pageX=a.clientX+(c&&c.scrollLeft||body&&body.scrollLeft||0)-(c.clientLeft||0);a.pageY=a.clientY+(c&&c.scrollTop||body&&body.scrollTop||0)-(c.clientTop||0)}if(!a.which&&((a.charCode||a.charCode===0)?a.charCode:a.keyCode))a.which=a.charCode||a.keyCode;if(!a.metaKey&&a.ctrlKey)a.metaKey=a.ctrlKey;if(!a.which&&a.button)a.which=(a.button&1?1:(a.button&2?3:(a.button&4?2:0)));return a},special:{ready:{setup:function(){bindReady();return},teardown:function(){return}},mouseenter:{setup:function(){if(v.browser.msie)return false;v(this).bind("mouseover",v.event.special.mouseenter.handler);return true},teardown:function(){if(v.browser.msie)return false;v(this).unbind("mouseover",v.event.special.mouseenter.handler);return true},handler:function(a){if(G(a,this))return true;arguments[0].type="mouseenter";return v.event.handle.apply(this,arguments)}},mouseleave:{setup:function(){if(v.browser.msie)return false;v(this).bind("mouseout",v.event.special.mouseleave.handler);return true},teardown:function(){if(v.browser.msie)return false;v(this).unbind("mouseout",v.event.special.mouseleave.handler);return true},handler:function(a){if(G(a,this))return true;arguments[0].type="mouseleave";return v.event.handle.apply(this,arguments)}}}};v.fn.extend({bind:function(a,b,c){return a=="unload"?this.one(a,b,c):this.each(function(){v.event.add(this,a,c||b,c&&b)})},one:function(b,c,d){return this.each(function(){v.event.add(this,b,function(a){v(this).unbind(a);return(d||c).apply(this,arguments)},d&&c)})},unbind:function(a,b){return this.each(function(){v.event.remove(this,a,b)})},trigger:function(a,b,c){return this.each(function(){v.event.trigger(a,b,this,true,c)})},triggerHandler:function(a,b,c){if(this[0])return v.event.trigger(a,b,this[0],false,c);return undefined},toggle:function(){var b=arguments;return this.click(function(a){this.lastToggle=0==this.lastToggle?1:0;a.preventDefault();return b[this.lastToggle].apply(this,arguments)||false})},hover:function(a,b){return this.bind('mouseenter',a).bind('mouseleave',b)},ready:function(a){bindReady();if(v.isReady)a.call(document,v);else v.readyList.push(function(){return a.call(this,v)});return this}});v.extend({isReady:false,readyList:[],ready:function(){if(!v.isReady){v.isReady=true;if(v.readyList){v.each(v.readyList,function(){this.apply(document)});v.readyList=null}v(document).triggerHandler("ready")}}});var F=false;function bindReady(){if(F)return;F=true;if(document.addEventListener&&!v.browser.opera)document.addEventListener("DOMContentLoaded",v.ready,false);if(v.browser.msie&&window==top)(function(){if(v.isReady)return;try{document.documentElement.doScroll("left")}catch(error){setTimeout(arguments.callee,0);return}v.ready()})();if(v.browser.opera)document.addEventListener("DOMContentLoaded",function(){if(v.isReady)return;for(var i=0;i<document.styleSheets.length;i++)if(document.styleSheets[i].disabled){setTimeout(arguments.callee,0);return}v.ready()},false);if(v.browser.safari){var a;(function(){if(v.isReady)return;if(document.readyState!="loaded"&&document.readyState!="complete"){setTimeout(arguments.callee,0);return}if(a===undefined)a=v("style, link[rel=stylesheet]").length;if(document.styleSheets.length!=a){setTimeout(arguments.callee,0);return}v.ready()})()}v.event.add(window,"load",v.ready)}v.each(("blur,focus,load,resize,scroll,unload,click,dblclick,"+"mousedown,mouseup,mousemove,mouseover,mouseout,change,select,"+"submit,keydown,keypress,keyup,error").split(","),function(i,b){v.fn[b]=function(a){return a?this.bind(b,a):this.trigger(b)}});var G=function(a,b){var c=a.relatedTarget;while(c&&c!=b)try{c=c.parentNode}catch(error){c=b}return c==b};v(window).bind("unload",function(){v("*").add(document).unbind()});v.fn.extend({load:function(c,d,e){if(v.isFunction(c))return this.bind("load",c);var f=c.indexOf(" ");if(f>=0){var g=c.slice(f,c.length);c=c.slice(0,f)}e=e||function(){};var h="GET";if(d)if(v.isFunction(d)){e=d;d=null}else{d=v.param(d);h="POST"}var i=this;v.ajax({url:c,type:h,dataType:"html",data:d,complete:function(a,b){if(b=="success"||b=="notmodified")i.html(g?v("<div/>").append(a.responseText.replace(/<script(.|\s)*?\/script>/g,"")).find(g):a.responseText);i.each(e,[a.responseText,b,a])}});return this},serialize:function(){return v.param(this.serializeArray())},serializeArray:function(){return this.map(function(){return v.nodeName(this,"form")?v.makeArray(this.elements):this}).filter(function(){return this.name&&!this.disabled&&(this.checked||/select|textarea/i.test(this.nodeName)||/text|hidden|password/i.test(this.type))}).map(function(i,b){var c=v(this).val();return c==null?null:c.constructor==Array?v.map(c,function(a,i){return{name:b.name,value:a}}):{name:b.name,value:c}}).get()}});v.each("ajaxStart,ajaxStop,ajaxComplete,ajaxError,ajaxSuccess,ajaxSend".split(","),function(i,o){v.fn[o]=function(f){return this.bind(o,f)}});var H=(new Date).getTime();v.extend({get:function(a,b,c,d){if(v.isFunction(b)){c=b;b=null}return v.ajax({type:"GET",url:a,data:b,success:c,dataType:d})},getScript:function(a,b){return v.get(a,null,b,"script")},getJSON:function(a,b,c){return v.get(a,b,c,"json")},post:function(a,b,c,d){if(v.isFunction(b)){c=b;b={}}return v.ajax({type:"POST",url:a,data:b,success:c,dataType:d})},ajaxSetup:function(a){v.extend(v.ajaxSettings,a)},ajaxSettings:{global:true,type:"GET",timeout:0,contentType:"application/x-www-form-urlencoded",processData:true,async:true,data:null,username:null,password:null,accepts:{xml:"application/xml, text/xml",html:"text/html",script:"text/javascript, application/javascript",json:"application/json, text/javascript",text:"text/plain",_default:"*/*"}},lastModified:{},ajax:function(s){var c,jsre=/=\?(&|$)/g,status,data;s=v.extend(true,s,v.extend(true,{},v.ajaxSettings,s));if(s.data&&s.processData&&typeof s.data!="string")s.data=v.param(s.data);if(s.dataType=="jsonp"){if(s.type.toLowerCase()=="get"){if(!s.url.match(jsre))s.url+=(s.url.match(/\?/)?"&":"?")+(s.jsonp||"callback")+"=?"}else if(!s.data||!s.data.match(jsre))s.data=(s.data?s.data+"&":"")+(s.jsonp||"callback")+"=?";s.dataType="json"}if(s.dataType=="json"&&(s.data&&s.data.match(jsre)||s.url.match(jsre))){c="jsonp"+H++;if(s.data)s.data=(s.data+"").replace(jsre,"="+c+"$1");s.url=s.url.replace(jsre,"="+c+"$1");s.dataType="script";window[c]=function(a){data=a;success();complete();window[c]=undefined;try{delete window[c]}catch(e){}if(g)g.removeChild(h)}}if(s.dataType=="script"&&s.cache==null)s.cache=false;if(s.cache===false&&s.type.toLowerCase()=="get"){var d=(new Date()).getTime();var f=s.url.replace(/(\?|&)_=.*?(&|$)/,"$1_="+d+"$2");s.url=f+((f==s.url)?(s.url.match(/\?/)?"&":"?")+"_="+d:"")}if(s.data&&s.type.toLowerCase()=="get"){s.url+=(s.url.match(/\?/)?"&":"?")+s.data;s.data=null}if(s.global&&!v.active++)v.event.trigger("ajaxStart");if((!s.url.indexOf("http")||!s.url.indexOf("//"))&&s.dataType=="script"&&s.type.toLowerCase()=="get"){var g=document.getElementsByTagName("head")[0];var h=document.createElement("script");h.src=s.url;if(s.scriptCharset)h.charset=s.scriptCharset;if(!c){var i=false;h.onload=h.onreadystatechange=function(){if(!i&&(!this.readyState||this.readyState=="loaded"||this.readyState=="complete")){i=true;success();complete();g.removeChild(h)}}}g.appendChild(h);return undefined}var j=false;var k=window.ActiveXObject?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();k.open(s.type,s.url,s.async,s.username,s.password);try{if(s.data)k.setRequestHeader("Content-Type",s.contentType);if(s.ifModified)k.setRequestHeader("If-Modified-Since",v.lastModified[s.url]||"Thu, 01 Jan 1970 00:00:00 GMT");k.setRequestHeader("X-Requested-With","XMLHttpRequest");k.setRequestHeader("Accept",s.dataType&&s.accepts[s.dataType]?s.accepts[s.dataType]+", */*":s.accepts._default)}catch(e){}if(s.beforeSend)s.beforeSend(k);if(s.global)v.event.trigger("ajaxSend",[k,s]);var l=function(a){if(!j&&k&&(k.readyState==4||a=="timeout")){j=true;if(m){clearInterval(m);m=null}status=a=="timeout"&&"timeout"||!v.httpSuccess(k)&&"error"||s.ifModified&&v.httpNotModified(k,s.url)&&"notmodified"||"success";if(status=="success"){try{data=v.httpData(k,s.dataType)}catch(e){status="parsererror"}}if(status=="success"){var b;try{b=k.getResponseHeader("Last-Modified")}catch(e){}if(s.ifModified&&b)v.lastModified[s.url]=b;if(!c)success()}else v.handleError(s,k,status);complete();if(s.async)k=null}};if(s.async){var m=setInterval(l,13);if(s.timeout>0)setTimeout(function(){if(k){k.abort();if(!j)l("timeout")}},s.timeout)}try{k.send(s.data)}catch(e){v.handleError(s,k,null,e)}if(!s.async)l();function success(){if(s.success)s.success(data,status);if(s.global)v.event.trigger("ajaxSuccess",[k,s])}function complete(){if(s.complete)s.complete(k,status);if(s.global)v.event.trigger("ajaxComplete",[k,s]);if(s.global&&!--v.active)v.event.trigger("ajaxStop")}return k},handleError:function(s,a,b,e){if(s.error)s.error(a,b,e);if(s.global)v.event.trigger("ajaxError",[a,s,e])},active:0,httpSuccess:function(r){try{return!r.status&&location.protocol=="file:"||(r.status>=200&&r.status<300)||r.status==304||r.status==1223||v.browser.safari&&r.status==undefined}catch(e){}return false},httpNotModified:function(a,b){try{var c=a.getResponseHeader("Last-Modified");return a.status==304||c==v.lastModified[b]||v.browser.safari&&a.status==undefined}catch(e){}return false},httpData:function(r,a){var b=r.getResponseHeader("content-type");var c=a=="xml"||!a&&b&&b.indexOf("xml")>=0;var d=c?r.responseXML:r.responseText;if(c&&d.documentElement.tagName=="parsererror")throw"parsererror";if(a=="script")v.globalEval(d);if(a=="json")d=eval("("+d+")");return d},param:function(a){var s=[];if(a.constructor==Array||a.jquery)v.each(a,function(){s.push(encodeURIComponent(this.name)+"="+encodeURIComponent(this.value))});else for(var j in a)if(a[j]&&a[j].constructor==Array)v.each(a[j],function(){s.push(encodeURIComponent(j)+"="+encodeURIComponent(this))});else s.push(encodeURIComponent(j)+"="+encodeURIComponent(a[j]));return s.join("&").replace(/%20/g,"+")}});v.fn.extend({show:function(b,c){return b?this.animate({height:"show",width:"show",opacity:"show"},b,c):this.filter(":hidden").each(function(){this.style.display=this.oldblock||"";if(v.css(this,"display")=="none"){var a=v("<"+this.tagName+" />").appendTo("body");this.style.display=a.css("display");if(this.style.display=="none")this.style.display="block";a.remove()}}).end()},hide:function(a,b){return a?this.animate({height:"hide",width:"hide",opacity:"hide"},a,b):this.filter(":visible").each(function(){this.oldblock=this.oldblock||v.css(this,"display");this.style.display="none"}).end()},_toggle:v.fn.toggle,toggle:function(a,b){return v.isFunction(a)&&v.isFunction(b)?this._toggle(a,b):a?this.animate({height:"toggle",width:"toggle",opacity:"toggle"},a,b):this.each(function(){v(this)[v(this).is(":hidden")?"show":"hide"]()})},slideDown:function(a,b){return this.animate({height:"show"},a,b)},slideUp:function(a,b){return this.animate({height:"hide"},a,b)},slideToggle:function(a,b){return this.animate({height:"toggle"},a,b)},fadeIn:function(a,b){return this.animate({opacity:"show"},a,b)},fadeOut:function(a,b){return this.animate({opacity:"hide"},a,b)},fadeTo:function(a,b,c){return this.animate({opacity:b},a,c)},animate:function(h,i,j,k){var l=v.speed(i,j,k);return this[l.queue===false?"each":"queue"](function(){if(this.nodeType!=1)return false;var f=v.extend({},l);var g=v(this).is(":hidden"),self=this;for(var p in h){if(h[p]=="hide"&&g||h[p]=="show"&&!g)return v.isFunction(f.complete)&&f.complete.apply(this);if(p=="height"||p=="width"){f.display=v.css(this,"display");f.overflow=this.style.overflow}}if(f.overflow!=null)this.style.overflow="hidden";f.curAnim=v.extend({},h);v.each(h,function(a,b){var e=new v.fx(self,f,a);if(/toggle|show|hide/.test(b))e[b=="toggle"?g?"show":"hide":b](h);else{var c=b.toString().match(/^([+-]=)?([\d+-.]+)(.*)$/),start=e.cur(true)||0;if(c){var d=parseFloat(c[2]),unit=c[3]||"px";if(unit!="px"){self.style[a]=(d||1)+unit;start=((d||1)/e.cur(true))*start;self.style[a]=start+unit}if(c[1])d=((c[1]=="-="?-1:1)*d)+start;e.custom(start,d,unit)}else e.custom(start,b,"")}});return true})},queue:function(a,b){if(v.isFunction(a)||(a&&a.constructor==Array)){b=a;a="fx"}if(!a||(typeof a=="string"&&!b))return I(this[0],a);return this.each(function(){if(b.constructor==Array)I(this,a,b);else{I(this,a).push(b);if(I(this,a).length==1)b.apply(this)}})},stop:function(a,b){var c=v.timers;if(a)this.queue([]);this.each(function(){for(var i=c.length-1;i>=0;i--)if(c[i].elem==this){if(b)c[i](true);c.splice(i,1)}});if(!b)this.dequeue();return this}});var I=function(a,b,c){if(!a)return undefined;b=b||"fx";var q=v.data(a,b+"queue");if(!q||c)q=v.data(a,b+"queue",c?v.makeArray(c):[]);return q};v.fn.dequeue=function(a){a=a||"fx";return this.each(function(){var q=I(this,a);q.shift();if(q.length)q[0].apply(this)})};v.extend({speed:function(a,b,c){var d=a&&a.constructor==Object?a:{complete:c||!c&&b||v.isFunction(a)&&a,duration:a,easing:c&&b||b&&b.constructor!=Function&&b};d.duration=(d.duration&&d.duration.constructor==Number?d.duration:{slow:600,fast:200}[d.duration])||400;d.old=d.complete;d.complete=function(){if(d.queue!==false)v(this).dequeue();if(v.isFunction(d.old))d.old.apply(this)};return d},easing:{linear:function(p,n,a,b){return a+b*p},swing:function(p,n,a,b){return((-Math.cos(p*Math.PI)/2)+0.5)*b+a}},timers:[],timerId:null,fx:function(a,b,c){this.options=b;this.elem=a;this.prop=c;if(!b.orig)b.orig={}}});v.fx.prototype={update:function(){if(this.options.step)this.options.step.apply(this.elem,[this.now,this]);(v.fx.step[this.prop]||v.fx.step._default)(this);if(this.prop=="height"||this.prop=="width")this.elem.style.display="block"},cur:function(a){if(this.elem[this.prop]!=null&&this.elem.style[this.prop]==null)return this.elem[this.prop];var r=parseFloat(v.css(this.elem,this.prop,a));return r&&r>-10000?r:parseFloat(v.curCSS(this.elem,this.prop))||0},custom:function(b,c,d){this.startTime=(new Date()).getTime();this.start=b;this.end=c;this.unit=d||this.unit||"px";this.now=this.start;this.pos=this.state=0;this.update();var e=this;function t(a){return e.step(a)}t.elem=this.elem;v.timers.push(t);if(v.timerId==null){v.timerId=setInterval(function(){var a=v.timers;for(var i=0;i<a.length;i++)if(!a[i]())a.splice(i--,1);if(!a.length){clearInterval(v.timerId);v.timerId=null}},13)}},show:function(){this.options.orig[this.prop]=v.attr(this.elem.style,this.prop);this.options.show=true;this.custom(0,this.cur());if(this.prop=="width"||this.prop=="height")this.elem.style[this.prop]="1px";v(this.elem).show()},hide:function(){this.options.orig[this.prop]=v.attr(this.elem.style,this.prop);this.options.hide=true;this.custom(this.cur(),0)},step:function(a){var t=(new Date()).getTime();if(a||t>this.options.duration+this.startTime){this.now=this.end;this.pos=this.state=1;this.update();this.options.curAnim[this.prop]=true;var b=true;for(var i in this.options.curAnim)if(this.options.curAnim[i]!==true)b=false;if(b){if(this.options.display!=null){this.elem.style.overflow=this.options.overflow;this.elem.style.display=this.options.display;if(v.css(this.elem,"display")=="none")this.elem.style.display="block"}if(this.options.hide)this.elem.style.display="none";if(this.options.hide||this.options.show)for(var p in this.options.curAnim)v.attr(this.elem.style,p,this.options.orig[p])}if(b&&v.isFunction(this.options.complete))this.options.complete.apply(this.elem);return false}else{var n=t-this.startTime;this.state=n/this.options.duration;this.pos=v.easing[this.options.easing||(v.easing.swing?"swing":"linear")](this.state,n,0,1,this.options.duration);this.now=this.start+((this.end-this.start)*this.pos);this.update()}return true}};v.fx.step={scrollLeft:function(a){a.elem.scrollLeft=a.now},scrollTop:function(a){a.elem.scrollTop=a.now},opacity:function(a){v.attr(a.elem.style,"opacity",a.now)},_default:function(a){a.elem.style[a.prop]=a.now+a.unit}};v.fn.offset=function(){var b=0,top=0,elem=this[0],results;if(elem)with(v.browser){var c=elem.parentNode,offsetChild=elem,offsetParent=elem.offsetParent,doc=elem.ownerDocument,safari2=safari&&parseInt(version)<522&&!/adobeair/i.test(C),fixed=v.css(elem,"position")=="fixed";if(elem.getBoundingClientRect){var d=elem.getBoundingClientRect();add(d.left+Math.max(doc.documentElement.scrollLeft,doc.body.scrollLeft),d.top+Math.max(doc.documentElement.scrollTop,doc.body.scrollTop));add(-doc.documentElement.clientLeft,-doc.documentElement.clientTop)}else{add(elem.offsetLeft,elem.offsetTop);while(offsetParent){add(offsetParent.offsetLeft,offsetParent.offsetTop);if(mozilla&&!/^t(able|d|h)$/i.test(offsetParent.tagName)||safari&&!safari2)border(offsetParent);if(!fixed&&v.css(offsetParent,"position")=="fixed")fixed=true;offsetChild=/^body$/i.test(offsetParent.tagName)?offsetChild:offsetParent;offsetParent=offsetParent.offsetParent}while(c&&c.tagName&&!/^body|html$/i.test(c.tagName)){if(!/^inline|table.*$/i.test(v.css(c,"display")))add(-c.scrollLeft,-c.scrollTop);if(mozilla&&v.css(c,"overflow")!="visible")border(c);c=c.parentNode}if((safari2&&(fixed||v.css(offsetChild,"position")=="absolute"))||(mozilla&&v.css(offsetChild,"position")!="absolute"))add(-doc.body.offsetLeft,-doc.body.offsetTop);if(fixed)add(Math.max(doc.documentElement.scrollLeft,doc.body.scrollLeft),Math.max(doc.documentElement.scrollTop,doc.body.scrollTop))}results={top:top,left:b}}function border(a){add(v.curCSS(a,"borderLeftWidth",true),v.curCSS(a,"borderTopWidth",true))}function add(l,t){b+=parseInt(l)||0;top+=parseInt(t)||0}return results}})();//"

// play nice with other libraries that use $:
jQuery.noConflict();


// Babelmark GUI (c) 2008 John Fraser
// http://attacklab.net/babelmark/
// MIT license: http://www.opensource.org/licenses/mit-license.php
 
// This code makes some assumptions about the HTML it's used with.  First, in injectHtml():
// 
//     $("div#app > div").addClass("implementation");
// 
// ...So it assumes each div that's a direct child of #app represents an implementation.
// 
// Second, in startGui(), it grabs the implementation name from $(".implementation label"),
// trimming whitepace and cutting off a trailing ":" if it's there.  Finally, it reads the
// implementation's output from $(".implementation code").

(function ($){

var bookmarklet = false;

var implementations = [];
var src = queryString("src") || 1;
var dest = queryString("dest") || 2;
var compare = queryString("compare") || "off";

function queryString(key) {
    var re = RegExp("[?&]"+key+"=(.*?)([?&]|$)");
    return re.test(document.location.href) ? RegExp.$1 : null;
    return match ? match[1] : null;
}

// Ideally this would be all done in the HTML and CSS files themselves.
function injectHtmlHooks() {
    $("div#app > div").addClass("implementation");

    // Ideally this would be in the css file:
	$("head").append(
    	"<style>"
        	+"del {background: #f88 ! important;}"
        	+"ins {background: #8f8 ! important; text-decoration: none;}"
        	+"#srcList,#destList {width: 49%; float: left;}"
        	+".match {color: black} .nonmatch {color: #888}"
        	+"#diffTitle {font-weight: bold ! important;}"
        	+"#buttonrow label {margin-right: 2em}"
        	+".group0 {color: #66a;}"
        	+".group1 {color: #a66;}"
        	+".group2 {color: #660;}"
        	+".group3 {color: #a80;}"
        	+".group4 {color: #066;}"
        	+".group5 {color: #80a;}"
        	+".group6 {color: #a06;}"
        	+".group7 {color: #6a6;}"
        	+".group8 {color: #0a8;}"
        	+".group9 {color: #8a0;}"
        +"</style>");

    // Add form controls for switching modes
    $("#buttonrow input:last").before(
        '<label for="compare"><input type="checkbox" name="compare" id="compare">Compare...</label>');
	
	// Add divs for our UI
    $("form").append(
        '<div id="diffDiv">'
            +'<div id="srcList"><label>Compare:</label><br></div>'
            +'<div id="destList"><label>To:</label><br></div>'
            +'<br style="clear: left"><br>'
            +'<label id="diffTitle"></label>'
            +'<div id="diffOutput"></div>'
        +'</div>');

    // IE strips out newlines if we insert Showdown's output with createTextNode()
    // or innerText().  Instead we'll use innerHtml (inside jQuery's html() function)
    // and escape the html ourselves.
	var output = new Showdown.converter().makeHtml($("#markdown").val());
	output = output.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
    $("#showdown-result").html(output);
}

function radioList(listName) {
	for (var i=0,items=[]; i<implementations.length; i++) {
	    var id = ""+listName+i;
    	items.push('<label for="'+id+'"><input type="radio" value="' + i + '" name="'+listName+'" id="'+id+'">'
    	+ implementations[i].name+'</label>');
	}
	return items.join("<br>\n");
}

// Color each entry in the dest list to show whether or not it's equivalent to src
function colorDestList() {
    var srcText = implementations[src].output.replace(/\s+/g,"");
    $("#destList label:gt(0)").each(function(i){
        var destText = implementations[i].output;

        // super-naive: just strip all whitespace and do a string comparision
        if (destText.replace(/\s+/g,"") === srcText) {
            $(this).addClass("match").removeClass("nonmatch");
        } else {
            $(this).removeClass("match").addClass("nonmatch");
        }
    });
}

// split implementations into groups by output
function colorSrcList() {
    // build groups
    var groups = {};
    for (var i=0; i<implementations.length; i++) {
        var output = implementations[i].output.replace(/\s+/g,"");
        if (groups[output] == null) {
            groups[output] = [i];
        } else {
            groups[output].push(i);
        }
    };

    // color by group
    var g = 0;
    for (var output in groups) {
        var group = groups[output];
        var className = "group" + (g++%10);
        for (var i=0; i<group.length; i++) {
            $("#srcList label:gt(0)")[group[i]].className = className;
        }
    }
}

function doDiff() {
	var dmp = new diff_match_patch();
	var diff = dmp.diff_main(implementations[src].output, implementations[dest].output);
	dmp.diff_cleanupSemantic(diff);
    $("#diffTitle").text('$ diff "'+implementations[src].name + '" "' + implementations[dest].name + '"')
    $("#diffOutput").html('<pre><code>' + dmp.diff_prettyHtml(diff) + '</pre></code>');

    colorDestList();
}

function toggleCompare() {
   	doDiff();
   	$(".implementation").toggle();
   	$("#diffDiv").toggle();
}

function startGui() {
    injectHtmlHooks();
    
    // build a list of all implementations and their output
	$(".implementation").each(function(){
	    // strip ":" and whitespace:
	    var name = $("label",this).text().replace(/\s*:\s*$/,"");
	    // normalize line endings:
	    var output = $("code",this).text().replace(/\r\n/g,"\n").replace(/\r/g,"\n");

        implementations.push({name:name,output:output});
	});

    // populate the radio button lists
    $("#srcList").append(radioList("src"));
    $("#destList").append(radioList("dest"));

    // select default values
	$("#srcList input").get(src).checked = "checked";
	$("#destList input").get(dest).checked = "checked";
   	$(".implementation").show();
   	$("#diffDiv").hide();
	if (compare == "on") {
       	doDiff();
       	$(".implementation").hide();
       	$("#diffDiv").show();
    	$("#compare").attr("checked","checked");
    }

    // add event handlers
	$("#srcList input").click(function(){
	    src = $(this).attr("value");
        doDiff();
	});
	$("#destList input").click(function(){
	    dest = $(this).attr("value");
        doDiff();
	});
    $("#compare").click(toggleCompare);

    colorSrcList();
}

if (bookmarklet) {
    startGui();
} else {
    $(document).ready(startGui);
}

})(jQuery);