function initialiseVideoBox(startParam) {
	containerId = profilePage.getContainerForApp(startParam);
	if(containerId) {
		var videoBox = new VideoBoxClass();
		videoBox.id = containerId;
		videoBox.param = startParam;
		
		appManagerId = appManager.runApp(startParam, videoBox);
		
		videoBox.name = 'appManager.runningApps["' + startParam + '"]';
		appManager.runningApps[startParam].init();
	}
}

function VideoBoxClass() {
	var addVideoAppReady = false;
	var addVideoAppNeeded = false;
	var videos = false;
	var currentPage = 1;
	var maxPageCounter = 1;
	var currentVideo = 'none';
	var isEditable = false;
	
	
	this.init = function() {
		if(!this.title) {
			this.title = '<span class="darkerGreen">Meine</span> Videos...';
		}
			
		this.box = document.getElementById(this.id);
		this.buildContainer();

		this.addVideoEventHandler = new this.addVideoEventHandlerClass();
		this.addVideoEventHandler.name = this.name + '.addVideoEventHandler';
		this.addVideoEventHandler.eventHandler = this;

		var output = new Object();
		
		if(!this.objectId && !this.objectType) {
			this.addVideoEventHandler.boxId = this.param;	
						
			output.objectType = 'user';
			output.objectId = profilePageUserId;
		} else {
			output.objectType =  this.objectType;
			output.objectId = this.objectId;			
		}
		
		this.addVideoEventHandler.objectType = output.objectType;
		this.addVideoEventHandler.objectId = output.objectId;		
		
		outputString = JSONstring.make(output);
		
		jsonPostData('jsApi/videos/get/videosForObject', escape(outputString), this.name + '.displayVideo');		
		
	}
	
	this.addVideoComplete = function() {
		this.init();
	}
	
	this.displayVideo = function(Object) {
		var displayErrorMessage = true;

		if(Object) {
			
			if(Object["isEditable"]) {
				isEditable = true;
				document.getElementById(this.id + 'headerOptions').style.display = 'block';
			}	
					
			if(Object["status"]) {
				if(Object["status"]=='ok') {
					if(Object["videos"]) {
						if(Object["videos"].length > 0) {
							videos = Object["videos"];
							maxPageCounter = Math.ceil(videos.length / 5);
														
							for(vidCnt = 0; vidCnt < Object["videos"].length; vidCnt++) {
								videoThumbnailContainer = document.createElement("DIV");
								videoThumbnailContainer.id = this.id + 'vThumb' + vidCnt;
								videoThumbnailContainer.className = 'videoThumbnailContainer';
								eval("videoThumbnailContainer.onmouseover = function(event) { this.className = 'videoThumbnailContainer selected'; mousePointerLabel.display(event, '" + Object["videos"][vidCnt]["Title"] + "'); };");
								eval("videoThumbnailContainer.onmouseout = function() { if(currentVideo != " + vidCnt + ") { this.className = 'videoThumbnailContainer'; } mousePointerLabel.clear(); };");
								eval("videoThumbnailContainer.onclick = function() { " + this.name + ".showVideo(" + vidCnt + "); };");
																								
								videoThumbnail = document.createElement("IMG");
								videoThumbnail.src = Object["videos"][vidCnt]["ThumbnailPath"];
								videoThumbnail.className = 'videoThumbnail';
								
								videoPlayButton = document.createElement("IMG");
								videoPlayButton.src = '/images/style/icons/videos/whitePlayButton.gif';
								videoPlayButton.className = 'videoPlayButton';
								
								videoThumbnailContainer.appendChild(videoThumbnail);
								videoThumbnailContainer.appendChild(videoPlayButton);		
								
								document.getElementById(this.id + 'innerVideoScrollContainer').appendChild(videoThumbnailContainer);
							}
							
							displayErrorMessage = false;
						}
					}
				}
				this.refreshScrollButtons();
			}
		}
		
		if(displayErrorMessage) {
			if(!isEditable && this.hideIfEmpty) {
				document.getElementById(this.id).style.display = 'none';			
			}
			
			document.getElementById(this.id + 'videoBox').innerHTML = '';
			
			var noVideosMessageContainer = document.createElement("DIV");
			noVideosMessageContainer.className = 'noVideosMessageContainer';
			
			var noVideosIcon = document.createElement("IMG");
			noVideosIcon.className = 'noVideosIcon';
			noVideosIcon.src = '/images/style/icons/videosOnBright.gif';
		
			var noVideosMessage = document.createElement("DIV");
			noVideosMessage.id = this.id + 'noVideosMessage';
			noVideosMessage.className = 'noVideosMessage';
			noVideosMessage.innerHTML = 'Hier wurde noch kein Video hinzugef&uuml;gt.';	
					
			noVideosMessageContainer.appendChild(noVideosIcon);
			noVideosMessageContainer.appendChild(noVideosMessage);
					
			document.getElementById(this.id + 'videoBox').appendChild(noVideosMessageContainer);		
		}	
	}

	this.refreshScrollButtons = function() {
		if(currentPage > 1) {
			document.getElementById(this.id + 'scrollLeftButton').className = 'scrollButton left';
		} else {
			document.getElementById(this.id + 'scrollLeftButton').className = 'scrollButton left inactive';		
		}
		
		if(currentPage < maxPageCounter) {
			document.getElementById(this.id + 'scrollRightButton').className = 'scrollButton right';
		} else {
			document.getElementById(this.id + 'scrollRightButton').className = 'scrollButton right inactive';		
		}		
	}

	this.nextPage = function() {
		if(currentPage < maxPageCounter) {
			currentPage++;
			
			var leftPos = ((currentPage - 1) * - 650); 
			
			startMoveBoxEffect(document.getElementById(this.id + 'innerVideoScrollContainer'), 'left', leftPos, 35, false);				
			
			this.refreshScrollButtons();
		}
	}
	
	this.previousPage = function() {
		if(currentPage > 1) {
			currentPage--;
			
			var leftPos = ((currentPage - 1) * - 650); 
			
			startMoveBoxEffect(document.getElementById(this.id + 'innerVideoScrollContainer'), 'right', leftPos, 35, false);	
						
			this.refreshScrollButtons();
		}
	}

	this.showVideo = function(id) {
		if(currentVideo == id) {
			this.hideVideo();
		} else {
			startChangeBoxSizeEffect(document.getElementById(this.id + 'videoBox'), 'increaseHeight', 625, 60, this.name + '.showVideoInt(' + id + ')');			
			currentVideo = id;
		}
	}
	
	this.showVideoInt = function(id) {
		document.getElementById(this.id + 'vThumb' + currentVideo).className = 'videoThumbnailContainer';
		document.getElementById(this.id + 'vThumb' + id).className = 'videoThumbnailContainer active';
		
		currentVideo = id;
		
		if(currentVideo > 0) {
			document.getElementById(this.id + 'prevVideoIcon').className = 'videoNavIcon prev';
		} else {
			document.getElementById(this.id + 'prevVideoIcon').className = 'videoNavIcon prev inactive';			
		}
		
		if(currentVideo < videos.length - 1) {
			document.getElementById(this.id + 'nextVideoIcon').className = 'videoNavIcon next';
		} else {
			document.getElementById(this.id + 'nextVideoIcon').className = 'videoNavIcon next inactive';			
		}		
		
		document.getElementById(this.id + 'videoOptions').style.display = 'block';	
		document.getElementById(this.id + 'videoContainer').innerHTML = videos[id]["EmbedString"];
		
		document.getElementById(this.id + 'videoTitle').innerHTML = videos[id]["Title"];

		if(isEditable) {
			document.getElementById(this.id + 'deleteVideoContainer').style.display = 'block';
		} else {
			document.getElementById(this.id + 'deleteVideoContainer').style.display = 'none';
		}
	}
	
	this.prevVideo = function() {
		if(currentVideo > 0) {
			this.showVideoInt(currentVideo - 1);
		}
		
		if(Math.ceil((currentVideo + 1) / 4) < currentPage) {
			this.previousPage();			
		}
	}
	
	this.nextVideo = function() {
		if(currentVideo < videos.length - 1) {
			this.showVideoInt(currentVideo + 1);
		}
		
		if(Math.ceil((currentVideo +1 ) / 4) > currentPage) {
			this.nextPage();			
		}		
	}	
	
	this.shareVideo = function() {
		this.postVideoWindow = new MessageWindowClass();
		this.postVideoWindow.name = this.name + '.postVideoWindow';
		this.postVideoWindow.className = 'eventCreatorMessageWindow';
		this.postVideoWindow.title = 'Video posten?';
		this.postVideoWindow.message = 'M&ouml;chtest du das Video auf deinem Profil posten?';
		this.postVideoWindow.defaultValue = 'Auf Profil Posten';
		this.postVideoWindow.displayCancelButton = true;
		this.postVideoWindow.call = this.name + '.shareVideoInt()';
		this.postVideoWindow.displayCurtain = false;
		this.postVideoWindow.display();		
	}
	
	this.shareVideoInt = function() {
		if(currentVideo!='none') {
			document.location.href='/share/?shareVideoId=' + videos[currentVideo]["PublicID"];
		}		
	}
	
	this.reportVideo = function() {
		if(currentVideo!='none') {
			document.location.href='/reports/send.php?type=video&id=' + videos[currentVideo]["PublicID"];
		}
	}
	
	this.hideVideo = function() {
		document.getElementById(this.id + 'vThumb' + currentVideo).className = 'videoThumbnailContainer';
		
		startChangeBoxSizeEffect(document.getElementById(this.id + 'videoBox'), 'decreaseHeight', 115, 35, this.name + '.hideVideoInt()');			
		currentVideo = 'none';
	}
	
	this.hideVideoInt = function() {
		document.getElementById(this.id + 'videoOptions').style.display = 'none';
		document.getElementById(this.id + 'videoContainer').innerHTML = '';	
	}	

	this.addVideo = function() {
		appManager.addApp('ADDVIDEOAPP', false, this.name + '.addVideoInt');
		
		if(addVideoAppReady) {
			this.addVideoApp = new AddVideoAppClass();
			this.addVideoApp.id = this.id + 'addVideoApp';
			this.addVideoApp.name = this.name + '.addVideoApp';
			this.addVideoApp.eventHandler = this.addVideoEventHandler;
			this.addVideoApp.init();		
			this.addVideoApp.show();
		} else {
			appManager.startApp('ADDVIDEOAPP');		
			addVideoAppNeeded = true;
		}
	}
	
	this.addVideoInt = function() {
		addVideoAppReady = true;
		
		if(addVideoAppNeeded) {
			this.addVideo();
		}
	}
	
	this.addVideoEventHandlerClass = function() {
		this.addVideoComplete = function(videoId) {
			
			var output = new Object();
			output.videoId = videoId;
			
			if(!this.objectId && !this.objectType) {		
				output.objectType = 'user';
				output.objectId = profilePageUserId;				
			} else {
				output.objectType = this.objectType;
				output.objectId = this.objectId;
			}
			
			outputString = JSONstring.make(output);								
			
			jsonPostData('jsApi/videos/add/videoToObject', escape(outputString), this.name + '.addVideoInt');		
		}
		
		this.addVideoInt = function() {
			this.eventHandler.addVideoComplete();
		}
	}	

	this.deleteVideo = function() {
		this.deleteVideoWindow = new MessageWindowClass();
		this.deleteVideoWindow.name = this.name + '.deleteVideoWindow';
		this.deleteVideoWindow.className = 'eventCreatorMessageWindow';
		this.deleteVideoWindow.title = 'Wirklich l&ouml;schen?';
		this.deleteVideoWindow.message = 'M&ouml;chtest du das Video wirklich l&ouml;schen?';
		this.deleteVideoWindow.defaultValue = 'L' + String.fromCharCode(246) + 'schen';
		this.deleteVideoWindow.displayCancelButton = true;
		this.deleteVideoWindow.call = this.name + '.deleteVideoInt()';
		this.deleteVideoWindow.displayCurtain = false;
		this.deleteVideoWindow.display();		
	}	
	
	this.deleteVideoInt = function() {
		if(currentVideo!='none') {
			id = currentVideo;
			
			var output = new Object();
			output.videoId = videos[id]["PublicID"];
						
			outputString = JSONstring.make(output);
	
			jsonPostData('jsApi/videos/delete/video', escape(outputString), this.name + '.deleteVideoIntInt');
		}
	}

	this.deleteVideoIntInt = function() {
		this.init();
	}

	this.likeVideo = function() {
		this.likeVideoWindow = new MessageWindowClass();
		this.likeVideoWindow.name = this.name + '.likeVideoWindow';
		this.likeVideoWindow.className = 'eventCreatorMessageWindow';
		this.likeVideoWindow.title = 'Zu Favoriten hinzuf&uuml;gen?';
		this.likeVideoWindow.message = 'M&ouml;chtest du das Video zu deinen Favoriten hinzuf&uuml;gen?';
		this.likeVideoWindow.defaultValue = 'Hinzuf' + String.fromCharCode(252) + 'gen';
		this.likeVideoWindow.displayCancelButton = true;
		this.likeVideoWindow.call = this.name + '.likeVideoInt()';
		this.likeVideoWindow.displayCurtain = false;
		this.likeVideoWindow.display();		
	}	
	
	this.likeVideoInt = function() {
		if(currentVideo!='none') {
			id = currentVideo;
			
			var output = new Object();
			output.objectType = 'video';
			output.objectId = videos[id]["PublicID"];
						
			outputString = JSONstring.make(output);
	
			jsonPostData('jsApi/favorites/add', escape(outputString), '');
		}
	}

	this.buildContainer = function() {
		this.box.innerHTML = '';
		
		this.box.className = this.box.className + ' bright videoBoxApp';
		
		var header = document.createElement("DIV");
		header.className = 'header';
		header.id = this.id + 'header';
		
		var title = document.createElement("DIV");
		title.id = this.id + 'title';
		title.innerHTML = this.title;
		
		var headerOptions = document.createElement("DIV");
		headerOptions.id = this.id + 'headerOptions';
		headerOptions.className = 'headerOptions';
		headerOptions.innerHTML = '<li><a href="Javascript: ' + escape(this.name) + '.addVideo();">Video hinzuf&uuml;gen</a></li>';
		headerOptions.style.display = 'none';
		
		header.appendChild(title);
		header.appendChild(headerOptions);
		
		var videoBox = document.createElement("DIV");
		videoBox.id = this.id + 'videoBox';
		videoBox.className = 'body videoBox';
		videoBox.style.padding = '0px';
		videoBox.style.height = '117px';
				
		var scrollLeftButton = document.createElement("DIV");
		scrollLeftButton.id = this.id + 'scrollLeftButton';
		scrollLeftButton.className = 'scrollLeftButton inactive';
		scrollLeftButton.innerHTML = '<img src="/images/style/arrows/greyArrowLeftActive.gif" />';
		eval("scrollLeftButton.onclick = function() { " + this.name + ".previousPage(); };");
				
		var scrollRightButton = document.createElement("DIV");
		scrollRightButton.id = this.id + 'scrollRightButton';
		scrollRightButton.className = 'scrollRightButton inactive';
		scrollRightButton.innerHTML = '<img src="/images/style/arrows/greyArrowRightActive.gif" />';		
		eval("scrollRightButton.onclick = function() { " + this.name + ".nextPage(); };");	
				
		var outerVideoScrollContainer = document.createElement("DIV");
		outerVideoScrollContainer.id = this.id + 'outerVideoScrollContainer';
		outerVideoScrollContainer.className = 'outerVideoScrollContainer';
		
		var innerVideoScrollContainer = document.createElement("DIV");
		innerVideoScrollContainer.id = this.id + 'innerVideoScrollContainer';
		innerVideoScrollContainer.className = 'innerVideoScrollContainer';
		
		outerVideoScrollContainer.appendChild(innerVideoScrollContainer);
	
		var videoHeader = document.createElement("DIV");
		videoHeader.id = this.id + 'videoHeader';
		videoHeader.className = 'videoHeader';		

		var videoContainer = document.createElement("DIV");
		videoContainer.id = this.id + 'videoContainer';
		videoContainer.className = 'videoContainer';	
		
		var videoOptions = document.createElement("DIV");
		videoOptions.id = this.id + 'videoOptions';
		videoOptions.className = 'videoOptions';				
		
		var videoTitle = document.createElement("DIV");
		videoTitle.id = this.id + 'videoTitle';
		videoTitle.className = 'videoTitle';
		
		var videoHeaderSelector = document.createElement("DIV");
		videoHeaderSelector.className = 'headerSelector';
		
		var videoCloseLink = document.createElement("DIV");
		videoCloseLink.className = 'selectorEntry single';
		videoCloseLink.innerHTML = 'Video ausblenden';
		eval("videoCloseLink.onclick = function() { " + this.name + ".hideVideo(); }; ");
		
		videoHeaderSelector.appendChild(videoCloseLink);
		
		videoHeader.appendChild(videoTitle);
		videoHeader.appendChild(videoHeaderSelector);			
		
		var shareVideoContainer = document.createElement("DIV");
		shareVideoContainer.className = 'videoOptionContainer';
		eval("shareVideoContainer.onclick = function() { " + this.name + ".shareVideo(); }; ");
		
		var shareVideoIcon = document.createElement("IMG");
		shareVideoIcon.src = '/images/style/icons/videos/shareVideo.gif';
		shareVideoIcon.style.marginTop = '2px';
		
		var shareVideoLabel = document.createElement("DIV");
		shareVideoLabel.className = 'videoOptionText';
		shareVideoLabel.innerHTML = 'Video teilen';
		
		shareVideoContainer.appendChild(shareVideoIcon);
		shareVideoContainer.appendChild(shareVideoLabel);	

		var likeVideoContainer = document.createElement("DIV");
		likeVideoContainer.className = 'videoOptionContainer';
		eval("likeVideoContainer.onclick = function() { " + this.name + ".likeVideo(); }; ");
		
		var likeVideoIcon = document.createElement("IMG");
		likeVideoIcon.src = '/images/style/icons/videos/loveIcon.gif';
		likeVideoIcon.style.marginTop = '2px';
		
		var likeVideoText = document.createElement("DIV");
		likeVideoText.className = 'videoOptionText';
		likeVideoText.innerHTML = 'Video m&ouml;gen';
		likeVideoText.style.marginLeft = '3px';
		
		likeVideoContainer.appendChild(likeVideoIcon);
		likeVideoContainer.appendChild(likeVideoText);		

		var reportVideoContainer = document.createElement("DIV");
		reportVideoContainer.className = 'videoOptionContainer';
		eval("reportVideoContainer.onclick = function() { " + this.name + ".reportVideo(); }; ");
		
		var reportVideoIcon = document.createElement("IMG");
		reportVideoIcon.src = '/images/style/icons/reportOnBright.gif';
		
		var reportVideoText = document.createElement("DIV");
		reportVideoText.className = 'videoOptionText';
		reportVideoText.innerHTML = 'Video melden';
		
		reportVideoContainer.appendChild(reportVideoIcon);
		reportVideoContainer.appendChild(reportVideoText);		
		
		var deleteVideoContainer = document.createElement("DIV");
		deleteVideoContainer.id = this.id + 'deleteVideoContainer';
		deleteVideoContainer.className = 'videoOptionContainer';
		eval("deleteVideoContainer.onclick = function() { " + this.name + ".deleteVideo(); }; ");
			
		var deleteVideoIcon = document.createElement("IMG");
		deleteVideoIcon.src = '/images/style/icons/deleteOnBright.gif';
			
		deleteVideoText = document.createElement("DIV");
		deleteVideoText.className = 'videoOptionText';
		deleteVideoText.innerHTML = 'Video l&ouml;schen';
			
		deleteVideoContainer.appendChild(deleteVideoIcon);
		deleteVideoContainer.appendChild(deleteVideoText);

		prevVideoIcon = document.createElement("IMG");
		prevVideoIcon.id = this.id + 'prevVideoIcon';		
		prevVideoIcon.src = '/images/style/arrows/greyArrowLeftActive.gif';
		prevVideoIcon.className = 'videoNavIcon prev inactive';
		eval("prevVideoIcon.onclick = function() { " + this.name + ".prevVideo(); };");
		
		nextVideoIcon = document.createElement("IMG");
		nextVideoIcon.id = this.id + 'nextVideoIcon';
		nextVideoIcon.src = '/images/style/arrows/greyArrowRightActive.gif';
		nextVideoIcon.className = 'videoNavIcon next';
		eval("nextVideoIcon.onclick = function() { " + this.name + ".nextVideo(); };");
		
		videoOptions.appendChild(shareVideoContainer);		
		videoOptions.appendChild(likeVideoContainer);
		videoOptions.appendChild(reportVideoContainer);		
		videoOptions.appendChild(deleteVideoContainer);
		videoOptions.appendChild(prevVideoIcon);
		videoOptions.appendChild(nextVideoIcon);
		
		videoBox.appendChild(outerVideoScrollContainer);	
		videoBox.appendChild(scrollLeftButton);
		videoBox.appendChild(scrollRightButton);
		videoBox.appendChild(videoHeader);
		videoBox.appendChild(videoContainer);
		videoBox.appendChild(videoOptions);

		this.box.appendChild(header);
		this.box.appendChild(videoBox);
	}	
}
	
function videosVideoBoxjs() {}
