/*
Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.html or http://ckeditor.com/license
*/

(function(){(function(){CKEDITOR.plugins.add('wygwam',{init:function(d){CKEDITOR.on('instanceReady',function(e){if(CKEDITOR.env.webkit)e.editor.on('paste',function(f){var g=f.data,h=f.editor;if(typeof g.html!=='undefined'&&g.html!=''){g.html=g.html.replace(/<(META|LINK)[^>]*>\s*/gi,'');var i=document.createElement('div');i.innerHTML=g.html;if(i.children.length==1&&i.children[0].className.indexOf('Apple-style-span')>-1){g.html=$(i).children[0].innerHTML;i=document.createElement('div');i.innerHTML=g.html;}var j=h.getSelection(),k=j.getRanges()[0],l=k.startContainer,m=l.getNext();if(k.startContainer.$.nodeName!='#text'){if(l.$.innerHTML.match(/^\s*<br>\s*$/)&&l.$.tagName=='P'){var n=new CKEDITOR.dom.range(k.document),o=document.createDocumentFragment();for(var p=0;p<i.childNodes.length;++p){if(typeof i.childNodes[p]=='object'){if(i.childNodes[p].nodeName=='#text')o.appendChild(document.createTextNode(i.childNodes[p].data));else o.appendChild(i.childNodes[p].cloneNode(true));}}l.$.parentNode.replaceChild(o,l.$);if(m){n.setStartAt(m,3);n.setEndAt(m,3);}else{n.setStartAt(h.document.getBody(),2);n.setEndAt(h.document.getBody(),2);}n.select();f.cancel();}}}});});CKEDITOR.on('dialogDefinition',function(e){var f=[],g=[];f.id='advId';f.dir='advLangDir';f.accesskey='advAccessKey';f.name='advName';f.lang='advLangCode';f.tabindex='advTabIndex';f.title='advTitle';f.type='advContentType';f['class']='advCSSClasses';f.charset='advCharset';f.style='advStyles';f.rel='advRel';g.target='linkTargetType';var h=e.data.definition,i=e.data.name,j=h.getContents('info'),k=[],l=d.config.link_types;if(e.editor!=d||i!='link')return;var m=b(j.elements,'linkType');if(l)for(label in l){var n=a(label);m.items.push([label,n]);k.push(n);}m.onChange=CKEDITOR.tools.override(m.onChange,function(z){return function(){z.call(this);var A=this.getValue(),B=this.getDialog();if(l){if(c(k,A,false))for(var C=0;C<k.length;C++){var D=B.getContentElement('info',k[C]+'_wrapper').getElement();if(!D)continue;if(k[C]==A){D.show();var E=B.getContentElement('info',k[C]);x(E);y(E);}else D.hide();}else for(var C=0;C<k.length;C++){var D=B.getContentElement('info',k[C]+'_wrapper').getElement();if(!D)continue;D.hide();var E=B.getContentElement('info',k[C]);x(E);}for(var F in l){if(A==a(F))B.showPage('target');}}};});for(var o in l){var p=a(o),q=l[o],r=0,s=[];for(var t in q){var u=q[t],v='';if(u.label_depth)v=new Array(u.label_depth*4+1).join('\xa0');s[r]=[v+u.label,u.url];r++;}var w={id:p,type:'select',label:o,items:s,required:true,onLoad:function(){var z=this.getDialog(),A=z.getContentElement('info',this.id+'_wrapper').getElement();
A.hide();},setup:function(z){if(z.type==this.id)this.setValue(z.customLinkUrl||'');},commit:function(z){if(z.type==this.id)z.customLinkUrl=this.getValue();},validate:function(){var z=this.getDialog();if(m){if(z.getValueOf('info','linkType')==this.id)return true;}},onChange:function(){x(this);y(this);}};j.elements.push({type:'vbox',id:p+'_wrapper',children:[w]});}var x=function(z){for(var A in f){var B=z.getDialog().getContentElement('advanced',f[A]);B.setValue('');}for(var C in g){var D=z.getDialog().getContentElement('target',g[C]);C=='target'?D.setValue('notSet'):D.setValue('');}},y=function(z){var A=z.id;for(var B in l){var C=a(B);if(C==A){var D=l[B];for(var E in D){var F=D[E];if(z.getValue()==F.url)for(var G in F){if(typeof f[G]!='undefined'){var H=z.getDialog().getContentElement('advanced',f[G]);H.setValue(F[G]);}if(typeof g[G]!='undefined'){var I=z.getDialog().getContentElement('target',g[G]);I.setValue(F[G]);}}}}}};});}});})();var a=function(d){d=d.replace(' ','_').toLowerCase();d=d.replace(/\'/g,'');d=d.replace(/\"/g,'');return d;},b=function(d,e){for(var f=0,g;g=d[f];f++){if(g.id==e)return g;}return null;},c=function(d,e,f){var g;if(!d)return false;for(g=0;g<d.length;g++){if(!f){if(d[g].toLowerCase()==e.toLowerCase())return true;}else if(d[g]==e)return true;}return false;};})();
