var vdl = {
	path:"http://admin.telvi.de/campaigns/vdl",
	portalKey: "",
	portalUrl: "",
	nodeId: "vdl_marktplatz",
	initPortalKey: function(){
		var src = this.findScript();
		if(src != ""){
			var key = src.match(/\?.*key=([a-zA-Z0-9,]*)/);
			this.portalKey = key[1];
			if(this.portalKey != ""){
				if(this.nodeId != "" && document.getElementById(this.nodeId)){
					document.getElementById(this.nodeId).innerHTML = "<div id=\"loader\" style=\"text-align:center;font-weight:bold;height:100px;vertical-align:middle;line-height:100px;\">Lade Artikel</div>";
					this.communicateWithTelvi();
				} else {alert("Die Container ID wurde nicht mit angegeben oder ist nicht vorhanden!");}
			} else {alert("Bitte Überprüfen Sie das Einbindungscript vom Verband Deutscher Lokalzeitungen!");}
		}
	},
	findScript: function(){
		var find = "";
		var scripts = document.getElementsByTagName("script");
			for(i=0;i<scripts.length;i++){
				var s = scripts[i];
				if(s.src && s.src.match(/vdl\/main(.*)\.js(\?.*)?$/)){
					find =  s.src;
				}
			}
		return find;
	},
	communicateWithTelvi: function(){
		var d = document.getElementById(this.nodeId);
		var dim = {
			width:500,
			height:800
		}
		
		if(!d.style.width){d.width = dim.width} else {d.width = d.style.width.replace("px","")}
		if(!d.style.height){d.height = dim.height} else {d.height = d.style.height.replace("px","")}
		
		this.portalUrl = location.host;
		var iframesrc = this.path+"/root.php?key="+this.portalKey+"&url="+this.portalUrl;
//		var iframesrc = "about:blank";
		document.getElementById(this.nodeId).innerHTML += "<iframe style=\"display:none;width:"+d.width+"px;height:"+d.height+"px;overflow-x:auto;\" src=\""+iframesrc+"\" id=\"vdl_frame\" onload=\"vdl.request();\" frameborder=\"0\" scrolling=\"yes\"></style>";
	},
	request : function(){
		document.getElementById("loader").style.display = "none";
		document.getElementById("vdl_frame").style.display = "block";
	}
};
window.setTimeout(function(){
	vdl.initPortalKey();
},500);