/**************************************************************

	Script		: multiBox
	Version		: 1.4
	Authors		: Samuel Birch
	Desc		: Supports jpg, gif, png, flash, flv, mov, wmv, mp3, html, iframe
	Licence		: Open Source MIT Licence


**************************************************************/
var scrollTimerActive=null;
var markActiveTeaser=null;
var activeIDMultibox = "";

var multiBoxVideo = new Class({
	getOptions: function(){
		return {
			initialWidth: 250,
			initialHeight: 250,
			container: document.body, //this will need to be setup to the box open in relation to this.
			overlay: false, //this will be a reference to an overlay instance. - TODO: implement below.
			contentColor: '#FFF',
			showNumbers: true,
			showControls: true,
			//showThumbnails: false,
			//autoPlay: false,
			//waitDuration: 2000,
			descClassName: false,
			descMinWidth: 400,
			descMaxWidth: 600,
			movieWidth: 400,
			movieHeight: 300,
			offset: {x:0, y:0},
			fixedTop: false,
			path: 'files/',
			_onOpen: $empty,
			_onClose: $empty,
			openFromLink: true
			//relativeToWindow: true
		};
	},

	
	initialize: function(className, options,fixedWidth,fixedHeight,bolPhotoGallery,strMovie,timestamp,strType,flashImage,language){
		this.setOptions(this.getOptions(), options);
		
		this.openClosePos = {};
		this.timer = 0;
		this.contentToLoad = {};
		this.index = 0;
		this.opened = false;
		this.contentObj = {};
		this.containerDefaults = {};
		this.createArray = [];
		this.fixedWidth=-1;
		this.fixedHeight=-1;
		this.isNewVideo=false;
		this.markTextPageId="";
		this.textPageSize=-1;
		this.teaserPage=1;
		this.strType="";
		this.activeTeaser="";
		this.bolPhotoGallery = bolPhotoGallery;
		this.isNewOpen = true;
		this.strMovie = strMovie;
		this.timestamp = timestamp;
		this.variableName = "boxVideo_" + timestamp;
		this.flashImage = "";
		this.language = "";
		this.params = "";
		this.flashvars = "";
		this.attributes = "";
		
		this.type = "";
		if((fixedWidth != null) && (fixedHeight != null))
		{
			this.fixedWidth=fixedWidth;
			this.fixedHeight=fixedHeight;
		}		
		if(this.options.useOverlay){
			this.overlay = new Overlay({container: this.options.container, onClick:this.close.bind(this)});
		}
		this.overlay = this.options.overlay;
		if(this.overlay){
			this.overlay.setOnClick(this.close.bind(this));
		}
		
		this.content = $$('.'+className);
		/*if(this.options.descClassName){
			this.descriptions = $$('.'+this.options.descClassName);
			this.descriptions.each(function(el){
				el.setStyle('display', 'none');
			});
		}*/
		
		this.container = new Element('div').addClass('vpMultiBoxContainer').injectInside(this.options.container);
		this.iframe = new Element('iframe').setProperties({
			'id': 'vpmultiBoxIframe_' + this.timestamp,
			'name': 'vpmulitBoxIframe',
			'src': 'javascript:void(0);',
			'frameborder': 0,
			'scrolling': 'no'
		}).setStyles({
			'position': 'absolute',
			'top': -20,
			'left': -20,
			'filter': 'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)',
			'opacity': 0
		}).inject(this.container);
		this.box = new Element('div').addClass('vpMultiBoxContent').inject(this.container);
		
		this.closeButton = new Element('div').addClass('vpMultiBoxClose').inject(this.container).addEvent('click', this.close.bind(this));
		
		this.controlsContainer = new Element('div').addClass('vpMultiBoxControlsContainer').inject(this.container);
		if(this.bolPhotoGallery == true)
		{
			this.controls = new Element('div').addClass('vpMultiBoxControlsPhotoGallery').inject(this.controlsContainer);
		}
		else
		{
			this.controls = new Element('div').addClass('vpMultiBoxControls').inject(this.controlsContainer);
		}

		//this.description = new Element('div').addClass('vpMultiBoxDescription').inject(this.controls);

		new Element('div').setStyle('clear', 'both').inject(this.controls);
		
		this.content.each(function(el,i){
			el.index = i;
			el.addEvent('click', function(e){
				new Event(e).stop();
				this.open(el);
			}.bind(this));
			if(el.href.indexOf('#') > -1){
				el.content = $(el.href.substr(el.href.indexOf('#')+1));
				if(el.content){el.content.setStyle('display','none');}
			}
		}, this);
		
		this.containerEffects = new Fx.Morph(this.container, {duration: 400, transition: Fx.Transitions.Sine.easeInOut});
		this.iframeEffects = new Fx.Morph(this.iframe, {duration: 400, transition: Fx.Transitions.Sine.easeInOut});
		this.controlEffects = new Fx.Morph(this.controlsContainer, {duration: 300, transition: Fx.Transitions.Sine.easeInOut});
		this.reset();
	},
	
	setContentType: function(link){
		var str = link.href.substr(link.href.lastIndexOf('.')+1).toLowerCase();
		str = "swf";
		var contentOptions = {};
		if($chk(link.rel)){
			var optArr = link.rel.split(',');
			optArr.each(function(el){
				var ta = el.split(':');
				contentOptions[ta[0]] = ta[1];
			});
		}
		
		if(contentOptions.type != undefined){
			str = contentOptions.type;
		}
		
		this.contentObj = {};
//	this.contentObj.url = link.href;
//	this.contentObj.src = link.href;

	this.contentObj.url = "AS_VideoPlayer.swf";
	this.contentObj.src = "AS_VideoPlayer.swf";
		this.contentObj.xH = 0;
		
		if(contentOptions.width){
			this.contentObj.width = contentOptions.width;
		}else{
			this.contentObj.width = this.options.movieWidth;
		}
		if(contentOptions.height){
			this.contentObj.height = contentOptions.height;	
		}else{
			this.contentObj.height = this.options.movieHeight;
		}
		if(contentOptions.panel){
			this.panelPosition = contentOptions.panel;
		}else{
			this.panelPosition = this.options.panel;
		}
		
		switch(str){
			case 'jpg':
			case 'image':
			case 'gif':
			case 'png':
				this.type = 'image';
				this.contentObj.width = this.initialize.fixedWidth;
				this.contentObj.height = this.fixedHeight;	
				break;
			case 'swf':
				this.type = 'flash';
				break;
			case 'youtube':
				this.type = 'youtube';
				break;
			case 'flv':
				this.type = 'flashVideo';
				this.contentObj.xH = 70;
				break;
			case 'mov':
				this.type = 'quicktime';
				break;
			case 'wmv':
				this.type = 'windowsMedia';
				break;
			case 'rv':
			case 'rm':
			case 'rmvb':
				this.type = 'real';
				break;
			case 'mp3':
				this.type = 'flashMp3';
				this.contentObj.width = 320;
				this.contentObj.height = 70;
				break;
			case 'element':
				this.type = 'htmlelement';
				this.elementContent = link.content;
				this.elementContent.setStyles({
					display: 'block',
					opacity: 0
				})
	
				if(this.elementContent.getStyle('width') != 'auto'){
					this.contentObj.width = this.elementContent.getStyle('width');
				}
				
				this.contentObj.height = this.elementContent.getSize().y;
				this.elementContent.setStyles({
					display: 'none',
					opacity: 1
				})
				break;
				
			default:
				
				this.type = 'iframe';
				if(contentOptions.ajax){
					this.type = 'ajax';
				}
				break;
		}
	},
	
	reset: function(){
		this.container.setStyles({
			'opacity': 0,
			'display': 'none'
		});
		this.controlsContainer.setStyles({
			'height': 0
		});
		this.removeContent();
		//this.previousButton.removeClass('vpMultiBoxButtonDisabled');
		//this.nextButton.removeClass('vpMultiBoxButtonDisabled');
		this.opened = false;
	},
	
	getOpenClosePos: function(el){
		if (this.options.openFromLink) {
			if (el.getFirst()) {
				var w = el.getFirst().getCoordinates().width - (this.container.getStyle('border').toInt() * 2);
				if (w < 0) {
					w = 0
				}
				var h = el.getFirst().getCoordinates().height - (this.container.getStyle('border').toInt() * 2);
				if (h < 0) {
					h = 0
				}
				this.openClosePos = {
					width: w,
					height: h,
					top: el.getFirst().getCoordinates().top,
					left: el.getFirst().getCoordinates().left
				};
			}
			else {
				var w = el.getCoordinates().width - (this.container.getStyle('border').toInt() * 2);
				if (w < 0) {
					w = 0
				}
				var h = el.getCoordinates().height - (this.container.getStyle('border').toInt() * 2);
				if (h < 0) {
					h = 0
				}
				this.openClosePos = {
					width: w,
					height: h,
					top: el.getCoordinates().top,
					left: el.getCoordinates().left
				};
			}
		}else{
			var border = this.container.getStyle('border').toInt();
			
			if(this.options.fixedTop){
				var top = this.options.fixedTop;
			}else{
				var top = ((window.getHeight()/2)-(this.options.initialHeight/2) - border)+this.options.offset.y;
			}
			this.openClosePos = {
				width: this.options.initialWidth,
				height: this.options.initialHeight,
				top: top,
				left: ((window.getWidth()/2)-(this.options.initialWidth/2)-border)+this.options.offset.x
			};
		}
		return this.openClosePos;
	},
	
	open: function(el){
		this.isNewOpen = true;

		this.options._onOpen();
	
		this.index = this.content.indexOf(el);
		
		this.openId = el.getProperty('id');
		
		var border = this.container.getStyle('border').toInt();
		
		if(!this.opened){
			this.opened = true;
			
			if(this.options.overlay){
				MenuMatic.aSubMenu.displayTransMask(true,true);
				activeIDMultibox = this.variableName;
				$("transMask").addEvent('click',eval(this.variableName).closeFromOutSide); 
			}

			this.container.setStyles(this.getOpenClosePos(el));
			this.container.setStyles({
				opacity: 0,
				display: 'block'
			});
			
			if(this.options.fixedTop){
				var top = this.options.fixedTop;
			}else{
				var top = ((window.getHeight()/2)-(this.options.initialHeight/2) - border)+this.options.offset.y;
			}
			
			
			this.containerEffects.start({
				width: this.options.initialWidth,
				height: this.options.initialHeight,
				top: top,
				left: ((window.getWidth()/2)-(this.options.initialWidth/2)-border)+this.options.offset.x,
				opacity: [0, 1]
			});
			
			this.load(this.index);
		
		}else{
			if (this.options.showControls) {
				this.hideControls();
			}
			this.getOpenClosePos(this.content[this.index]);
			this.timer = this.hideContent.bind(this).delay(500);
			this.timer = this.load.pass(this.index, this).delay(1100);
			
		}
		objVideoTeaser = document.getElementById("vpMultiBoxVideoPlaylistContainer_" + this.timestamp);
		document.getElementById("vpMultiBoxVideoPlaylistContainerTmp_" + this.timestamp).appendChild(objVideoTeaser)
		objVideoTeaser.style.display = "none";
	},
	
	findActiveTeaser : function()
	{
		//this.onMouseDownString = $(this.var_setHighlight).getAttribute("onMouseDown").toString();
		this.isNewOpen = false;
		allTeasers = $$('.videoTeaser');
		activeTeaserObj = null;
		for(iPage = 0;iPage < allTeasers.length;iPage++)
		{
			this.onMouseDownString = allTeasers[iPage].getAttribute("onMouseDown").toString();
			if(this.onMouseDownString.indexOf(this.strMovie) != -1)
			{
				if(allTeasers[iPage].id.indexOf(this.timestamp) != -1)
				{
					activeTeaserObj = allTeasers[iPage];
					break;
				}
			}
		}
		if(activeTeaserObj != null)
		{
			this.setVideoTeaserActive(activeTeaserObj);

			containerHeight = $("vpMultiBoxContentContainer_" + this.timestamp).getHeight();
			iTeaserSpace = this.calculateTeaserSpace(containerHeight);
			iTeaserCount = this.getTeaserCount();
			teaserNumber = activeTeaserObj.id.replace("videoTeaser","");
			teaserNumber = teaserNumber.replace("_" + this.timestamp,"");
			page = parseInt(teaserNumber/iTeaserSpace);
			for(i = 0;i < page;i++)
			{
				this.vidioTeaserScrollDown();
			}
			
		}
	},
	
	create: function(obj){

		
		if(this.createArray.contains(obj.url)){
			var index = this.createArray.indexOf(obj.url);
			var a = this.content[index];
		}else{
			
			var id = 'mbDirect_' + $time();
			var rel = [];
			if(obj.type){rel.push('type:'+obj.type)}
			if(obj.width){rel.push('width:'+obj.width)}
			if(obj.height){rel.push('height:'+obj.height)}
			
			var a = new Element('a', {
				'href': obj.url,
				'id': id,
				'title': obj.title || '',
				'rel': rel.join(',')
			});
			var desc = new Element('div', {
				'class': id,
				'html': obj.description || ''
			})
		
			this.createArray.push(obj.url);
			this.content.push(a);
			var index = this.content.length-1;
			

		}

		
		this.open(a);
	},
	
	getContent: function(index){
		this.setContentType(this.content[index]);
		var desc = false;

		this.contentToLoad = {
			title: this.content[index].title || '&nbsp;',
			desc: desc,
			number: index+1
		};
		
	},
	
	close: function(){
		if(this.options.overlay){
			MenuMatic.aSubMenu.displayTransMask(false,true);
		}
		if (this.options.showControls) {
			this.hideControls();
		}
		this.hideContent();
		this.containerEffects.cancel();
		this.zoomOut.bind(this).delay(500);
		this.options._onClose();
	},
	
	closeFromOutSide: function()
	{
		$("transMask").removeEvent('click',activeIDMultibox.closeFromOutSide);
		MenuMatic.aSubMenu.displayTransMask(false,true);
		if (eval(activeIDMultibox).options.showControls) {
			eval(activeIDMultibox).hideControls();
		}
		eval(activeIDMultibox).hideContent();
		eval(activeIDMultibox).containerEffects.cancel();
		eval(activeIDMultibox).zoomOutFromOutside.bind(eval(activeIDMultibox)).delay(500);
	},	
	
	zoomOut: function(){
		this.iframeEffects.start({
			width: this.openClosePos.width,
			height: this.openClosePos.height
		});
		this.containerEffects.start({
			width: this.openClosePos.width,
			height: this.openClosePos.height,
			top: this.openClosePos.top,
			left: this.openClosePos.left,
			opacity: 0
		});
		this.reset.bind(this).delay(500);
	},
	
	zoomOutFromOutside: function(){
		////console.log("9");

		eval(activeIDMultibox).iframeEffects.start({
			width: eval(activeIDMultibox).openClosePos.width,
			height: eval(activeIDMultibox).openClosePos.height
		});
		eval(activeIDMultibox).containerEffects.start({
			width: eval(activeIDMultibox).openClosePos.width,
			height: eval(activeIDMultibox).openClosePos.height,
			top: eval(activeIDMultibox).openClosePos.top,
			left: eval(activeIDMultibox).openClosePos.left,
			opacity: 0
		});
		eval(activeIDMultibox).reset.bind(eval(activeIDMultibox)).delay(500);
	},		
	
	load: function(index){
		this.box.addClass('vpMultiBoxLoading');
		this.getContent(index);
		if(this.type == 'image'){
			var xH = this.contentObj.xH;
			this.contentObj = new Asset.image(this.content[index].href, {onload: this.resize.bind(this)});
			this.contentObj.xH = xH;
			this.actImageHeight =  this.contentObj.height;
		}else{
			this.resize();
		}
	},
	
	resize: function(){
		if(this.tempSRC != this.contentObj.src){
			var markWidth = this.contentObj.width;
			var markHeight = this.contentObj.height;
			if((this.fixedWidth != -1) && (this.fixedHeight != -1))
			{
				this.contentObj.width = this.fixedWidth;
				this.contentObj.height = this.fixedHeight;				
			}			
			var border = this.container.getStyle('border').toInt();
			
			if (this.options.fixedTop) {
				var top = this.options.fixedTop;
			}
			else {
				var top = ((window.getHeight() / 2) - ((Number(this.contentObj.height) + this.contentObj.xH) / 2) - border + window.getScrollTop()) + this.options.offset.y;
			}
			var left = ((window.getWidth() / 2) - ((this.contentObj.width.toInt()+250) / 2) - border) + this.options.offset.x;
			if (top < 0) {
				top = 0
			}
			if (left < 0) {
				left = 0
			}
			
			this.containerEffects.cancel();
			this.containerEffects.start({
				width: this.contentObj.width+250,
				height: Number(this.contentObj.height) + this.contentObj.xH,
				top: top,
				left: left,
				opacity: 1
			});
			this.iframeEffects.start({
				width: Number(this.contentObj.width) + (border*2),
				height: Number(this.contentObj.height) + this.contentObj.xH + (border*2)
			});
			this.contentObj.width = markWidth;
			this.contentObj.height = markHeight;
			this.timer = this.showContent.bind(this).delay(500);
			this.tempSRC = this.contentObj.src;
		}
	},
	
	showContent: function(){
		this.tempSRC = '';
		this.box.removeClass('vpMultiBoxLoading');
		this.removeContent();
		var markWidth = this.contentObj.width;
		var markHeight = this.contentObj.height;
		if((this.fixedWidth != -1) && (this.fixedHeight != -1))
		{
			this.contentObj.width = this.fixedWidth;
			this.contentObj.height = this.fixedHeight;				
		}	
		this.contentContainer = new Element('div').setProperties({id: 'vpMultiBoxContentContainer_' + this.timestamp}).addClass('vpMultiBoxContentContainer').setStyles({opacity: 0, width: this.contentObj.width, height: (Number(this.contentObj.height)+this.contentObj.xH)}).injectInside(this.box);
		//this.contentContainerA = new Element('a').setProperties({id: 'MultiBoxContentContainerA'}).injectInside(this.contentContainer);
		
		containerHeight = document.getElementById("vpMultiBoxContentContainer_" + this.timestamp).style.height.replace("px","");
		containerHeightTmp = Number(containerHeight) - 36;
		//this.nextButton.style.top = (containerHeightTmp/2) + "px";
		//this.previousButton.style.top = (containerHeightTmp/2) + "px";

		document.getElementById("videoTeaserContainer_" + this.timestamp).style.height = containerHeight + "px";
		

		if(this.bolPhotoGallery == true)
		{
			if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) //Set the image to middle position when the browser version is ie 6
			{ //test for MSIE x.x;
			
				var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
				if (ieversion==6)
				{	
					containerHeight = containerHeight - this.actImageHeight;
					this.contentObj.style.marginTop = (containerHeight/2) + "px";
				}
			}
		}		
		
			
		if(this.type == 'image'){			
			this.contentObj.injectInside(this.contentContainer);
			
		}else if(this.type == 'iframe'){
			new Element('iframe').setProperties({
				id: 'iFrame'+new Date().getTime(), 
				width: this.contentObj.width,
				height: this.contentObj.height,
				src: this.contentObj.url,
				frameborder: 0,
				scrolling: 'auto'
			}).injectInside(this.contentContainer);
			
		}else if(this.type == 'htmlelement'){
			this.elementContent.clone().setStyle('display','block').injectInside(this.contentContainer);
			
		}else if(this.type == 'ajax'){
			new Request.HTML({
				update: $('vpMultiBoxContentContainer_' + this.timestamp),
				autoCancel: true
			}).get(this.contentObj.url);
			
		}else{
			var obj = this.createEmbedObject().injectInside(this.contentContainer);
			if(this.str != ''){
				eval(this.str);
				$("vpMultiBoxMediaObject_" + this.timestamp).style.position = 'absolute';
				//$("MultiBoxMediaObject_" + this.timestamp).style.left = "0px";
			}
		}
		
		this.contentEffects = new Fx.Morph(this.contentContainer, {duration: 500, transition: Fx.Transitions.linear});
		this.contentEffects.start({
			opacity: 1
		});

		if (this.options.showControls) {
			if(this.contentToLoad.title != '&nbsp;' || this.content.length > 1){
				this.timer = this.showControls.bind(this).delay(800);
			}
		}
//Am 30.4 auskommentiert da die Höhe nicht passte		
//this.contentObj.width = markWidth;
//this.contentObj.height = markHeight;
	},
	
	getTeaserCount: function()
	{
		var iCount = 0;
/*		for(i=1;i < 500;i++)
		{
			obj = document.getElementById("videoTeaser" + i + "_"  + this.timestamp);
			if(obj == null)
			{
				break;
			}
			iCount++;
		}
		return iCount;
	*/	
		
		allTeasers = $$('.videoTeaser');
		for(i = 0;i < allTeasers.length;i++)
		{
			if(allTeasers[i].id.indexOf(this.timestamp) != -1)
			{
				iCount++;
			}
		}
		return iCount;
		
	},
	
	resizeVideoTeaserContainer: function(iTeaserCount)
	{
		this.iTeaserCount = iTeaserCount;
		var iTeaserSpace = this.calculateTeaserSpace(this.contentObj.height);
		var iModulo = iTeaserCount%iTeaserSpace;
		var iSpacerHeight = this.contentObj.height - (iModulo*70);
		document.getElementById("videoTeaserSpacerBottom_" + this.timestamp).style.height = iSpacerHeight + "px";
	},
	
	calculateTeaserSpace: function(containerHeight)
	{
		var iTeaserSpace = (containerHeight-40) / 70;
		return parseInt(iTeaserSpace);
	},
	
	shutOfHiddenTeaser: function(iTeaserCountOnPage)
	{
		this.iTeaserCountOnPage = iTeaserCountOnPage;
		$("videoScrollerTop_" + this.timestamp).style.display = "block";
		$("videoScrollerBottom_" + this.timestamp).style.display = "block";
		var iPos = this.teaserPage * this.iTeaserCountOnPage;
		for(i=1;i <= iPos;i++)
		{
			obj = document.getElementById("videoTeaser" + i + "_" + this.timestamp);
			if(obj == null)
			{
				break;
			}
			else
			{
				obj.style.visibility = "visible";
			}
		}		
		
		if((this.getTeaserCount() < 6) && (this.iTeaserCountOnPage >= 5))
		{			
			$("videoScrollerTop_" + this.timestamp).style.display = "none";
			$("videoScrollerBottom_" + this.timestamp).style.display = "none";
		}
		else
		{
			var iPos = this.teaserPage * this.iTeaserCountOnPage;
			for(i=1;i <= iPos;i++)
			{
				obj = document.getElementById("videoTeaser" + i + "_" + this.timestamp);
				if(obj == null)
				{
					break;
				}
				else
				{
					obj.style.visibility = "visible";
				}
			}		
			iPos++;
			for(i=iPos;i < 500;i++)
			{
				obj = document.getElementById("videoTeaser" + i + "_" + this.timestamp);
				if(obj == null)
				{
					break;
				}
				else
				{
					obj.style.visibility = "hidden";
				}
			}
		}
	},
	
	setParent: function(el, newParent)  {
		newParent.appendChild(el);
	},

	

	getTitleToElement: function(id)
	{
		obj = $(id); 
		if(obj != null)
		{
			this.markTextPageId = id;
			return obj.innerHTML;
		}
		else
		{
			return null;
		}
	},
	
	visibleNavButttons: function(visibility)
	{
		if(visibility == "none")
		{
			document.getElementById("lightBoxMouseOver_" + this.timestamp).value = "false";			
			window.setTimeout("box.hideNavButttonsDelay()", 500);
		}
		else
		{
			document.getElementById("lightBoxMouseOver_" + this.timestamp).value = "true";			
			$("vpMultiBoxNext_" + this.timestamp).style.display = visibility;
			$("vpMultiBoxPrevious_" + this.timestamp).style.display = visibility;
		}
	},
	
	hideNavButttonsDelay: function()
	{
		if(document.getElementById("lightBoxMouseOver_" + this.timestamp).value == "false")
		{
			window.status = document.getElementById("lightBoxMouseOver").value
			
			document.getElementById("vpMultiBoxNext_" + this.timestamp).style.display = "none";
			document.getElementById("vpMultiBoxPrevious_" + this.timestamp).style.display = "none";
		}
	},
	
	hideContent: function(){
		this.box.addClass('vpMultiBoxLoading');
		this.contentEffects.start({
			opacity: 0
		});
		this.removeContent.bind(this).delay(500);
	},
	
	removeContent: function(){
		if($('vpMultiBoxMediaObject_' + this.timestamp)){
		//	$('vpMultiBoxMediaObject').empty();
			//$('vpMultiBoxMediaObject').destroy();
		}
		if($('vpMultiBoxContentContainer_' + this.timestamp)){
			$('vpMultiBoxContentContainer_' + this.timestamp).destroy();	
		}
	},
	
	showControls: function(){
		this.container.style.width = Number(this.contentContainer.style.width.replace("px","")) + 250 + "px";
		this.contentContainer.style.width = Number(this.contentContainer.style.width.replace("px","")) + 250 + "px";
		if(document.getElementById("vpMultiBoxVideoPlaylist_" + this.timestamp) == null)
		{
			this.videoPlaylist= new Element('div').setProperties({id: 'vpMultiBoxVideoPlaylist_' + this.timestamp}).addClass('vpMultiBoxVideoPlaylist').injectInside(this.box);
		}
		this.resizeVideoTeaserContainer(this.getTeaserCount());
		objVideoTeaser = document.getElementById("vpMultiBoxVideoPlaylistContainer_" + this.timestamp);
		this.shutOfHiddenTeaser(this.calculateTeaserSpace(this.contentObj.height));
		document.getElementById("vpMultiBoxVideoPlaylist_" + this.timestamp).appendChild(objVideoTeaser)

		if(this.activeTeaser != "")
		{
			this.setVideoTeaserActive(this.activeTeaser);
			this.videoTeaserUpToActiveTeaser(this.activeTeaser);
		}
		objVideoTeaser.style.display = "block";
		
		this.clicked = false;
		
		if(this.container.getStyle('height') != 'auto'){
			this.containerDefaults.height = this.container.getStyle('height')
			this.containerDefaults.backgroundColor = this.options.contentColor;
		}
		
		this.container.setStyles({
			'height': 'auto'
		});
		
	
		this.controlEffects.start({'height': this.controls.getCoordinates().height});
		this.iframeEffects.start({'height': this.iframe.getStyle('height').toInt()+this.controls.getStyle('height').toInt()});
		
		if(this.options.overlay){
			this.options.overlay.position();
		}
		if(this.isNewOpen == true)
		{
			this.findActiveTeaser();
		}
		
	},
	
	hideControls: function(num){
		this.iframeEffects.start({'height': this.iframe.getStyle('height').toInt()-this.controls.getStyle('height').toInt()});
		this.controlEffects.start({'height': 0}).chain(function(){
			this.container.setStyles(this.containerDefaults);
		}.bind(this));
	},
	
	showThumbnails: function(){
		
	},
	
	next: function(){
		if(this.index < this.content.length-1){
			this.index++;
			this.openId = this.content[this.index].getProperty('id');
			if (this.options.showControls) {
				this.hideControls();
			}
			this.getOpenClosePos(this.content[this.index]);
			//this.getContent(this.index);
			this.timer = this.hideContent.bind(this).delay(500);
			this.timer = this.load.pass(this.index, this).delay(1100);
		}
	},
	
	previous: function(){
		if(this.index > 0){
			this.index--;
			this.openId = this.content[this.index].getProperty('id');
			if (this.options.showControls) {
				this.hideControls();
			}
			this.getOpenClosePos(this.content[this.index]);
			//this.getContent(this.index);
			this.timer = this.hideContent.bind(this).delay(500);
			this.timer = this.load.pass(this.index, this).delay(1000);
		}
	},
	

	createEmbedObject: function(){
		if(this.type == 'flash'){
			var url = this.contentObj.url;
			
			// at videoplaylist autoplay
			if (this.strType=='flv')
			{
				this.strType='auto_play';
			}	
			var obj = new Element('div',{'class': 'vpMultiBoxMediaObject'}).setProperties({id: 'vpMultiBoxMediaObject_' + this.timestamp});
			this.str = 'var flashvars = {};';
			this.str += 'flashvars.Video_width = "0";';
			this.str += 'flashvars.Video_height = "0";';
			this.str += 'flashvars.Video_x = "0";';
			this.str += 'flashvars.Video_y = "0";';
			if((this.strType == "stream") || (this.strType == "stream2"))
			{
				iPos = this.strMovie.lastIndexOf("/");
				this.str += 'flashvars.Video_file =   "' + this.strMovie.substring(iPos+1,this.strMovie.length) + '";';
				this.str += 'flashvars.Video_streampath =   "' + this.strMovie.substring(0,iPos) + '";';
				//alert(this.str);
			}
			else
			{
				this.str += 'flashvars.Video_file = "' + this.strMovie + '";';
			}
			this.str += 'flashvars.Image_file = "' + this.flashImage + '";';
			this.str += 'flashvars.Video_type = "' +  this.strType + '";';
			this.str += 'flashvars.Video_autosize = "true";';
			/*this.str += 'flashvars.Video_autoplay = "' + this.autoplay + '";';*/
			this.str += 'flashvars.Video_autoplay = "true";';

			
			strExternalFlashVars = this.getExternalFlashVars();
			if(strExternalFlashVars != "")
				this.str += strExternalFlashVars;
			
			//this.str += 'flashvars.
			this.str += 'var params = {};';
			this.str += 'params.menu = "false";';
			this.str += 'params.scale = "noscale";';
			this.str += 'params.allowfullscreen = "true";';
			this.str += 'params.bgcolor = "f6f6f6";';
			this.str += 'params.autostart = "true";';
			this.str += 'params.allowscriptaccess = "sameDomain";';
			this.str += 'params.allownetworking = "all";';
			this.str += 'params.wmode = "window";';
			this.str += 'params.lang = "' +  this.strLanguage + '";';
			strExternalParams = this.getExternalParams();
			if(strExternalParams != "")
				this.str += strExternalParams;
			
			this.str += 'var attributes = {};';
			this.str += 'attributes.id = "vpMultiBoxMediaObject_' + this.timestamp + '";';
			
			strExternalAttributes = this.getExternalAttributes();
			if(strExternalAttributes != "")
				this.str += strExternalAttributes;
			this.str += 'swfobject.embedSWF("fileadmin/layout/flash/AS_VideoPlayer.swf", "vpMultiBoxMediaObject_' + this.timestamp + '", "' + this.contentObj.width + '","' + this.contentObj.height + '", "9.0.0", "expressInstall.swf", flashvars, params, attributes);';
			//alert(this.str);

		}
		
		if(this.type == 'flashVideo'){
			alert('flashVideo');
			//var url = this.contentObj.url.substring(0, this.contentObj.url.lastIndexOf('.'));
			var url = this.contentObj.url;
			
			var obj = new Element('div',{'class': 'vpMultiBoxMediaObject'}).setProperties({id: 'vpMultiBoxMediaObject_' + this.timestamp});
			this.str = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" '
			this.str += 'width="'+this.contentObj.width+'" ';
			this.str += 'height="'+(Number(this.contentObj.height)+this.contentObj.xH)+'" ';
			this.str += 'title="vpMultiBoxMedia">';
  			this.str += '<param name="movie" value="'+this.options.path+'flvplayer.swf" />'
  			this.str += '<param name="quality" value="high" />';
  			this.str += '<param name="salign" value="TL" />';
  			this.str += '<param name="scale" value="noScale" />';
  			this.str += '<param name="autostart" value="true" />';
  			this.str += '<param name="FlashVars" value="path='+url+'" />';
  			this.str += '<embed src="'+this.options.path+'flvplayer.swf" ';
  			this.str += 'quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" ';
  			this.str += 'width="'+this.contentObj.width+'" ';
  			this.str += 'height="'+(Number(this.contentObj.height)+this.contentObj.xH)+'"';
  			this.str += 'salign="TL" ';
  			this.str += 'scale="noScale" ';
  			this.str += 'autostart="true" ';
  			this.str += 'FlashVars="path='+url+'"';
  			this.str += '></embed>';
			this.str += '</object>';
			
		}
		return obj;
	},
	
	videoTeaserUpToActiveTeaser: function(obj)
	{
		var iTeaserSpace = this.calculateTeaserSpace(this.contentObj.height);
		var iTeaserCount = this.getTeaserCount();
		var iCountPages = parseInt(iTeaserCount / iTeaserSpace);
		if(iTeaserCount%iTeaserSpace > 0)
		{
			iCountPages++;
		}
		strActiveTeaser = obj.id.replace("videoTeaser","");
		iPos = strActiveTeaser.indexOf("-");
		if(iPos != -1)
			strActiveTeaser = strActiveTeaser.substring(0,iPos);
		iActiveTeaser = Number(strActiveTeaser.replace("_" + this.timestamp,""));
		var tmp = Math.ceil(iActiveTeaser / iTeaserSpace)-1;
		//var tmp = parseInt(iActiveTeaser / iTeaserSpace);
		this.teaserPage = tmp+1; //Start with 1 for the first page
		var iScrollDownPos = (iTeaserSpace * 70)*tmp;
		this.shutOfHiddenTeaser(iTeaserSpace);
		obj = document.getElementById("videoTeaserContainer_" + this.timestamp);
		obj.scrollTop = iScrollDownPos;
		// scrolling per positioning
		if (iScrollDownPos!=0){
			$("videoScrollerTop_" + this.timestamp).className = "videoScrollerTop";		
		}else{
			$("videoScrollerTop_" + this.timestamp).className = "videoScrollerTopNotActive";		
                }	
	},
	
	
	vidioTeaserScrollDown: function()
	{
		var iTeaserSpace = this.calculateTeaserSpace(this.contentObj.height);
		var iTeaserCount = this.getTeaserCount();
		var iCountPages = parseInt(iTeaserCount / iTeaserSpace);
		

		if(this.teaserPage == iCountPages)
		{
			$("videoScrollerBottom_" + this.timestamp).style.visibility = "hidden";
		}
		if(iTeaserCount%iTeaserSpace > 0)
		{
			iCountPages++
		}
		this.teaserPage++;
		if(iCountPages >= 1)
		{
			$("videoScrollerTop_" + this.timestamp).className = "videoScrollerTop";		
		}	
		var iScrollDownPos = (iTeaserSpace * 70);
		this.shutOfHiddenTeaser(iTeaserSpace);
		obj = document.getElementById("videoTeaserContainer_" + this.timestamp);
		obj.scrollTop = obj.scrollTop + iScrollDownPos
		
	},

	vidioTeaserScrollUp: function()
	{
		if(this.teaserPage > 1)
		{
			this.teaserPage--;
			if(this.teaserPage == 1)
			{
				$("videoScrollerTop_" + this.timestamp).className = "videoScrollerTopNotActive";						
			}
			var iTeaserSpace = this.calculateTeaserSpace(this.contentObj.height);
			var iScrollUpPos = (iTeaserSpace * 70);
			this.shutOfHiddenTeaser(iTeaserSpace);
			obj = document.getElementById("videoTeaserContainer_" + this.timestamp);
			obj.scrollTop = obj.scrollTop - iScrollUpPos;
			$("videoScrollerBottom_" + this.timestamp).style.visibility = "visible";
			
		}
	},	
	
	setVideoTeaserActive: function(obj)
	{
		obj.className = "videoTeaserActive";
		if(markActiveTeaser != null)
			document.getElementById(markActiveTeaser).className = "videoTeaser";
		markActiveTeaser = obj.id;
		
	},
	
	getExternalFlashVars: function()
	{
		strFlashVars = "";
		if(this.flashvars != null)
		{
			aryFlashvars = this.flashvars.split(";");
			for(i=0;i < aryFlashvars.length;i++)
			{
				splitTmp = aryFlashvars[i].split("=");
				if(splitTmp.length > 1)
				{
					if(splitTmp[0].indexOf(".") != -1)
					{
						pos = splitTmp[0].indexOf(".");
						splitTmp[0] = splitTmp[0].substring(pos+1,splitTmp[0].length);
					}
					strFlashVars = strFlashVars + "flashvars." + splitTmp[0] + " = \"" + splitTmp[1] + "\";";
				}
			}
		}
		return strFlashVars;
	},
	
	getExternalParams: function()
	{
		strParams = "";
		if(this.params != null)
		{
			aryParams = this.params.split(";");
			for(i=0;i < aryParams.length;i++)
			{
				splitTmp = aryParams[i].split("=");
				if(splitTmp.length > 1)
				{
					if(splitTmp[0].indexOf(".") != -1)
					{
						pos = splitTmp[0].indexOf(".");
						splitTmp[0] = splitTmp[0].substring(pos+1,splitTmp[0].length);
					}
					strParams = strParams + "params." + splitTmp[0] + " = \"" + splitTmp[1] + "\";";
				}
			}
		}
		return strParams;
	},	
	
	getExternalAttributes: function()
	{
		strAttributes = "";
		if(this.attributes != null)
		{
			aryAttributes = this.attributes.split(";");
			for(i=0;i < aryAttributes.length;i++)
			{
				splitTmp = aryAttributes[i].split("=");
				if(splitTmp.length > 1)
				{
					if(splitTmp[0].indexOf(".") != -1)
					{
						pos = splitTmp[0].indexOf(".");
						splitTmp[0] = splitTmp[0].substring(pos+1,splitTmp[0].length);
					}
					strAttributes = strAttributes + "attributes." + splitTmp[0] + " = \"" + splitTmp[1] + "\";";
				}
			}
		}
		return strAttributes;
	},	

	
	resizeContent: function(width, height,obj,movie,timestamp,strType,flashImage,language,params,flashvars,attributes)
	{
		this.fixedWidth = width;
		this.fixedHeight = height;
		this.contentObj.width = width;
		this.contentObj.height = height;
		this.timestamp = timestamp;
		this.isNewVideo = true;		
		this.type = "flash";
		this.autoplay = "true"
		this.strType = strType;
		if(params != null)
			this.params = params;
		if(flashvars != null)
			this.flashvars = flashvars;
		if(attributes != null)
			this.attributes = attributes;
		
		if(obj != null)
		{
			if(obj.className.indexOf("videoTeaser") != -1)
			{
				this.activeTeaser = obj;
			}
		}
		if(document.getElementById("vpMultiBoxMediaObject_" + this.timestamp) != null)
		{
			document.getElementById("vpMultiBoxMediaObject_" + this.timestamp).style.display = "none";
			this.resize();
		}
		this.strMovie = movie;
		if(language != undefined)
			this.language = language;
		else
			this.language = "de";

		if(flashImage != undefined)
			this.flashImage = flashImage;
		else
			this.flashImage = "uploads/tx_livideocontent/BMW_328_3x2.jpg";
			
	}
	
});
multiBoxVideo.implement(new Options);
multiBoxVideo.implement(new Events);
