var api = {
	pW: 0,
	pH: 0,
	pD: 0,
	defImgH: 800,
	views: [{h:33,b:47},{h:43, b:37}, {h:53,b:27}, {h:73,b:27}],
	dragBox: false,
	browser: false,
	mainPid: 4,

	loadPage: function () {
		if(!api.browserCheck()) return;
		$("staticBorder").style.display = 'none';
		api.pD = api._getDimension("pageBody");
		api.Ajax.loadPanel('getPageBody', "pageBody", api.Ajax.rpc + "&action=getPageBody", 'get');
		this.initPage();
		this.load30d = new Image(100, 100);
		this.load30d.src = "/template/img/load-30d.gif";
		this.load30h = new Image(78, 78);
		this.load30h.src = "/template/img/load-30h.gif";

	},

	initPage: function () {
		window.onresize = api.initResize;
	},

	initResize: function () {
		api.pD = api._getDimension("pageBody");
		api.initLayout();
		var pid = parseInt(api.ImageLine.currImg.pId);
		var node = $('pItem_'+ pid);
		var niD = api._getDimension(node);
		var move = api.Control.pos - (niD.w + niD.l);
		api.ImageLine.cObj.node.style.left = move+"px";
	},

	initLayout: function () {
		api.dragBox.maxLeft = api.pD.w;
		api.dragBox.maxTop = api.pD.h;
		api.ImageLine.update();
		api.ImageLine.click(api.ImageLine.currImg.node, 'start');
		api.ImageLine.declare();
		api.Textbox.init();
	},

	Control: {
		pos: 0,
		zoom: 2,
		init: function (){
			api.Ajax.loadPanel('nothing', "controlPanel", api.Ajax.rpc + "&action=getControlPanel", 'get');
		},
		play: function(act) {
			var pid = parseInt(api.ImageLine.currImg.pId);
			var iid = parseInt(api.ImageLine.currImg.node.getAttribute("rel"));

			switch(act) {
				case '-':
					if(this.zoom == 0) return;
					api.ImageLine.declare();
					this.zoom-=1;
					$('imageLineOuter').style.height = api.views[this.zoom].h +"%";
					$('imageLineOuter').style.bottom = api.views[this.zoom].b +"%";

					api.ImageLine.update();

					var node = $('pItem_'+ pid);
					var niD = api._getDimension(node);
					var move = this.pos - (niD.w + niD.l);
					api.ImageLine.cObj.node.style.left = move+"px";

					if(this.zoom == 0) {
						$('controlMinus').addClassName('controlMinusDisable');
						$('controlMinus').title = "";
					} else if ($('controlPlus').hasClassName('controlPlusDisable')){
						$('controlPlus').removeClassName('controlPlusDisable');
						$('controlPlus').title = "Bilder vergrößern";
					}
					api.ImageLine.declare();
				break;

				case '+':
					if(this.zoom == api.views.length-1) return;
					api.ImageLine.declare();
					this.zoom+=1;
					$('imageLineOuter').style.height = api.views[this.zoom].h +"%";
					$('imageLineOuter').style.bottom = api.views[this.zoom].b +"%";
					api.ImageLine.update();

					var node = $('pItem_'+ pid);
					var niD = api._getDimension(node);
					var move = this.pos - (niD.w + niD.l);
					api.ImageLine.cObj.node.style.left = move+"px";

					if(this.zoom == api.views.length-1) {
						$('controlPlus').addClassName('controlPlusDisable');
						$('controlPlus').title = "";
					} else if($('controlMinus').hasClassName('controlMinusDisable')){
						$('controlMinus').removeClassName('controlMinusDisable');
						$('controlMinus').title = "Bilder verkleinern";
					}
					api.ImageLine.declare();
				break;

				case '<':
					if(api.ImageLine.inAction || pid == '0') return;
					if(api.ImageLine.currImg.node.getAttribute('rel')!='0') {
						window.setTimeout("api.ImageLine.Next.reset('"+ api.ImageLine.currImg.pId +"', 0);", 10);
					}
					api.ImageLine.currImg.node.style.cursor = "pointer";
					var node = $('pItem_'+ (pid-1));
					var move = api.ImageLine.currImg.iD.w;
					api.ImageLine.currImg.node = node;
					api.ImageLine.currImg.pId = pid-1;
					api.ImageLine.inAction = true;
					api.ImageLine.slide(move, 'relative', 'cmd');
				break;

				case '>':
					var nextPid = parseInt(pid) + 1;
					if(api.ImageLine.inAction || nextPid == api.ImageLine.cObj.items) return;
					if(api.ImageLine.currImg.node.getAttribute('rel')!='0') {
						window.setTimeout("api.ImageLine.Next.reset('"+ api.ImageLine.currImg.pId +"', 0);", 100);
					}
					api.ImageLine.currImg.node.style.cursor = "pointer";
					var node = $('pItem_'+ nextPid);
					var niD = api._getDimension(node);
					var move = 0 - niD.w;
					api.ImageLine.currImg.node = node;
					api.ImageLine.currImg.pId = pid+1;
					api.ImageLine.inAction = true;
					api.ImageLine.slide(move, 'relative', 'cmd');
				break;

				case 'dw':
					var imgLineH =  $('imageLineOuter').getHeight();
					var iObj = api.ImageLine.cObj.data[pid]['items'];
					if(!(iid < iObj.length-1)) return;
					cid = iid+1;
					api.ImageLine.Next.start("/img/"+ imgLineH +"/"+ iObj[cid]['pid'] +".jpg", iObj[cid]['img_w']);
					api.ImageLine.currImg.node.setAttribute('rel', cid);
					api.Textbox.load(iObj[cid]['pid']);
				break;

				case 'up':
					var imgLineH =  $('imageLineOuter').getHeight();
					var iObj = api.ImageLine.cObj.data[pid]['items'];
					if(iid == 0) return;
					cid = iid-1;
					api.ImageLine.Next.start("/img/"+ imgLineH +"/"+ iObj[cid]['pid'] +".jpg", iObj[cid]['img_w']);
					api.ImageLine.currImg.node.setAttribute('rel', cid);
					api.Textbox.load(iObj[cid]['pid']);
				break;

				case 'T':
					if($('textPanel').hasClassName('hidden')) {
						$('textPanel').style.top = '';
						$('textPanel').style.left = '0px';
						$('textPanel').style.bottom = '0px';
						$('textPanel').style.width = "50%";
						$('textPanel').style.height = ($('imageFloor').getHeight()+30) +"px";

						$('textPanel').removeClassName('hidden');
						$('controlText').title = "Projekttext ausblenden";
					} else {
						$('textPanel').addClassName('hidden');
						$('controlText').title = "Projekttext einblenden";
					}
					api.Textbox.update();
				break;
			}

			return false;
		}
	},

	ImageLine: {
		viewCDM : false,
		inAction: false,
		cObj: {nodes: Array(), node:false, iD:false, items:0, data:false },
		currImg: {node: false, iD: false, pId: false},
		currPid: 0,
		currSub: 0,

		load: function () {
			var iD = $('imageLineOuter').getDimensions();
			api.Ajax.loadPanel('nothing', "imageLineOuter", api.Ajax.rpc + "&action=getImageLine&h="+ iD.height, 'get');

		},

		init: function (){
			api.Ajax.loadData('ImageDataLoad', api.Ajax.rpc + "&action=getPageData");
		},

		create: function(data) {
			//var imgLineH = Math.ceil(api.pD.h / 100 * 53);
			var imgLineH =  $('imageLineOuter').getHeight();
			var wF = imgLineH / api.defImgH, vW = 0;

			if(!data) return;
			eval("var jsdata = "+ data +";");
			this.cObj.data = jsdata;

			if($('imageLineInner')) { this.update(); return; };

			this.cObj.node = document.createElement("div");
			this.cObj.node.id = "imageLineInner";
			this.cObj.node.style.left = "0px";
			$('imageLineOuter').insert(this.cObj.node);


			for(var i=0; i < jsdata.length; i++){
				var items = jsdata[i].items;
				if(items[0].pid) {
					//var cImg = document.createElement("img");
					var cImg = new Image(Math.ceil(wF * items[0].img_w), imgLineH);
					cImg.src = "/spacer.gif";
					var pid = "pItem_"+ i;
					cImg.setAttribute("rel", '0');
					cImg.id = pid;
					//cImg.alt = this.cObj.data[i].items[0].title;
					cImg.onclick = function() { api.ImageLine.click(this, 'click'); };
					$('imageLineInner').insert(cImg, "after");
					$(pid).addClassName('Loader');
					cImg.src = "/img/"+ imgLineH +"/"+ items[0].pid +".jpg";
					this.cObj.nodes[i] = cImg;
					this.cObj.nodes[i].dataLink = items[0].linkUrl;
					this.cObj.nodes[i].dataPath = items[0].linkUrl.replace('.html','').split('/');
				}
			}
			api.ImageLine.declare();
			this.randomStart();
		},

		randomStart: function() {
			if(this.getCurrentPageId(0)) return;
			var a = Math.round( 2 + (this.cObj.nodes.length-2) * (Math.random()));
			var item = this.cObj.nodes[a];
			this.click(item, 'start');
		},

		getCurrentPageId: function() {
			//console.log("getCurrentPageId by: "+ location.pathname);
			var retValue = false;
			var startBy = 1;
			var urlArr   = location.pathname.replace('.html','').split('/');
			var urlPath  = urlArr[startBy];
			//console.log("Check 1: urlArr.length("+ urlArr.length +") == startBy("+ startBy +")");
			if(urlPath == '' ) return retValue;

			for(var id=0; id < this.cObj.nodes.length; id++) {
				//console.log(urlPath +" = node["+ id +"] = "+ this.cObj.nodes[id].dataPath[startBy]);
				if(urlPath == this.cObj.nodes[id].dataPath[startBy]) {
					var nodePath = this.cObj.nodes[id].dataPath;
					var nodeData = this.cObj.data[id];
					this.click(this.cObj.nodes[id], 'start');
					retValue = true;
				}
			}

			startBy += 1;
			var urlPath  = urlArr[startBy];
			//console.log("Check 2: urlArr.length("+ urlArr.length +") / startBy("+ startBy +")");
			//console.log("Check 2: urlPath("+ urlPath +") / nodePath["+ startBy +"]("+ nodePath[startBy] +")");
			if(urlPath != undefined || urlPath != nodePath[startBy] ) {
				var iObj = nodeData['items'];
				if(iObj.length < 2) return retValue;
				var imgLineH =  $('imageLineOuter').getHeight();

				for(var id=0; id < iObj.length; id++) {
					var dataPath = iObj[id].linkUrl.replace('.html','').split('/')
					if(urlPath == dataPath[startBy]) {
						api.ImageLine.Next.start("/img/"+ imgLineH +"/"+ iObj[id]['pid'] +".jpg", iObj[id]['img_w']);
						api.ImageLine.currImg.node.setAttribute('rel', id);
						if(urlArr[startBy+1] != '') api.Textbox.mainText.load(urlArr[startBy+1])
						else api.Textbox.load(iObj[id]['pid']);
						retValue = true;
					}
				}
			}

			return retValue;

		},

		update:function() {
			var imgLineH = $('imageLineOuter').getHeight();
			var wF = imgLineH / api.defImgH;

			for(i=0; i < this.cObj.nodes.length; i++) {
				var ii = parseInt(this.cObj.nodes[i].getAttribute("rel"));
				var imgName = this.cObj.nodes[i].src.split("/")[5];
				this.cObj.nodes[i].height = imgLineH;
				this.cObj.nodes[i].style.height = imgLineH +"px";
				this.cObj.nodes[i].width = Math.ceil(wF * this.cObj.data[i].items[ii].img_w);
				this.cObj.nodes[i].style.width = Math.ceil(wF * this.cObj.data[i].items[ii].img_w) +'px';
				this.cObj.nodes[i].src = "/img/"+imgLineH+"/"+ imgName;
			}
		},

		declare: function() {
			this.cObj.iD = api._getDimension(this.cObj.node);
			//this.cObj.items = this.cObj.node.childElements().length;
			this.cObj.items = this.cObj.nodes.length;
		},

		click: function (item, from) {

			if(this.currImg['node']) this.currImg['node'].style.cursor = "pointer";
			var item = $(item.id);
			if(!item || (this.inAction && from != 'slide')) return;
			var cmdPanel = $('controlPanel');
			this.currImg['node'] = item;
			this.currImg['iD']   = api._getDimension(item);
			this.currImg['pId']  = item['id'].split("_")[1];
			if(this.currImg['node']) this.currImg['node'].style.cursor = "default";

			api.Control.pos = this.currImg.iD.l + this.currImg.iD.w + this.cObj.iD.l;
			var leftOffset = this.getLeftOffset(this.currImg);

			if( (api.Control.pos > api.pD.w || api.Control.pos < this.currImg.iD.w) && from == 'click') {
				this.inAction = true;
				this.slide(0 - this.currImg.iD.l + leftOffset, 'absolute', 'img');
				return;
			}
			if( (api.Control.pos > api.pD.w || api.Control.pos < this.currImg.iD.w) && from == 'start') {
				this.inAction = true;
				window.setTimeout("api.ImageLine.setLeft("+ (0 - this.currImg.iD.l + leftOffset) +");", 100);
				return;
			}

			cmdPanel.style.left = (api.Control.pos - 78) +"px";
			cmdPanel.removeClassName('hidden');
			this.viewCMD = true;

			if(from == 'slide') this.inAction = false;

			var currPid = this.currImg.pId;
			if($('controlArrowRight') && $('controlArrowRight').hasClassName('controlArrowRightDisable')) {
				$('controlArrowRight').removeClassName('controlArrowRightDisable');
				$('controlArrowRight').title = "Nächstes Thema";
			}
			if($('controlArrowLeft') && $('controlArrowLeft').hasClassName('controlArrowLeftDisable')) {
				$('controlArrowLeft').removeClassName('controlArrowLeftDisable');
				$('controlArrowLeft').title = "Vorheriges Thema";
			}

			if(currPid == 0) {
				$('controlArrowLeft').addClassName('controlArrowLeftDisable');
				$('controlArrowLeft').title = "";
			}else if(currPid == this.cObj.items-1) {
				$('controlArrowRight').addClassName('controlArrowRightDisable');
				$('controlArrowRight').title = "";
			}

			var currImg = parseInt(this.currImg['node'].getAttribute("rel"));
			if($('controlArrowUp') && $('controlArrowUp').hasClassName('controlArrowUpDisable')) {
				$('controlArrowUp').removeClassName('controlArrowUpDisable');
				$('controlArrowUp').title = "Nächstes Bild";
			}
			if($('controlArrowDown') && $('controlArrowDown').hasClassName('controlArrowDownDisable')) {
				$('controlArrowDown').removeClassName('controlArrowDownDisable');
				$('controlArrowDown').title = "Vorheriges Bild";
			}
			if(currImg == 0 && $('controlArrowDown')) {
				$('controlArrowDown').addClassName('controlArrowDownDisable');
				$('controlArrowDown').title = "";
			} else if (!(currImg < this.cObj.data[currPid]['items'].length-1) && $('controlArrowUp')) {
				$('controlArrowUp').addClassName('controlArrowUpDisable');
				$('controlArrowUp').title = "";
			}

			if (this.cObj.data[currPid]['items'].length == 1) {
				$('controlArrowUp').addClassName('controlArrowUpDisable');
				$('controlArrowUp').title = "";
			}

			$('controlPDF').href = this.cObj.data[currPid]['items'][currImg]['pdfUrl'];
			api.Textbox.load(this.cObj.data[currPid]['items'][currImg]['pid']);
			//alert("Thema: "+ currPid +" Bild: "+ currImg);
		},

		slide: function(to, art, from) {
			//alert("Slide To "+ to);
			if(api.browser != 'msie'){
				new Effect.Move('imageLineInner', { duration:1.0, x:to, y:0, mode:art, afterFinish:function(){
					api.ImageLine.declare();
					api.ImageLine.click(api.ImageLine.currImg.node, 'slide');
				}});
			} else {
				if(art == "relative") to = parseInt($('imageLineInner').style.left) + to;
				$('imageLineInner').style.left = to + "px";
				api.ImageLine.declare();
				api.ImageLine.click(api.ImageLine.currImg.node, 'slide');
			}
		},
		setLeft: function(to) {
			$('imageLineInner').style.left = to +"px";
			api.ImageLine.declare();
			api.ImageLine.click(api.ImageLine.currImg.node, 'slide');
		},

		Next: {
			NewImg: false,

			start: function(imgUrl, W) {
				this.imgH = api.ImageLine.currImg.node.getHeight();
				this.imgW = api.ImageLine.currImg.node.getWidth();

				var wF = this.imgH / api.defImgH;
				this.newW = Math.ceil(wF * W);
				//api.ImageLine.currImg.node.addClassName("Loader");

				this.margW = this.imgW - this.newW;
				api.ImageLine.currImg.node.src = "/spacer.gif";

				api.ImageLine.Next.moved=true;


				if(this.newW != this.imgW) {
					if(api.browser != 'msie'){
						new Effect.Parallel([
  							new Effect.Move('imageLineInner', { sync:true, x:this.margW, y:0, mode:'relative'}),
 							new Effect.Morph(api.ImageLine.currImg.node, {sync: true, style: 'width:'+this.newW +'px'})
							], {duration: 1.0, afterFinish:function(){api.ImageLine.Next.end(api.ImageLine.Next.imgW);}}
						);
					} else {
						$('imageLineInner').style.left = parseInt($('imageLineInner').style.left) + this.margW + 'px';
						api.ImageLine.currImg.node.style.width = this.newW +'px';
						api.ImageLine.Next.end(api.ImageLine.Next.imgW);
					}
				} else {
					api.ImageLine.Next.end();
				}
				this.NewImg = new Image(this.imgW, this.imgH);
				this.NewImg.src = imgUrl;
			},

			reset: function(pid, cid) {
				if(api.ImageLine.inAction){
					window.setTimeout("api.ImageLine.Next.reset('"+ pid +"', 0);", 100);
					return;
				}
				var oid = api.ImageLine.currImg.pId;
				var nObj = $('pItem_'+ pid);
				var dObj = api.ImageLine.cObj.data[pid]['items'][0];
				var W = dObj['img_w'];
				var imgH = nObj.getHeight(), imgW = nObj.getWidth();
				var imgUrl = "/img/"+ imgH +"/"+ dObj['pid'] +".jpg";
				var wF = imgH / api.defImgH;
				var newW = Math.ceil(wF * W);
				var margW = imgW - newW;
				//alert(oid + "/" + pid +" / "+ cid +" = "+ dObj['pid'] );
				var cLeft = parseInt($('imageLineInner').style.left);
				var nLeft = cLeft + margW;
				if(parseInt(oid) > parseInt(pid)) $('imageLineInner').style.left = nLeft + 'px';
				nObj.style.width = newW +'px';
				nObj.src = imgUrl
				nObj.setAttribute('rel', cid);
			},

			end: function(w) {
				if(this.NewImg.complete == true) {
					//api.ImageLine.currImg.node.removeClassName("Loader");
					api.ImageLine.currImg.node.src = this.NewImg.src;
					this.NewImg = false;
					api.ImageLine.declare();
					api.ImageLine.click(api.ImageLine.currImg.node, 'slide');
				} else {
					window.setTimeout('api.ImageLine.Next.end()', 100);
				}
			}
		},

		getLeftOffset: function(node) {
			return (api.pD.w / 2) - (node.iD.w / 2);
		}
	},

	Textbox: {
		currPid: false,
		zoom: 1,
		views: [{fs:11,lh:12},{fs:12, lh:14}, {fs:14, lh:16}, {fs:16, lh:18}],
		loading: '<table width="100%" height="100%" border="0"><tr valign="middle"><td align="center" style="font-size:16px; color:#fff;"><img src="/template/img/load-30h.gif" width="30" height="30" border="0" align="absmiddle" style="width:30px; height:30px; margin-right:10px;" /> Loading ...</td></tr></table>',
		titleHeight: 30,

		init: function() {
			var tD = api._getDimension('textPanel');
			var fD = api._getDimension('imageFloor');

			if($('textPanel').style.top != '') {
				if(tD.t + tD.h > api.pD.h) $('textPanel').style.top = (api.pD.h - tD.h) + "px";
				if(tD.l + tD.w > api.pD.w) $('textPanel').style.left = (api.pD.w - tD.w) + "px";
			} else {
				var tBoxH = $('imageFloor').getHeight() + 30;
				$('textPanel').style.height = (tBoxH) +"px";
			}

		},

		load: function(pid) {
			if(pid == 1010 || pid == 1020) {
				api.Textbox.currPid = pid;
				if($('controlPDF')) $('controlPDF').addClassName('hidden');
				this.mainText.init();
				return;
			} else if ($('controlPDF') && $('controlPDF').hasClassName('hidden')) {
				$('controlPDF').removeClassName('hidden');
			}
			api.Textbox.mainText.currPid = '';
			var tBox = $('textPanel');
			if(api.Textbox.currPid == pid || tBox.hasClassName('hidden')) return;
			$('textPanel').update(this.loading);
			api.Ajax.loadPanel('getTextBody', 'textPanel', api.Ajax.rpc + "&action=getTextBody&pid="+pid, 'get');
			api.Textbox.currPid = pid;
		},

		declare: function() {
			this.titleHeight = 30;
			if(api.ImageLine.currImg['pId'] == api.mainPid) this.titleHeight = 60;

			api.dragBox = new DragResize('dragresize', { minWidth:350, minHeight:150, minLeft: 0, minTop: 0, maxLeft: api.pD.w, maxTop: api.pD.h });
			api.dragBox.isElement = function(elm) { if (elm.className && elm.className.indexOf('drsElement') > -1) return true; };
			api.dragBox.isHandle = function(elm) { if (elm.className && elm.className.indexOf('drsMoveHandle') > -1) return true; };
			api.dragBox.ondragstart = function(isResize) { };
			api.dragBox.ondragmove = function(isResize) { };
			api.dragBox.ondragend = function(isResize) {
				api.Textbox.Scroll.destroy();
				api.Textbox.Scroll.init();
				if(api.browser == 'msie'){
					$('tdText').style.height = ($('textPanel').getHeight() - api.Textbox.titleHeight) +"px";
					$('textPanelTitle').style.width = ($('textPanel').getWidth() - 80) +"px";
				}
			};
			api.dragBox.ondragblur = function() { };
			api.dragBox.apply(document);

			if(api.browser == 'msie'){
				$('tdText').style.height = ($('textPanel').getHeight() - api.Textbox.titleHeight) +"px";
			}
		},


		update: function() {
			this.Scroll.destroy();
			if($('textPanelTitle')) {
				$('textPanelTitle').style.fontSize = this.views[this.zoom].fs + "px";
				$('textPanelTitle').style.lineHeight = this.views[this.zoom].lh + "px";
			}
			if($('textPanelText')) {
				$('textPanelText').style.fontSize = this.views[this.zoom].fs + "px";
				$('textPanelText').style.lineHeight = this.views[this.zoom].lh + "px";
			}
			this.declare();
			this.Scroll.init();
		},

		play: function(act) {
			switch(act){
				case 'x': api.Control.play('T'); break;
				case '+':
					if(!(this.zoom < this.views.length-1)) return;
					this.zoom++;
					this.update();
				break;
				case '-':
					if(this.zoom == 0) return;
					this.zoom--;
					this.update();
				break;
			}
		},
		mainText: {
			currIid: '',
			currPid: '',

			init: function() {
				if(this.currPid != '') return;
				api.Textbox.mainText.load('bueroprofil');
			},

			load: function(pid) {
				var tBox = $('textPanel');
				if(this.currPid && (this.currPid == pid || tBox.hasClassName('hidden'))) return;
				$('textPanel').update(api.Textbox.loading);
				api.Ajax.loadPanel('getTextBody', 'textPanel', api.Ajax.rpc + "&action=getTextBodyMain&pid="+ pid, 'get');
				this.currPid = pid;
			}

		},

		Scroll: {
			cObj: {'DIV': false, 'BAR': false, 'TWE': false},

			init: function () {

				var objCo = $("TextOuter");
				var objCi = $("TextInner");
				var objCiH = objCi.getHeight();
				var objCoW = objCo.getWidth();
				var objCoH = objCo.getHeight();
				//alert(objCoW +"x"+ objCoH);

				if( objCiH <= objCoH) {
					//alert(objCi.style.top);
					if(parseInt(objCi.style.top != 0)) objCi.style.top = "0px";
					return;
				}
				if(!$("cmdScrollContainer")) this.create();

				var objBar = $("cmdScrollContainer");

				api.Textbox.Scroll.cObj['DIV'] = new Scrolling.Scroller(objCo, objCoW, objCoH);
				//api.Textbox.Scroll.cObj['BAR'] = new Scrolling.Scrollbar(objBar, api.Textbox.Scroll.cObj['DIV'], new Scrolling.ScrollTween());
				//api.Textbox.Scroll.cObj['TWE'] = new Scrolling.ScrollTween(api.Textbox.Scroll.cObj['BAR'], false);
  				this.cObj['TWE'].stepDelay = 54;
			},

			create: function() {
				var node = $("cmdScroll");
				var divSC = document.createElement("div"); divSC.id = "cmdScrollContainer"; api.addClass(divSC, "ScrollBarContainer");
				var divST = document.createElement("div"); api.addClass(divST, "Scrollbar-Track");

				var step  = api.browser == 'msie' ? 20 : 10;
				var imgUP = document.createElement("img"); imgUP.src = "/spacer.gif"; imgUP.title="Text nach oben";  imgUP.height = 20; imgUP.width = 20; api.addClass(imgUP, "Scrollbar-Up"); imgUP.onmousedown = function() {api.Textbox.Scroll.cObj['DIV'].startScroll(0, 0-step);}; imgUP.onmouseup = function() {api.Textbox.Scroll.cObj['DIV'].stopScroll();};
				var imgDW = document.createElement("img"); imgDW.src = "/spacer.gif"; imgDW.title="Text nach unten"; imgDW.height = 20; imgDW.width = 20; api.addClass(imgDW, "Scrollbar-Down"); imgDW.onmousedown = function() {api.Textbox.Scroll.cObj['DIV'].startScroll(0, step);}; imgDW.onmouseup = function() {api.Textbox.Scroll.cObj['DIV'].stopScroll();};
				var imgHD = document.createElement("img"); imgHD.src = "/spacer.gif"; imgHD.setAttribute("height", 20); imgHD.setAttribute("width", 20); api.addClass(imgHD, "Scrollbar-Handle");

				divST.appendChild(imgHD);
				divSC.appendChild(imgUP);
				divSC.appendChild(imgDW);
				divSC.appendChild(divST);
				node.appendChild(divSC);
			},

			destroy: function() {
				var node = $("cmdScroll");
				var divSC = $("cmdScrollContainer");
				if(!divSC) return;
				node.removeChild(divSC);
			}
		}
	},

	Logo: {
		status: 0,
		click: function (node) {
			api.ImageLine.click(api.ImageLine.cObj.nodes[api.mainPid], 'click');
			return false;
			var to = this.status ? 170 : -170;
			this.status = this.status ? 0 : 1;
			new Effect.Move(node, { duration:1.0, x:0, y:to, mode:'relative', afterFinish:function(){api.Logo.declare(node);}});
		},
		declare: function(node) {

		}
 	},
	_getDimension: function (obj) {
		if(typeof(obj) != "object") obj = $(obj);
		if(!obj) return {'h': 0, 'w': 0, 't': 0, 'l': 0};
		var offset = Element.positionedOffset(obj);
		//alert(Element.getWidth(obj) +"x"+ Element.getHeight(obj) +" Top:"+ offset.top + " Left:" +offset.left);
		return {'h': Element.getHeight(obj), 'w': Element.getWidth(obj), 't': offset.top, 'l': offset.left};
	},

	_getWinSize: function() {
		if (navigator.appName.indexOf('Netscape') != -1) { api.pW = self.innerWidth; api.pH = self.innerHeight}
		else if (navigator.appName.indexOf('Microsoft') != -1) { api.pW = document.body.clientWidth; api.pH = document.body.clientHeight };
	},

	hasClass: function(node, classStr){
		if(typeof(node) != "object") node = $(node);
		if(!node) return;
		return ((" "+$(node).className+" ").indexOf(" "+classStr+" ") >= 0);
	},

	addClass: function(node, classStr){
		if(typeof(node) != "object") node = $(node);
		if(!node) return;
		node = $(node);
		var cls = node.className;
		if((" "+cls+" ").indexOf(" "+classStr+" ") < 0){
			node.className = cls + (cls ? ' ' : '') + classStr;
		}
	},

	removeClass: function(node, classStr) {
		if(typeof(node) != "object") node = $(node);
		if(!node) return;
		var t = api.trim((" " + node.className + " ").replace(" " + classStr + " ", " "));
		if(node.className != t){ node.className = t; }
	},

	trim: function(str){
		return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');	// String
	},

	browserCheck: function () {
		//alert("Browser Check");
		if (!window.RegExp) return false;
		var agentStr = false;
		var AGENTS = ["opera","msie","safari","firefox","netscape","mozilla"];
		var agent  = navigator.userAgent.toLowerCase();
		var browser = navigator.appName.toLowerCase();
		for (var i = 0; i < AGENTS.length; i++) {
			agentStr = AGENTS[i];
			api.browser = agentStr;
			if (agent.indexOf(agentStr) != -1) {
				var versionExpr = new RegExp(agentStr + "[ \/]?([0-9]+(\.[0-9]+)?)");
				if (versionExpr.exec(agent) != null) {
					version = parseFloat(RegExp.$1);
				};
				//alert("Browser: "+ agentStr +" Version: "+ version +" Name: "+ navigator.appName +" Code: "+ navigator.appCodeName);
				if (agentStr == "opera") return version >= 8.0;
				if (agentStr == "safari") return version >= 125;
				if (agentStr == "msie") return (version >= 6.0 && agent.indexOf("powerpc") == -1);
				if (agentStr == "netscape") return version > 7.1;
				if (agentStr == "firefox") return version >= 2.0;
				if (browser  == "konqueror") return version >= 5.5;
			};
		};
		return !!document.getElementById;
	},

	Ajax: {
		rpc: "/index.php?mod=Ajax",
		nObj: {Year: false, Top: false, Sub: false},
		anchor: false,
		curr: {tPid:0, sPid:0},

		init: function () {
			api.ImageLine.init();
			api.Control.init();
			api.Textbox.init();
		},

		Forms: {
			init: function(name) {
				if($(name)) {
					$(name).action = api.Ajax.rpc + "&action=getPageImage&pid="+ api.Ajax.nObj.Sub.curr.pid;
					$(name).onsubmit = function() { api.Ajax.Forms.send(name); return false; };
				}
			},

			send: function(name) {
				$(name).serialize(true)
				api.Ajax.loadPanel('loadedSubContent', "subContent", api.Ajax.rpc + "&action=getPageImage&pid="+ api.Ajax.nObj.Sub.curr.pid, 'post', $(name).serialize(true));
				return false;
			}
		},

		loadPanel: function (type, node, url, rqMethod, param) {
			if(typeof(node) != "object") node = $(node);
			if(!node) return;
			url += '&dy=' + Math.random();
			if(rqMethod == 'post') {
				new Ajax.Updater(node, url, { parameters: param, method: 'post', evalScripts: true, onComplete: function(){ api.Ajax.afterLoad(type);} });
			} else {
				new Ajax.Updater(node, url, { method: 'get', evalScripts: true, onComplete: function(){ api.Ajax.afterLoad(type);} });
			}
		},

		loadData: function (type, url){
			url += '&dy=' + Math.random();
			new Ajax.Request(url, {method: 'get', onSuccess: function(transport) { api.Ajax.afterLoad(type, transport.responseText); }});
		},

		afterLoad: function (type, data) {
			switch (type) {
				case "getPageBody"     : api.Ajax.init(); break;
				case "ImageLineLoaded" : api.ImageLine.declare(); break;
				case "ImageDataLoad"   : api.ImageLine.create(data); break;
				case "getTextBody"     : api.Textbox.update(); break;
			}
		}
	}
};



