var procontra={
		ge : function(id){return document.getElementById(id);},
		ce : function(el){return document.createElement(el);},
		gp : function(el){
			var y_pos = 0;
			var x_pos = 0;
			var pos = {};
			pos.width = el.clientWidth;
			pos.height = el.clientHeight;
			pos.x=el.offsetLeft;
			pos.y=el.offsetTop;
			pos.x = x_pos;
			pos.y = y_pos;
			return pos;
		},
		parseQuery : function(str){
			var p={};
			if(str){
				var arr=str.split("&");
				var l=arr.length;
				for(var i=0;i<l;i++){
					var pair=arr[i].split("=");
					p[pair[0]]=pair[1];
				}
			}
			return p;
		},
		toQuery : function(obj){
			var qs=new Array();
			if(obj){
				for(var k in obj){
					if(obj[k]!==null){
						qs.push(k+"="+encodeURIComponent(obj[k]));
					}
				}
			}
			return qs.join("&");
		},
	api: {
		initialized: false,
		init:function(){
			if(!procontra.api.initialized){
				procontra.api.initialized=true;
				if(window.postMessage){
					if(window.addEventListener){
						window.addEventListener ("message", function(e){
						if(e.data!=""){
							var arr=e.data.split("$");
							if(arr[0] && arr[1]){
								procontra.api.getContainer(arr[0]).rm(arr[1]);
							}
						}
					}, false);
				}else {
					window.attachEvent("onmessage", function(e){
						if(e.data!=""){
							var arr=e.data.split("$");
							if(arr[0] && arr[1]){
								procontra.api.getContainer(arr[0]).rm(arr[1]);
							}
						}
					});
				}
			}else {
				window.setInterval(function(){
					if(window.location.hash!="" && 	window.location.hash.indexOf("!~procontra-api:")>-1){
						var arr=window.location.hash.split("!~procontra-api:");
						if(arr[1]){
							var arr1=arr[1].split("$");
							if(arr1[0] && arr1[1]){
								procontra.api.getContainer(arr1[0]).rm(arr1[1]);
							}
						}
						window.location.hash=arr[0];
					}
				},200);
			}
		}
	},
	Container: function(p,params){
			var callback;
			var tooltips=new Array();
			if(p!=-1){
				if(!procontra.api.initialized){
					procontra.api.init();
				}
				if(p && procontra.ge(p)){
					p=procontra.ge(p);
				}
				this.id=null;
				this.parent=null;
				if(p){
					this.parent=p;
					if(!this.parent.id){
						// TODO
					}
					this.id=this.parent.id;
				}
				this.url="http://www.procontra-online.de/newsticker/";
				this.width="100%";
				this.design="";
				this.limit="";
				this.caption="";
				if(params){
					if(params["width"]){
						this.width=params["width"];
					}
					if(params["design"]){
						this.design=params["design"];
					}
					if(params["limit"]){
						this.limit=params["limit"];
					}
					if(params["caption"]){
						this.caption=params["caption"];
					}
				}
				if(params["callback"]){
					callback=params["callback"];
				}
				params["callback"]=null;
				params["target"]=null;
				params["width"]=null;
			}
			this.pm=function(m){
				if(window.postMessage){
					this.contentIframe.contentWindow.postMessage(m,"*");
				}else {
					this.contentIframe.contentWindow.location=this.contentIframe.src+((this.contentIframe.src.indexOf("#")>-1)?"":"#")+"!~blau-api:"+m;
				}
			};
			this.rm=function(m){
				var arr=m.split(":");
				if(arr[0]){
					var action=arr[0];
					var p=(arr[1])?procontra.parseQuery(arr[1]):null;
					var ret=true;
					if(callback){
						ret=callback(action,p);
					}
					if(ret!==false){
						switch(action){
							case "resize":
								if(p["w"]){
									var pos=pos=procontra.gp(this.parent);
									if(p["w"]>pos.width)p["w"]=pos.width;
									this.contentIframe.style.width=Number(p["w"])+"px";
								}
								if(p["h"]){
									this.contentIframe.style.height=Number(p["h"])+"px";
								}
								break;
							case "loaded":
								var i=0;
								while(this.parent.childNodes.length>1){
									if(i==0&&this.parent.childNodes[i]!=this.contentIframe){
											this.parent.removeChild(this.parent.childNodes[i]);
									}else {
										i=1;
									}
								}
								break;
						}
					}
				}
			};
			this.create=function(){
				this.contentIframe=procontra.ce("iframe");
				this.contentIframe.src=this.url+((this.url.indexOf("?")>-1)?"":"?")+"&jsapi=1&design="+this.design+"&limit="+this.limit+"&caption="+encodeURIComponent(this.caption)+"&baseuri="+encodeURIComponent(window.location.href)+"&id="+this.parent.id;
				this.contentIframe.setAttribute("style","border:0;background-color:transparent;height:0;width:"+this.width+";");
				this.contentIframe.setAttribute("frameborder","0");
				this.contentIframe.setAttribute("ALLOWTRANSPARENCY","true");
				this.contentIframe.setAttribute("scrolling","no");
				this.parent.appendChild(this.contentIframe);
			};
			if(p!=-1){
				procontra.api._c[this.id]=this;
			}
		},
		_c:{},
		getContainer:function(p){
			return procontra.api._c[p];
		}
	}
};

var s=document.getElementsByTagName("script");
for(var i=0;i<s.length;i++){
	if(s[i].src && s[i].src=="http://www.procontra-online.de/newsticker/api.js"){
		var p=s[i].parentNode;
		var parent=procontra.ce("div");
		parent.id="procontra_newsticker";
		var params={};
		if(s[i].innerHTML!=""){
			eval("var params="+s[i].innerHTML+";");
		}
		p.appendChild(parent);
		(new procontra.api.Container(parent,params)).create();
	}
}


