/**************************************************************

	Script		: multiBox
	Version		: 1.4
	Desc		: Supports jpg, gif, png, flash, flv, mov, wmv, mp3, html, iframe
	Licence		: Open Source MIT Licence
	Date            : 2010-09-07


**************************************************************/
var activeIDMultibox = "";
var multiBox = new Class({
	
	getOptions: function(){
		return {
			initialWidth: 250,
			initialHeight: 250,
			container: $("content-overlay"), //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:-100}, //Change the y position from 0 to -100 
			fixedTop: false,
			path: 'files/',
			_onOpen: $empty,
			_onClose: $empty,
			openFromLink: true
			//relativeToWindow: true
		};
	},

	initialize: function(className, options,fixedWidth,fixedHeight,bolPhotoGallery,variableName){
		this.setOptions(this.getOptions(), options);
		////console.log("1");
		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.markTextPageId="";
		this.textPageSize=-1;
		this.timeStamp = new Date().getTime();
		this.params = "";
		this.flashvars = "";
		this.attributes = "";
//		this.flashvars = "flashvars.Video_width:0;Video_height:0;Video_x:0;Video_y:0;Video_autosize:true;";
		this.bolPhotoGallery = bolPhotoGallery;
		this.variableName = variableName;
		if(this.variableName == undefined)
			this.variableName = "box";
		this.strMovie;
		this.lightBoxMouseOver;
		this.isTextAvailable = false;
		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('MultiBoxContainer').injectInside(this.options.container);
		this.iframe = new Element('iframe').setProperties({
			'id': 'multiBoxIframe',
			'name': 'mulitBoxIframe',
			'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('MultiBoxContent').inject(this.container);
		
		this.closeButton = new Element('a').addClass('MultiBoxClose').setProperties({id:"MultiBoxClose" + this.timeStamp}).setProperties({href:"JavaScript:" + this.variableName + ".close()"}).inject(this.container);
		
		
		this.controlsContainer = new Element('div').addClass('MultiBoxControlsContainer').inject(this.container);
		if(this.bolPhotoGallery == true)
		{
			this.controls = new Element('div').addClass('MultiBoxControlsPhotoGallery').inject(this.controlsContainer);
		}
		else
		{
			this.controls = new Element('div').addClass('MultiBoxControls').inject(this.controlsContainer);
		}
		

		this.previousButtonDiv = new Element('a').addClass('DivMultiBoxPrevious').setProperties({id:"DivMultiBoxPrevious" + this.timeStamp}).setProperties({href: "JavaScript:" + this.variableName + ".previous(this)"}).inject(this.controls);
		this.nextButtonDiv = new Element('a').addClass('DivMultiBoxNext').setProperties({id:"DivMultiBoxNext" + this.timeStamp}).setProperties({href: "JavaScript:" + this.variableName + ".next(this)"}).inject(this.controls);
		
		
		this.previousButton = new Element('a').addClass('MultiBoxPreviousDisabled').setProperties({id:"MultiBoxPreviousDisabled"}).setProperties({href: "JavaScript:" + this.variableName + ".previous(this)"}).inject(this.previousButtonDiv);
		this.nextButton = new Element('a').addClass('MultiBoxNextDisabled').setProperties({id:"MultiBoxNextDisabled"}).setProperties({href: "JavaScript:" + this.variableName + ".next(this)"}).inject(this.nextButtonDiv);
		
		this.title = new Element('div').addClass('MultiBoxTitle').inject(this.controls);
		this.titleMargin = this.title.getStyle('margin-left');
		this.numberElement = new Element('div').addClass('MultiBoxNumberContainer').inject(this.controls);
		this.previousTextButton = new Element('a').addClass('MultiBoxNumberTextPrevious').setProperties({id:"MultiBoxNumberTextPrevious"}).setProperties({href: "JavaScript:" + this.variableName + ".previousTextMessage()"}).inject(this.numberElement); 
		this.nextTextButton = new Element('a').addClass('MultiBoxNumberTextNext').setProperties({id:"MultiBoxNumberTextNext"}).setProperties({href: "JavaScript:" + this.variableName + ".nextTextMessage()"}).inject(this.numberElement); 
		this.number = new Element('div').addClass('MultiBoxNumber').inject(this.numberElement);
		this.numberLine = new Element('div').addClass('MultiBoxNumberLine').inject(this.controls);

		//this.description = new Element('div').addClass('MultiBoxDescription').inject(this.controls);
		
		if(this.content.length == 1){
			this.title.setStyles({
				'margin-left': 0
			});
			
			this.previousButton.setStyle('display', 'none');
			this.nextButton.setStyle('display', 'none');
			//this.previousButtonDiv.setStyle('display', 'none');
			//this.nextButtonDiv.setStyle('display', 'none');
			this.number.setStyle('display', 'none');
		}
		
		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){
		////console.log("2");

		var str = link.href.substr(link.href.lastIndexOf('.')+1).toLowerCase();
		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;
		}		
		if(link.type != null)
		{
			if(link.type == "swfVideo")
				str = link.type;
			if(link.type == "swf")
				str = link.type;
		}
		this.contentObj = {};
		this.contentObj.url = link.href;
		this.contentObj.src = link.href;
		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 'swfVideo':
				this.type = 'flashVideoPlayer';
				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(){
		////console.log("3");

		this.container.setStyles({
			'opacity': 0,
			'display': 'none'
		});
		this.controlsContainer.setStyles({
			'height': 0
		});
		this.removeContent();
		this.previousButton.removeClass('MultiBoxButtonDisabled');
		this.nextButton.removeClass('MultiBoxButtonDisabled');
		this.opened = false;
	},
	
	getOpenClosePos: function(el){
		////console.log("4");

		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){
		////console.log("5");

		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); 
				/*				$("transMask").removeEvent('click',this.clickOnClose);

				if(this.options.overlay){
					//this.overlay.hide();
					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();*/

				

				
				//this.overlay.show();
			}

			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;
			}
			top = top + $("content-overlay").scrollTop
			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);
			
		}
		
	},
	
	create: function(obj){
		////console.log("6");

		/*
		obj = {
			url: 'myurl',  *
			title: 'my title',
			description: 'my description',
			type: 'image',
			width: 400,
			height: 300
		}
		*/
		
		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;
			
			if(this.options.descClassName){
				//this.descriptions.include(desc);
			}
		}

		
		this.open(a);
	},
	
	getContent: function(index){
		////console.log("7");

		this.setContentType(this.content[index]);
		var desc = false;
		if(this.options.descClassName){
		/*this.descriptions.each(function(el,i){
			if(el.hasClass(this.openId)){
				desc = el.clone();
			}
		},this);*/
		}
		this.contentToLoad = {
			title: this.content[index].title || '&nbsp;',
			desc: desc,
			number: index+1
		};
		this.textMessageSize(); //Set the size of text pages for this image display 
		
	},
	
	clickOnClose: function(timeStamp){
	  var fireOnThis = $("MultiBoxClose" + activeIDMultibox)
	  if (document.createEvent)
	  {
	    var evObj = document.createEvent('MouseEvents')
	    evObj.initEvent( 'click', true, false )
	    fireOnThis.dispatchEvent(evObj)
	  }
	  else 
	  {
		  if (document.createEventObject)
		  {
		    fireOnThis.fireEvent('onclick');
		    alert("test")
	 	  }
	  }
	},
	
	close: function(){
		////console.log("8 close");


		if(this.options.overlay){
			//this.overlay.hide();
			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(){
		////console.log("9");

		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){
		////console.log("10");
		////console.log(this.type)
	//	eval("this." + this.variableName + ".addClass('MultiBoxLoading')");
		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(){
		////console.log("11");

		//////console.log("resize")
		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() / 2) - border) + this.options.offset.x;
			if (top < 0) {
				top = 0
			}
			if (left < 0) {
				left = 0
			}
			
			
			top = top + $("content-overlay").scrollTop
			this.containerEffects.cancel();
			this.containerEffects.start({
				width: this.contentObj.width,
				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(){
		////console.log("12 event");

		this.tempSRC = '';
		//eval("this." + this.variableName).removeClass('MultiBoxLoading');
		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: 'MultiBoxContentContainer'}).setStyles({opacity: 0, width: this.contentObj.width, height: (Number(this.contentObj.height)+this.contentObj.xH)}).injectInside(this.box);
	
		this.previousButtonDiv = new Element('a').addClass('DivMultiBoxPrevious').setProperties({id:"DivMultiBoxPrevious" + this.timeStamp}).setProperties({href: "JavaScript:" + this.variableName + ".previous(this)"}).inject(this.contentContainer);
		this.previousButtonImage = new Element('img').addClass('DivMultiBoxPreviousImg').setProperties({src:"fileadmin/layout/images/trans.gif"}).inject(this.previousButtonDiv);
		this.nextButtonDiv = new Element('a').addClass('DivMultiBoxNext').setProperties({id:"DivMultiBoxNext" + this.timeStamp}).setProperties({href: "JavaScript:" + this.variableName + ".next(this)"}).inject(this.contentContainer);
		this.nextButtonImage = new Element('img').addClass('DivMultiBoxNextImg').setProperties({src:"fileadmin/layout/images/trans.gif"}).inject(this.nextButtonDiv);
	
		this.previousButton = new Element('a').addClass('MultiBoxPrevious').setProperties({id:"MultiBoxPrevious"}).setProperties({href: "JavaScript:" + this.variableName + ".previous(this)"}).inject(this.contentContainer);
		this.nextButton = new Element('a').addClass('MultiBoxNext').setProperties({id:"MultiBoxNext"}).setProperties({href: "JavaScript:" + this.variableName + ".next(this)"}).inject(this.contentContainer);
		
		if(this.type != 'flashVideoPlayer')
		{

			if(this.content.length > 1)
			{
				this.contentContainer.addEvents({
					'mouseenter': function(e){		
						//	eval(this.variableName + ".visibleNavButttons('block')");
							this.visibleNavButttons('block');
					}.bind(this),
					'mouseleave': function(e){
	//					  eval(this.variableName + ".visibleNavButttons('none')");
						  this.visibleNavButttons('none');
					}.bind(this)			
					
				});
				this.previousButtonDiv.addEvents({
					'mousemove': function(e){		
					//	eval(this.variableName + ".visibleNavButttons('block')");
					this.nextButton.style.visibility = "hidden";	
					this.previousButton.style.visibility = "visible";	
					this.nextButtonDiv.setStyles({
						//display: 'none',
					    cursor: 'default'
					});
					if(this.index > 0)
					{							
						this.previousButtonDiv.setStyles({
							//display: 'none',
						    cursor: 'pointer'
						});
					}
					else
					{
						this.previousButtonDiv.setStyles({
							//display: 'none',
						    cursor: 'default'
						});
					}
				}.bind(this)			
				});
				
				this.nextButtonDiv.addEvents({
					'mousemove': function(e){		
					//	eval(this.variableName + ".visibleNavButttons('block')");
					this.nextButton.style.visibility = "visible";	
					this.previousButton.style.visibility = "hidden";
					if(this.index < Number(this.content.length)-1){
						this.nextButtonDiv.setStyles({
							//display: 'none',
						    cursor: 'pointer'
						});
					}
					this.previousButtonDiv.setStyles({
						//display: 'none',
					    cursor: 'default'
					});					
				}.bind(this)			
				
			});
				
			/*	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)
					{	
							this.previousButton.addEvents({
						'mouseover': function(e){
							eval(this.variableName + ".visibleNavButttons('block')");
						}.bind(this)
			
						});		
			
					this.nextButton.addEvents({
						'mouseover': function(e){
							eval(this.variableName + ".visibleNavButttons('block')");
						}.bind(this)
			
						});
					}
				}	*/
				
			
			}
		}
		if(this.bolPhotoGallery == true)
		{
			containerHeight = this.contentObj.style.height.replace("px","");
			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 = this.contentContainer.style.height.replace("px","");
					containerHeight = containerHeight - this.actImageHeight;
//An dieser Stelle kann bei Flash Inhalten ein Fehler entstehen					
					if(this.type == "image") 
					{
						if(this.actImageHeight > 0)
							this.contentObj.style.marginTop = (containerHeight/2) + "px";
						else
							this.contentObj.style.marginTop = "0px";
					}
				}
			}
			
		}		
		
		
		if(this.type == 'image'){			
			this.contentObj.setProperties({id:"image" + this.timeStamp}).addClass('imageStyle').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: $('MultiBoxContentContainer'),
				autoCancel: true
			}).get(this.contentObj.url);
			
		}else{
			var obj = this.createEmbedObject().injectInside(this.contentContainer);
			if(this.str != ''){
				if(this.str.indexOf("<object") != -1)
				{
					$('MultiBoxMediaObject').innerHTML = this.str;
				}
				else
				{
					eval(this.str);					
				}
			}
		}
		

		
		this.contentEffects = new Fx.Morph(this.contentContainer, {duration: 500, transition: Fx.Transitions.linear});
		this.contentEffects.start({
			opacity: 1
		});
		this.title.set('html', this.getTitleToElement(this.contentToLoad.title));
		if((this.content.length > 1)  && (this.type != 'flashVideoPlayer')){
			this.number.set('html', this.contentToLoad.number+' / '+ this.content.length);
		}else{
			this.number.set('html','');
		}
		if (this.options.descClassName) {
			/*if (this.description.getFirst()) {
				this.description.getFirst().destroy();
			}
			if(this.contentToLoad.desc){
				this.contentToLoad.desc.inject(this.description).setStyles({
					display: 'block'
				});
			}*/
		}
		//this.removeContent.bind(this).delay(500);
		if (this.options.showControls) {
			if(this.contentToLoad.title != '&nbsp;' || this.content.length > 1){
				this.timer = this.showControls.bind(this).delay(800);
			}
		}
		this.contentObj.width = markWidth;
		this.contentObj.height = markHeight;
		
	},

	getTitleToElement: function(id)
	{
		////console.log("13");

		obj = $(id); 
		if(obj != null)
		{
			this.markTextPageId = id;
			return obj.innerHTML;
		}
		else
		{
			return null;
		}
	},
	
	visibleNavButttons: function(visibility)
	{
		////console.log("14");

			if(visibility == "none")
			{
	//			this.lightBoxMouseOver = "false";	
	//			window.setTimeout(eval(this.variableName + ".hideNavButttonsDelay()"), 500);
				$("MultiBoxNext").style.visibility = "hidden";
				$("MultiBoxPrevious").style.visibility = "hidden";
				this.nextButtonDiv.setStyles({
					//display: 'none',
				    cursor: 'default'
				});
				this.previousButtonDiv.setStyles({
					//display: 'none',
				    cursor: 'default'
				});
			}
			else
			{
				ImageHeight = $("image" + this.timeStamp).getHeight();
				containerHeight = this.contentContainer.style.height.replace("px","");
				////console.log("start event")
				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)
					{	
						ImageHeight = containerHeight;
					}
				}
				if(ImageHeight > containerHeight)
				{
					containerHeight = ImageHeight;
				}
				
				arrowPos = (containerHeight / 2)-18;
				this.nextButton.style.right = "0px";
				this.nextButton.style.top = arrowPos + "px";
				
				this.previousButton.style.left = "0px";
				this.previousButton.style.top = arrowPos + "px";
				////console.log("end event")
				if(this.index < Number(this.content.length)-1){
					this.nextButtonDiv.setStyles({
					    cursor: 'pointer'
					    //display: 'block'
					});
				}
				if(this.index > 0){
					this.previousButtonDiv.setStyles({
					    cursor: 'pointer'
					   // display: 'block'	
					});
				}
				//$("MultiBoxNext").style.visibility = "visible";
				//$("MultiBoxPrevious").style.visibility = "visible";
			}
	},
	
	hideNavButttonsDelay: function()
	{
		////console.log("15");

		if(this.lightBoxMouseOver == "false")
		{
			document.getElementById("MultiBoxNext").style.right = "3000px";
			document.getElementById("MultiBoxPrevious").style.left = "-3000px";
		}
	},
	
	previousTextMessage: function()
	{
		////console.log("16");

		id = this.markTextPageId;
		ipos = id.lastIndexOf("_");
		nr = id.substring(ipos+1,id.length);
		nr = Number(nr);
		nr--;
		if(nr == 0)
		{
			this.previousTextButton.setStyles({
				'display': 'none'
			});			
		}
		if(this.textPageSize > 1)
		{
			this.nextTextButton.setStyles({
				'display': 'none'
			});	
		}
		id = id.substring(0,ipos) + "_" + nr;
		this.title.set('html', this.getTitleToElement(id));
		
	},

	nextTextMessage: function()
	{
		////console.log("17");

		id = this.markTextPageId;
		ipos = id.lastIndexOf("_");
		nr = id.substring(ipos+1,id.length);
		nr = Number(nr);
		nr++;
		if(nr+1 == this.textPageSize)
		{
			this.nextTextButton.setStyles({
				'display': 'none'
			});				
		}
		if(this.textPageSize > 1)
		{
			this.previousTextButton.setStyles({
				'display': 'none'
			});	
		}
		id = id.substring(0,ipos) + "_" + nr;
		this.title.set('html', this.getTitleToElement(id));
	},
	
	textMessageSize: function()
	{
		////console.log("18");

		id = this.contentToLoad.title;
		ipos = id.lastIndexOf("_");
		for(i = 1; i < 50;i++)
		{
			id = id.substring(0,ipos) + "_" + i;
			if($(id) == null)
			{
				this.textPageSize = i;
				break;
			}
		}
		if(this.textPageSize == 1)
		{
			this.previousTextButton.setStyles({
				'display': 'none'
			});			
			this.nextTextButton.setStyles({
				'display': 'none'
			});	
		}
		else
		{
			if(this.textPageSize > 1)
			{
				this.nextTextButton.setStyles({
					'display': 'none'
				});	
				this.previousTextButton.setStyles({
					'display': 'none'
				});					
			}
		}
		obj = $(this.contentToLoad.title); 
		if(obj != null)
		{
			if(obj.innerHTML.length > 1)
			{
				this.controls.style.height = "153px";			
			}
			else
			{
				this.controls.style.height = "29px";			
			}
		}
		else
		{
			this.controls.style.height = "29px";			
		}
	},
	
	hideContent: function(){
		////console.log("19");

		//eval("this." + this.variableName).addClass('MultiBoxLoading');
		this.contentEffects.start({
			opacity: 0
		});
		this.removeContent.bind(this).delay(500);
	},
	
	removeContent: function(){
		////console.log("20");

		if($('MultiBoxMediaObject')){
			//$('MultiBoxMediaObject').empty();
			//$('MultiBoxMediaObject').destroy();
		}
		if($('MultiBoxContentContainer')){
			//$('MultiBoxContentContainer').empty();
			$('MultiBoxContentContainer').destroy();	
		}
	},
	
	showControls: function(){
		////console.log("21");

		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({
			//'backgroundColor': this.controls.getStyle('backgroundColor'),
			'height': 'auto'
		});
		
		if(this.content.length > 1){
			this.previousButtonDiv.setStyles({
				//display: 'none',
			    cursor: 'default'
			});
			this.nextButtonDiv.setStyles({
				//display: 'none',
			    cursor: 'default'
			});
			
			this.previousButton.setStyle('visibility', 'hidden');
			this.nextButton.setStyle('visibility', 'hidden');
			this.title.setStyle('margin-left', this.titleMargin);
			
			if(this.contentToLoad.number == 1){
				this.previousButton.className = 'MultiBoxPreviousDisabled';
			}else{
				this.previousButton.removeClass('MultiBoxPreviousDisabled');
			}
			if(this.contentToLoad.number == this.content.length){
				this.nextButton.className = 'MultiBoxNextDisabled';
			}else{
				this.nextButton.removeClass('MultiBoxNextDisabled');
			}
		}else{
			this.previousButton.setStyle('visibility', 'hidden');
			this.nextButton.setStyle('visibility', 'hidden');
			this.previousButtonDiv.setStyles({
				//display: 'none',
			    cursor: 'default'
			});
			this.nextButtonDiv.setStyles({
				//display: 'none',
			    cursor: 'default'
			});
			this.title.setStyle('margin-left', 0);
		}
		if(this.textPageSize >= 1)
		{
			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();
		}

	},
	
	hideControls: function(num){
		////console.log("22");

		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(){
		////console.log("23");

	},
	
	next: function(thisBox){
		////console.log("24");

		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(){
		////console.log("25");

		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(){
		////console.log("26");

		if(this.type == 'flashVideoPlayer'){
			////console.log("flashVideoPlayer")
			var url = this.contentObj.url;
			
			var obj = new Element('div').setProperties({id: 'MultiBoxMediaObject'});
			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 = "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 = "MultiBoxMediaObject";';
			strExternalAttributes = this.getExternalAttributes();
			if(strExternalAttributes != "")
				this.str += strExternalAttributes;
			this.str += 'swfobject.embedSWF("fileadmin/layout/flash/AS_VideoPlayer.swf?2010090701", "MultiBoxMediaObject", "' + this.contentObj.width + '","' + this.contentObj.height + '", "9.0.0", "expressInstall.swf", flashvars, params, attributes);';
		}
		
		if(this.type == 'flash'){
			var url = this.contentObj.url;
			iPos = this.strMovie.lastIndexOf("/");
			var obj = new Element('div').setProperties({id: 'MultiBoxMediaObject'});
			this.str = 'var flashvars = {};';
			strExternalFlashVars = this.getExternalFlashVars();
			if(strExternalFlashVars != "")
				this.str += strExternalFlashVars;
			if(iPos != -1)
				this.str += 'flashvars.path = "' + this.strMovie.substring(0,iPos) + '";';
			this.str += 'var params = {};';
			this.str += 'params.lang = "' +  this.strLanguage + '";';	
			strExternalParams = this.getExternalParams();
			if(strExternalParams != "")
				this.str += strExternalParams;
			
			this.str += 'var attributes = {};';
			this.str += 'attributes.id = "MultiBoxMediaObject";';
			strExternalAttributes = this.getExternalAttributes();
			if(strExternalAttributes != "")
				this.str += strExternalAttributes;			
			this.str += 'swfobject.embedSWF("' + this.strMovie + '", "MultiBoxMediaObject", "' + this.contentObj.width + '","' + this.contentObj.height + '", "9.0.0", "expressInstall.swf", flashvars, params, attributes);';

		}	
		
		if(this.type == 'youtube'){
			var url = this.contentObj.url;
			
			var obj = new Element('div').setProperties({id: 'MultiBoxMediaObject'});
			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="'+this.contentObj.height+'" ';
			this.str += 'title="MultiBoxMedia">';
  			this.str += '<param name="movie" value="'+url+'" />'
  			this.str += '<param name="quality" value="high" />';
  			this.str += '<param name="allowFullScreen" value="true"></param>';
  			this.str += '<embed src="'+url+'" ';
  			this.str += 'quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" ';
  			this.str += 'allowfullscreen="true" ';
  			this.str += 'width="'+this.contentObj.width+'" ';
  			this.str += 'height="'+this.contentObj.height+'"></embed>';
			this.str += '</object>';
			
		}
		
		if(this.type == 'flashVideo'){
			//var url = this.contentObj.url.substring(0, this.contentObj.url.lastIndexOf('.'));
			var url = this.contentObj.url;
			
			var obj = new Element('div').setProperties({id: 'MultiBoxMediaObject'});
			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="MultiBoxMedia">';
  			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="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 += 'FlashVars="path='+url+'"';
  			this.str += '></embed>';
			this.str += '</object>';
			
		}
		
		if(this.type == 'flashMp3'){
			var url = this.contentObj.url;
			
			var obj = new Element('div').setProperties({id: 'MultiBoxMediaObject'});
			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="'+this.contentObj.height+'" ';
			this.str += 'title="MultiBoxMedia">';
  			this.str += '<param name="movie" value="'+this.options.path+'mp3player.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="FlashVars" value="path='+url+'" />';
  			this.str += '<embed src="'+this.options.path+'mp3player.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="'+this.contentObj.height+'"';
  			this.str += 'salign="TL" ';
  			this.str += 'scale="noScale" ';
  			this.str += 'FlashVars="path='+url+'"';
  			this.str += '></embed>';
			this.str += '</object>';
		}
		
		if(this.type == 'quicktime'){
			var obj = new Element('div').setProperties({id: 'MultiBoxMediaObject'});
			this.str = '<object  type="video/quicktime" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab"';
			this.str += ' width="'+this.contentObj.width+'" height="'+this.contentObj.height+'">';
			this.str += '<param name="src" value="'+this.contentObj.url+'" />';
			this.str += '<param name="autoplay" value="true" />';
			this.str += '<param name="controller" value="true" />';
			this.str += '<param name="enablejavascript" value="true" />';
			this.str += '<embed src="'+this.contentObj.url+'" autoplay="true" pluginspage="http://www.apple.com/quicktime/download/" width="'+this.contentObj.width+'" height="'+this.contentObj.height+'"></embed>';
			this.str += '<object/>';
			
		}
		
		if(this.type == 'windowsMedia'){
			var obj = new Element('div').setProperties({id: 'MultiBoxMediaObject'});
			this.str = '<object  type="application/x-oleobject" classid="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112"';
			this.str += ' width="'+this.contentObj.width+'" height="'+this.contentObj.height+'">';
			this.str += '<param name="filename" value="'+this.contentObj.url+'" />';
			this.str += '<param name="Showcontrols" value="true" />';
			this.str += '<param name="autoStart" value="true" />';
			this.str += '<embed type="application/x-mplayer2" src="'+this.contentObj.url+'" Showcontrols="true" autoStart="true" width="'+this.contentObj.width+'" height="'+this.contentObj.height+'"></embed>';
			this.str += '<object/>';
			
		}
		
		if(this.type == 'real'){
			var obj = new Element('div').setProperties({id: 'MultiBoxMediaObject'});
			this.str = '<object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA"';
			this.str += ' width="'+this.contentObj.width+'" height="'+this.contentObj.height+'">';
			this.str += '<param name="src" value="'+this.contentObj.url+'" />';
			this.str += '<param name="controls" value="ImageWindow" />';
			this.str += '<param name="autostart" value="true" />';
			this.str += '<embed src="'+this.contentObj.url+'" controls="ImageWindow" autostart="true" width="'+this.contentObj.width+'" height="'+this.contentObj.height+'"></embed>';
			this.str += '<object/>';
			
		}
		
		return obj;
	},
	
	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,bolPhotoGallery,flashImage,language,type,params,flashvars,attributes)
	{
		//////console.log("resizeContent")
		////console.log("27");

		this.fixedWidth = width;
		this.fixedHeight = height;

		this.contentObj.width = width;
		this.contentObj.height = height;
		this.bolPhotoGallery = bolPhotoGallery;		
		this.flashImage = flashImage;
		this.strLanguage = language;
		this.strType = type;
		if(params != null)
			this.params = params;
		if(flashvars != null)
			this.flashvars = flashvars;
		if(attributes != null)
			this.attributes = attributes;
		if(document.getElementById("MultiBoxMediaObject") != null)
		{
			document.getElementById("MultiBoxMediaObject").style.display = "none";
			this.resize();
		}
		this.strMovie = movie;
	}	
	
});
multiBox.implement(new Options);
multiBox.implement(new Events);


function clickOnTeaser(clickID)
{
  var fireOnThis = document.getElementById(clickID)
  if (document.createEvent)
  {
    var evObj = document.createEvent('MouseEvents')
    evObj.initEvent( 'click', true, false )
    fireOnThis.dispatchEvent(evObj)
  }
  else 
  {
	  if (document.createEventObject)
	  {
	    fireOnThis.fireEvent('onclick');
 	  }
  }
} 	