var mEvent = {
    add: function(obj, etype, fp, cap) {
        cap = cap || false;
        if (obj.addEventListener) obj.addEventListener(etype, fp, cap);
        else if (obj.attachEvent) obj.attachEvent("on" + etype, fp);
    },

    remove: function(obj, etype, fp, cap) {
        cap = cap || false;
        if (obj.removeEventListener) obj.removeEventListener(etype, fp, cap);
        else if (obj.detachEvent) obj.detachEvent("on" + etype, fp);
    },

    DOMit: function(e) {
        e = e? e: window.event;
        if (!e.target) e.target = e.srcElement;
        if (!e.preventDefault) e.preventDefault = function () { e.returnValue = false; return false; }
        if (!e.stopPropagation) e.stopPropagation = function () { e.cancelBubble = true; }
        return e;
    },

    getTarget: function(e) {
        e = mEvent.DOMit(e); var tgt = e.target;
        if (tgt.nodeType != 1) tgt = tgt.parentNode;
        return tgt;
    }

}

var mPlayer = {
	init: function (node, type, file) {
		var h = type == 'Video' ? 300 : 20;
		var so = new SWFObject('/mediaFiles/mplayer.swf', node+'MP', 360, h, 7);
		so.addParam('allowscriptaccess','always');
		so.addParam('allowfullscreen','false');
		so.addParam("wmode", "opaque");
		so.addParam('flashvars','&file='+ file +'&volume=50&autostart=false');
		so.write(node);
	}
};

//window.onload = api.loadPage;

