/*
version=1.0.0;
Details=Webplugs JavaScript Framework Core File;
license=GNU;
*/
(function() {

	//var wp=window.wp=window.$=function(v){
	var wp=window.wp=function(v){
		return new wp.fN.init(v);
	}

	wp.fN=wp.prototype={
		init:function(v){
			this.v=wp.element.v=v			
			this.v=v
			return this
		}
	}
	
	wp.extend=wp.fN.extend=function(d,s){
		if(!s)s=this;
		for(var i in d){
			s[i]=d[i]
			wp.fN[i]=d[i]
		}
	}
	
	wp.extend({
	version:"1.0",
	defaultTheme:"Office2003",
	server:"php",
	zindex:500,
	inc:[],
	dep:[],
	fire:{},
	uId:0,
	/*@cc_on
		msie:navigator.appVersion.match(/MSIE (\d\.\d)/)[1], // We only need to to browser checks for IE, all code is developed to work accross browsers but IE does very different things depending on its version
	@*/
	// if(window.WebKitPoint) - Safari or Chrome
	element:{},
	msg:function(v,o)
	{
		var m=wp.addNode(document.body,"div");
		wp.hide(m)
		m.innerHTML=v
		wp(m).into("dialog",o)
	},
	bob:function(o,S)
	{
		if(!o)o={};
		if(typeof(o.theme)=="undefined")o.theme=wp.defaultTheme;
		if(S&&!o.style)o.style="Default"
		return o
	},
	getE:function(e)
	{
		if(e.tagName)return e
		return e.target?e.target:e.srcElement;
	},
	rT:function(v,d){
		/*
		v:value, d:defaultto return  if undefined
		This function takes a value and returns true if it is undefined.
		It means we can have a default of true for a value even though nothing has been declared.
		*/
		if(!d)d=true
		if(typeof(v)=="undefined")v=d;
		return v;
	},
	iePngFix:function(T)
	{
		if(!T)T="scale"
		if(wp.msie<7){
			wp.each(wp.seek(this.v),function(a,i){
				var IM=wp.css.get(a[i],"background-image")   // Get the background image rule from CSS
				if(IM.search(/.png/ig)>-1){                  // Only apply if image is a .png
					a[i].style.backgroundImage="url('')";    // Need to remove the backgroundImage rule, replacing with AlphaImageLoader rule instead
					IM=IM.replace(/^url\(\"+|\"\)+$/g,'');   // Extract filename from CSS rule
					a[i].style.filter+="progid:DXImageTransform.Microsoft.AlphaImageLoader(src="+IM+",sizingMethod="+T+")";
				}
			})
		}
		return this
	},
	/*
	getType:function(v) // Gets the type of wpObject from the className
	{
		v=v.className.split(v.wpObject.theme)
		v=v[1].split(" ")[0].toLowerCase()
		return v
	},
	*/
	changeTheme:function(v,newTheme)
	{
		var V=wp.get(v)
		var aa=V.getElementsByTagName("*")
		aa[aa.length]=V
		wp.each(aa,function(a,i){
			if(a[i].wpObject){
				a[i].className=a[i].className.replace("wp"+a[i].wpObject.theme,"wp"+newTheme);
				a[i].wpObject.theme=newTheme
				wp.css.add(a[i].wpObject,a[i].webplug);
			}
		})
	},		
	seek:function(v,L)
	{
		if(!this.fN)v=this.v;
		var output=[],i,c,e,s,I,a,A,R=[],O,o,S,OBJ,J=0,K;
		if(typeof(v)=="string"){
			s=v.split(".");
			i=s[0];
			c=s[1];
			s=i.split("+");
			i=s[0];
			e=s[1]?s[1]:"*";
			I=wp.get(i);
			if(c){
				if(!I)I=document;
				if(L)I=L;

				OBJ=I.getElementsByTagName(e);
				if(OBJ.length==0){
					OBJ=[]
					OBJ[0]=I
				}
				//if(!OBJ.length)output.push(I);
				K=OBJ.length
				while(J<K){
					var found=0;
					if(OBJ[J].className){
						wp.each(OBJ[J].className.split(" "),function(a,i){
							if(a[i]==c)found=1;
						})
					}
					if(O&&e!=OBJ[J].id)found=0;
					if(found)output.push(OBJ[J]);
					J++
				}
			}
			else{
				if(i&&e=="*")return I?[I]:[];
				else{
					if(!L)L=document
					output=L.getElementsByTagName(e);
				}
			}
			if(output.length==0)output=null
			return output;
		}
		else{
			return v
		}
	},
	each:function(o,f,a) // a parameter forces each to scan through all elements in an object
	{
		if(!o)return
		if(a||o.length){
			for(var O in o){
				//if(typeof(o[O])!="string")alert(typeof(o[O]))
				if(O!="length" && typeof(o[O])!="function")f.call(this,o,O)
			}
		}
		else{
			f.call(this,[o],0)
		}
	},
	loadFunc:[],
	onload:function(f)
	{
		wp.loadFunc.push(function(){return f.apply(f)})
	},
	setready:function()
	{
		for(var x=0;x<wp.loadFunc.length;x++)wp.loadFunc[x].apply();
		wp.docState="complete";
		try{document.execCommand("BackgroundImageCache",false,true)}catch(err){}
	},
	ready:function()
	{
		var d=document;
		if(d.addEventListener){
			d.addEventListener('DOMContentLoaded',wp.setready,false);
		}
		else if(wp.msie){
			try{d.documentElement.doScroll("left")}catch(error){
				setTimeout("wp.ready()",10);
				return;
			}
			wp.setready()
		}
		else wp.addEvent(window,"load",wp.setready())
	},	
	getPath:function(F)
	{
		if(wp.path)return wp.path
		if(F)return F;
		var S,a,s,V;
		S=document.getElementsByTagName("script");
		for(a=0;a<S.length;a++){
			V=S[a].src;
			s=V.split("\/");
			if(s[s.length-1]=="webplugs.js"){
				wp.path=V.substr(0,V.length-11)
				return wp.path
			}
		}
	},
	include:function(f,F)
	{
		var S
		if(!wp.inc[f]){
			if(!wp.docState){
				document.write('<scr'+'ipt type="text/javascript" src="'+wp.getPath(F)+f+'.js"></scr'+'ipt>');
			}
			else{
				S=document.createElement('script');
				S.type='text/javascript';
				S.src=wp.getPath(F)+f+".js"
				document.getElementsByTagName("head")[0].appendChild(S);
			}
			wp.dep.push(f)
			wp.inc[f]=1
		}
		return this;
	},
	incOnLoad:function(f,p)
	{
		for(var d in wp.dep){
			if(!wp[wp.dep[d]]){
			var V=this.v
				setTimeout(function(){wp(V).incOnLoad(f,p)},10);
				return
			}
		}

		if(wp[f]&&wp[f].exec){
			wp[f].exec(this.v,p)
		}
		return this
	},
	into:function(v,p)
	{
		wp(this.v).include(v).incOnLoad(v,p)
		return this;
	},
	create:function(v,o)
	{
		if(!o)o={}
		var D=wp.addNode("div")
		D.innerHTML="Webplugs"
		wp(D).into(v,o)
	},
	ondone:function(v)
	{
		for(var d in wp.dep){
			if(!wp[wp.dep[d]]){
				//alert(wp.dep+" - "+d + " - "+wp.dep[d]+" - "+wp[wp.dep[d]])
				setTimeout(function(){wp.ondone(v)},10);
				return
			}
		}
		v()
	},
	dependencies:function(v)
	{
		var D=v.split(",");
		wp.each(D,function(a,i){
			wp.include(a[i])
		})
	},
	get:function(v,w)
	{
		if(!w)w=window;
		if(!this.fN)v=this.v;
		if(!v)return null;
		if(typeof(v)=="string")v=w.document.getElementById(v);
		return v
	},
	getAll:function(v)
	{
		if(wp.msie<6) return v.all; else return v.getElementsByTagName("*")
	},
	cloneNode:function(i) // wp.cloneNode(OBJ:object,BOOL:before/after(default is after),BOOL:do NOT include children)
	{
		var N=i.cloneNode(true),
		li=i.getElementsByTagName('*'),
		li2=N.getElementsByTagName('*');
	
		if(!wp.msie){
			wp.each(li,
				function(V,ii){
					if(ii){
						if(V[ii].nodeType==1 && V[ii].wpEvents){
							for(var a in V[ii].wpEvents){
								wp.addEvent(li2[ii],a.split("_")[0],V[ii].wpEvents[a])
							}
						}
					}
				}
			)
		}
		return N
	},
	insertNode:function(N,i,p)
	{
		i.parentNode.insertBefore(N,p?i:i.nextSibling);
	},
	swapNode:function(n1,n2)
	{
		var N=wp.msie?n2:n2.nextSibling;
		n1.parentNode.replaceChild(n2,n1);
		n2.parentNode.insertBefore(n1,N);			
	},
	/*
	allOffspring:function(v)
	{
		return v.getElementsByTagName("*");
	},
	rScr:function(v)
	{
		
		var V=wp.allOffspring(v)
		for(var a in V)
		{
			//if(V[a].wpScript)alert(a)
		}
		
		
		
		v=v.wpScript
		if(v)v.parentNode.removeChild(v);
	},
	*/
	removeNode:function(f)
	{
		var F=wp.seek(this.v)
		if(f)F=wp.get(f) // This allows for both wp(OBJ).removeNode() as well as wp.removeNode(OBJ)
		wp.each(F,function(V){
			
			if(V.length>-1){ // This will only remove the first Node in a collecion - Do we need to remove multiple nodes?
				if(!V[0].parentNode||V.length==0)return wp;
				V[0].parentNode.removeChild(V[0]);
			}
			else{
				V.parentNode.removeChild(V);
			}
		})
		return this
	},
	appendScript:function(v)
	{
		var re=/<script\b[\s\S]*?>([\s\S]*?)<\/script>/i,match,scr="",D=[];
		while(match=re.exec(v)){
			scr+=match[1]+"\n"
			v=v.replace(re,"");
		}
		if(scr!=""){
			var S2=document.createElement('script');
			S2.type='text/javascript';
			S2.text=scr
			S2.id="_wpScript"+wp.uId++;
			document.getElementsByTagName("head")[0].appendChild(S2);
			var js=document.getElementsByTagName("script") // Check to see if the script already exists
			for(S in js){
				if(js[S]&&js[S].id&&(js[S].text.length==scr.length)&&(js[S].text==scr))if(js[S].id!=S2.id)wp.removeNode(js[S]) // if it does exist, remove the script and start again.
			}
		}
	},		
	addNode:function(d,e,p){
		// d object adding to
		// e element to add
		// p flag for including object as first object
		if(typeof(d)=="string"){//If d is a string then we assume that you want the string added as an element to document.body
			e=d;
			d=document.body;
		}
	
		var O=document.createElement(e);
		if(p){
			if(d.firstChild)d.insertBefore(O,d.firstChild);
		}
		else{
			d.appendChild(O);
		}
		return O
	},
	getParentNode:function(v,t,c)
	{
		if(!c)c=1;
		var found=0
		var count=1;
		while(!found&&v.tagName){
			v=v.parentNode;
			if(v.tagName==t){
				if(count==c)found=1
				count++
			}
		}
		if(!v.tagName)v=undefined
		return v
	},
	//},
	//event:
	//{
		addEvent:function(o,t,f)
		{
			if(!o.wpEvents)o.wpEvents={};
			var N=t+"_wpEvent"+wp.uId++;

			if(wp.msie){
				o[N]=f;
				o.wpEvents[N]=function(e){
					o[N](e);
					//alert(this)
					/*
					if(o.parentWindow){
						//alert(1)
						o[N](e,o.parentWindow.event,e);
					}
					else if(o.ownerDocument){
						//alert(2)
						o[N](e,o.ownerDocument.parentWindow.event,e);
					}						
					else{
						//alert(3)
						o[N](e,window.event,e);
					}
					*/
				}
			}
			else 
			o.wpEvents[N]=f;

			if(o.attachEvent)o.attachEvent("on"+t,o.wpEvents[N]);else o.addEventListener(t,o.wpEvents[N],false)
			return this
		},

		execEvent:function(o,eType)
		{
			for(var a in o.wpEvents){
				if(a.split("_")[0]==eType)o.wpEvents[a].call(o,o)
			}
			return this
		},		
		removeEvent:function(o,t,f)
		{
			var O,C,E=o.wpEvents;
			for(C in E){
				var S=E[C];
				if(wp.msie)S=o[C];
				if(S&&f&&(S.toString()==f.toString()))O=C;
			}
			if(O){
				f=E[O];
				delete E[O];
				if(wp.msie)delete S
				if(o.detachEvent)o.detachEvent("on"+t,f);else o.removeEventListener(t,f,false)
			}
			return this
		},

		cancelEvent:function(e)
		{
			if(!e)return false;
			e.returnValue=false;
			e.cancelBubble=true;
			if(e.preventDefault){
				e.preventDefault();
				e.stopPropagation&&e.stopPropagation()
			}
			return false
		//}	
	},
	makeMovable:function(v)
	{
		v.style.position="absolute";
		return this
	},
	show:function(v)
	{
		//v.style.display="block";
		v.style.visibility="visible"
		return this
	},	
	hide:function(v)
	{
		//v.style.display="none";
		v.style.visibility="hidden"
		return this
	},
	outerHtml:function(v)
	{
		if(v.outerHTML)return v.outerHTML;
		else
		{
			var E={"IMG":1,"BR":1,"INPUT":1,"META":1,"LINK":1,"PARAM":1,"HR":1},
			A=v.attributes,S="<"+v.tagName,x;
			for(x=0;x<A.length;x++)S+=" "+A[x].name+"=\""+A[x].value+"\"";
			if(E[v.tagName])return S+" />";
			return S+">"+v.innerHTML+"</"+v.tagName+">";			
		}
	},
	IsWS:function(n)
	{
		return !(/[^\t\n\r ]/.test(n.data));
	},
	WsIgnore:function(n)
	{
		return(n.nodeType==8)||((n.nodeType==3)&&wp.IsWS(n));
	},
	previous:function(o)
	{
		while((o=o.previousSibling))if(!wp.WsIgnore(o))return o;
	},
	next:function(o)
	{
		while((o=o.nextSibling))if(!wp.WsIgnore(o))return o;
	},
	firstElement:function(v,Z)
	{
		Z=0;
		if(v.childNodes[0].nodeType==3)Z=1;
		return v.childNodes[Z];
	},
/*
last_child:function ( par )
{
	var res=par.lastChild;
	while (res) {
	if (!wp.WsIgnore(res)) return res;
	res = res.previousSibling;
	}
	return null;
},
first_child:function ( par )
{
	var res=par.firstChild;
	while (res) {
	if (!wp.WsIgnore(res)) return res;
	res = res.nextSibling;
	}
	return null;
},
*/
	tofront:function(v)
	{
		v.style.zIndex=wp.zindex++
		return this
	},
	getMouseCoords:function(e)
	{
		return{x:e.clientX,y:e.clientY}
	},	
	getObjMouseCoords:function(e)
	{
		//if(window.event)e=event;
		return{x:e.layerX?e.layerX:e.offsetX,y:e.layerY?e.layerY:e.offsetY}
	},
	S:function(v) // same as: var tempVar="";if(val)tempVar=val;
	{
		return v?v:"";
	},
	wpAction:function(v,a)
	{
		a="on"+a
		if(v.wpObject[a])v.wpObject[a]()
	},
	setEvents:function(D,II)
	{
		for(var C in II)if(C.substr(0,2)=="on"){
			wp.addEvent(D,C.substr(2),II[C])
		}
	},
	px:function(v)
	{
		var out=parseInt(v);
		if(!isNaN(out))return out+"px";
		return v;
	},
	fixZI:function(v)
	{
		var e,p;
		if(wp.msie){
			try{
				if(v.filters)
				{
					e=wp.addNode(v,"iframe",true);
					e.style.filter="Alpha(Opacity=0)"
					e.style.position="absolute"
					//e.style.display="block"
					e.style.top="-1px";
					
					e.style.left="-1px";
					e.className="wpMenuMask"
					v.iframe=e
					p=this.getDimension(v)
					wp(e).setDimension({height:p.height,width:p.width})
					e.style.visibility="visible"
					e.style.zIndex=-1			
				}
			}
			catch(e){}
		}
	},

		DELETE_get_Obj:function(o,t)
		{
			if(o&&o.object)wp.v=o.object;
			for(var C in o)if(C!="object")t[C]=o[C];
			return wp.v
		},
		edit:function()
		{
			var W=wp.get("wpEd")
			if(W){
				wp(W).openWindow()
			}
			else{
				var W=wp.addNode(document.body,"DIV");
				W.id="wpEd";
				wp(W).into("htmleditor",{windowable:true});
				
				wp.addEvent(document.body,'mousemove',function(e){
					E=wp.getE(e)
					N=wp.get("wpEdH");
					if(N)wp.removeNode(N);
					N=wp.addNode(E,"DIV");
					N.id="wpEdH";
					N.style.position="absolute";
					N.style.border="2px solid #3789ef";
					N.style.MozBorderRadius="5px"
					N.style.WebkitBorderRadius="5px"
					
					var T=N
					var P=wp.getPosition(E);
					var D=wp.getDimension(E);
					var S=wp.getScrolling(document);
					
					if(E.id!="wpEdH")
					{
						wp(T).setPosition({top:P.top-4,left:P.left-4}).setDimension({height:D.height+4,width:D.width+4})
					}
					
					T.style.zIndex=0
					
					//T.style.display="block"
					
					
					
				var a=wp.get(W.id+"contentEdit")
				a.contentWindow.document.body.innerHTML=E.innerHTML
				
				//wp.debug.objects(a.contentWindow.document.body)
					

					if(E.tagName=="A")
					{
						wp.addEvent(E,'click',function(e){
							wp.cancelEvent(e);
							return false
						})
					}
				})

				wp.addEvent(document.body,'mousedown',function(e){
					//wp.cancelEvent(e);
					//return false
					
				})

				wp.addEvent(document.body,'click',function(e){
					
					
					//wp.cancelEvent(e);
					//return false
					
				})
			}
		},	
	DELETE_all:function(o,f)
	{
		var v=wp.get_Obj(o,this);
		if(v.length){
			for(O in v)f.call(this,v[O],O)
		}
		else{
			f.call(this,v)
		}
	},		
	progUpdate:function()
	{
			var A=wp.get("_WP_pBar")
			
			if(!A)
			{
				
				//document.write("<div id=_WP_pBar style='border:1px solid black'><br></div>")
				
				
				

				A=wp.addNode(document.getElementsByTagName('HEAD').item(0),"DIV")
				A.id="_WP_pBar"
				A.style.border="1px solid black"
				A.style.position="absolute"
				A.style.top="100px"
				A.style.left="100px"

			}
			
			A.innerHTML=A.innerHTML+"loading: "
			A.innerHTML=A.innerHTML+".......done<br>"
				
	}		
	})
	wp.fN.init.prototype = wp.fN;
})()


wp.extend({
	debug:{
		objects:function(v)
		{
			if(!wp.docState){
				setTimeout(function(){wp(this.v).debug.objects(v)},20)
				return this
			}
			var a=wp.get("wpObj_P");
			if(!a)
			{
				var a=document.createElement("div");
				document.body.appendChild(a);
				a.id="wpObj_P";
				a.className="wpDebug"
				a.style.height="400px"

				//a.innerHTML="aaa"
				
				wp(a).into("window").ondone(function(){
					
					wp.css.add("","debug");
					wp.debug.createLinks(a,v);
				})
				
			}
			else{
				
				//wp(a).changeWindowContent(h)
				a.style.display="block"
				wp.debug.createLinks(a,v);
			}
			return this
		},
		createLinks:function(a,v,S)
		{
			var A,P
			a.content.innerHTML=""

			var V={}
			if(S)V['back']=S;
			
			
			V['wp']=wp(this)
			
			for(var i in v){
				try{V[i]=v[i]}catch(err){}
				
			}
			v=V
			
			for(var _cO in V){
				try{
						
					P=wp.addNode(a.content,"p");
					P.innerHTML=_cO+" - "
					
					A=wp.addNode(P,"a");
					A.innerHTML=V[_cO]
					A.obj=_cO
					
					if(v[_cO]&& typeof(v[_cO])==="object"){
						A.href="#"
						A.onclick=function(){
							wp.debug.createLinks(a,v[this.obj], a.S);
							return false;
						}
					}	
				}catch(err){}
				
			}
			a.S=v
		}
	}
})

	wp.extend({
		toarray:function(v){
			if(!v)v="";
			return this.split(v)
		}

	},String.prototype)

/* Remove this as we no longer support IE5.5 or below 
	if(wp.msie<5.5){
		wp.extend({
			push:function(v){this[this.length]=v}
		},Array.prototype)
		
		wp.extend({
			getElementsByTagName:function(str){return(str=='*')?document.all:document.all.tags(str)}
		},document)
	}

*/

wp.ready()

