/**************************************************************

	Script		: MultiBox
	Version		: 1.3.1
	Authors		: Samuel Birch (modified by Liam Smart for MooTools 1.2)
	Desc		: Supports jpg, gif, png, flash, flv, mov, wmv, mp3, html, iframe
	Licence		: Open Source MIT Licence
	Modified	: Leonardo Di Lella (leonardo@dilella.org) - MooTools 1.2 support
				: Liam Smart (liam_smart@hotmail.com)
				: Erik Damiano (trashfake@gmail.com) Diaporama functionnality + better resize + better flash player
	Usage		: window.addEvent('domready', function(){
					  if($$('.mb').length > 0)//only triggered if 'mb' class found on page
					  {
						  var initMultiBox = new multiBox('mb', {
							  descClassName: 'multiBoxDesc',//the class name of the description divs
							  path: 'Flash/',//path to mp3 and flv players
							  useOverlay: true,//use a semi-transparent background. default: false;
							  maxWidth: 600,//max width (set to false to disable)
							  maxHeight: 400,//max height (set to false to disable)
							  addRollover: true,//add rollover fade to each multibox link
							  addOverlayIcon: true,//adds overlay icons to images within multibox links
							  addChain: true,//cycle through all images fading them out then in
							  recalcTop: true//subtract the height of controls panel from top position
						  });
					  }
				  });

**************************************************************/
var MultiBox = new Class({
	
	getOptions: function(){
		return {
			initialWidth: 200,
			initialHeight: 200,
			container: document.body,
			useOverlay: true,
			contentColor: '#fff',
			showNumbers: true,
			showControls: true,
			waitDuration: 2000,
			descClassName: false,
			movieWidth: 400,
			movieHeight: 300,
			offset: {x:0, y:0},
			fixedTop: false,
			fixedLeft: false,
			path: 'flash/',
			openFromLink: true,
			relativeToWindow: true,
			rewriterule: false,
			autostart:false,
			autoload:false,
			diaporama:false,
			addChain:true,
			addOverlayIcon:false,
			addRollover:true,
			tipjar:true,
			sharing:true,
			site:'',
			_onOpen: $empty,
			_onClose: $empty
		};
	},

	initialize: function(className, options){
		this.setOptions(this.getOptions(), options);
		
		if (this.options.site == '') {
			this.site = 'http://' + document.domain + '/';
		}

		this.logopp = this.site + 'images/logopp.png';
		this.skin = this.site + 'flash/kleur.swf';
		this.email = "lepetitcowboylasso@gmail.com";

		this.openClosePos = {};
		this.timer = 0;
		this.contentToLoad = {};
		this.index = 0;
		this.opened = false;
		this.contentObj = {};
		this.containerDefaults = {};
		this.content = $$('.'+className);
		this.shortdesc='';
		this.utf8title = '';
		
		if(this.options.useOverlay){
			this.overlay = new Overlay({container: this.options.container, onClick:this.close.bind(this)});
		}
		
		//only if overlay is enabled in the top settings (liam)
		if(this.options.addOverlayIcon == true){
			this.addOverlayIcon(this.content);
		}
		
		//only if addRollover is enabled in the top settings (liam)
		if(this.options.addRollover == true){
			this.addRollover(this.content);
		}
		
		//only if startChain is enabled in the top settings (liam)
		if(this.options.addChain == true){
			this.addChain(this.content);
		}

		this.autostart = this.options.autostart;

		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').inject(this.options.container,'inside');
		this.iframe = new Element('iframe').setProperties({
			'id': 'multiBoxIframe',
			'name': 'mulitBoxIframe',
			'src': 'javascript:void(0);',
			'frameborder': 0,
			'scrolling': 'no'
		}).setStyles({
			'position': 'absolute',
			'top': '0',
			'left': '0',
			'width': '100%',
			'height': '100%',
			'filter': 'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)',
			'opacity': 0
		}).inject(this.container,'inside');
		this.box = new Element('div').addClass('MultiBoxContent').inject(this.container,'inside');
		
		if (this.options.diaporama) {
			this.playButton = new Element('div').addClass('MultiBoxPlay').inject(this.container,'inside').addEvent('click', this.toggleDiaporama.bind(this));
		}

		this.closeButton = new Element('div').addClass('MultiBoxClose').inject(this.container,'inside').addEvent('click', this.close.bind(this));
		
		this.controlsContainer = new Element('div').addClass('MultiBoxControlsContainer').inject(this.container,'inside');
		this.controls = new Element('div').addClass('MultiBoxControls').inject(this.controlsContainer,'inside');
		
		this.previousButton = new Element('div').addClass('MultiBoxPrevious').inject(this.controls,'inside').addEvent('click', this.previous.bind(this));
		this.nextButton = new Element('div').addClass('MultiBoxNext').inject(this.controls,'inside').addEvent('click', this.next.bind(this));
		
		this.title = new Element('div').addClass('MultiBoxTitle').inject(this.controls,'inside');
		this.number = new Element('div').addClass('MultiBoxNumber').inject(this.controls,'inside');
		this.description = new Element('div').addClass('MultiBoxDescription').inject(this.controls,'inside');
		
		if(this.content.length == 1){
			this.title.setStyles({
				'margin-left': 0
			});
			this.description.setStyles({
				'margin-left': 0
			});
			this.previousButton.setStyle('display', 'none');
			this.nextButton.setStyle('display', 'none');
			if (this.options.diaporama) {
				this.playButton.setStyle('display', 'none');
			}
			this.number.setStyle('display', 'none');
		}
		
		new Element('div').setStyle('clear', 'both').inject(this.controls,'inside');
		
		this.content.each(function(el,i){
			el.hrefCopy = el.href;
			el.index = i;
			el.addEvent('click', function(e){
				new Event(e).stop();
				this.open(el);
			}.bind(this));
		}, this);
		
		this.containerEffects = new Fx.Morph(this.container, {duration: 400});
		this.controlEffects = new Fx.Morph(this.controlsContainer, {duration: 300});
		
		this.reset();
		
		if (this.options.autoload == true && this.content.length) {
			this.content[0].fireEvent("click", this.content[0]);
		}
	},
	
	setContentType: function(link){
		this.shortDescription = "";
		this.utf8title = link.title;

		if (this.options.rewriterule == true) {
			link.xhr_object = null;

			if(window.XMLHttpRequest) // Firefox
			   link.xhr_object = new XMLHttpRequest();
			else if(window.ActiveXObject) // Internet Explorer
			   link.xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
			else { // XMLHttpRequest non supporté par le navigateur
			   alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
			   return;
			}
		
			link.xhr_object.open("GET", this.site+"rewriterule.php?multibox=true&href="+link.href, false);
			link.xhr_object.send(null);
			aInformations = link.xhr_object.responseText.split('##');
			link.hrefCopy = aInformations[0];
			this.utf8title = aInformations[1];
			this.shortDescription = aInformations[2];
		}
		
		if($chk(link.hrefCopy)){
			var hrefArray = link.hrefCopy.split('?');
			link.hrefReal=hrefArray[0];
			link.relReal=hrefArray[1];
			
			if(link.hrefCopy.indexOf('#') > -1){
				var hrefArray2 = link.hrefReal.split('#');
				link.hrefReal=hrefArray2[0];
				link.content = $(hrefArray2[1]);
				if(link.content){
					link.content.setStyle('display','none');
				}
			}
		}
		
		var str = link.hrefReal.substr(link.hrefReal.lastIndexOf('.')+1).toLowerCase();

		var contentOptions = {};
		if($chk(link.relReal)){
			var optArr = link.relReal.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.hrefReal;
		this.contentObj.urlNotRewrited = 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;
		}
		if(contentOptions.miniature){
			this.contentObj.miniature = contentOptions.miniature;
		}else{
			this.contentObj.miniature = this.options.miniature;
		}
		

		this.hdon = false;
		switch(str){
			case 'jpg':
			case 'gif':
			case 'png':
				this.type = 'image';
				break;
			case 'swf':
				this.type = 'flash';
				break;
			case 'flv':
				this.type = 'flashVideo';
				this.contentObj.xH = 0;
				break;
			case 'mp4'://to support mp4 format (code from phatfusion forum - liam)
			case 'f4v':
			    this.hdon = true;
				this.type = 'flashVideo';
				this.contentObj.xH = 0;
				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.elementContentCssId = link.content.getProperty('id');
				this.elementContent.setStyles({
					display: 'block',
					opacity: 0,
					width: 'auto'//added this to get htmlElement to behave (liam)
				});
	
				if(this.elementContent.getStyle('width') != 'auto'){
					this.contentObj.width = this.elementContent.getSize().x;
				}
				
				this.contentObj.height = this.elementContent.getSize().y;
				this.elementContent.setStyles({
					display: 'none',
					opacity: 1
				});
				break;
				
			default:
				
				this.type = 'iframe';
				if(contentOptions.req){
					this.type = 'req';
				}
				break;
		}
		
		this.contentObj.urlHD = this.contentObj.url;

		if (this.hdon) {
			this.contentObj.url = this.contentObj.url.substring(0, this.contentObj.url.lastIndexOf(str)) + "flv";
		}
	},
	
	reset: function(){
		this.container.setStyles({
			'opacity': 0,
			'display': 'none'
		});
		
		this.controlsContainer.setStyles({
			'height': 0
		});
	
		this.removeContent();
		this.previousButton.removeClass('MultiBoxButtonDisabled');
		this.nextButton.removeClass('MultiBoxButtonDisabled');
		this.isPlaying = false;
		this.resetDiaporama();
		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{
			if(this.options.fixedTop){
				var top = this.options.fixedTop;
			}else{
				var top = ((window.getHeight()/2)-(this.options.initialHeight/2)-this.container.getStyle('border').toInt())+ window.getScrollTop() + this.options.offset.y;
			}
			if(this.options.fixedLeft){
				var left = this.options.fixedLeft;
			}else{
				var left = ((window.getWidth()/2)-(this.options.initialWidth/2)-this.container.getStyle('border').toInt())+this.options.offset.x;
			}
		if (top <= window.getScrollTop()+10){
			top = window.getScrollTop()+10;
			}
			if (left < 0){
				left = 0;
			}

			this.openClosePos = {
				width: this.options.initialWidth,
				height: this.options.initialHeight,
				top: top,
				left: left
			}
		}
		return this.openClosePos;
	},
	
	open: function(el){
	
		this.options._onOpen();
	
		this.index = this.content.indexOf(el);
		
		this.openId = el.getProperty('id');
		
		if(!this.opened){
			this.opened = true;
			
			if(this.options.useOverlay){
				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)-this.container.getStyle('border').toInt())+ window.getScrollTop() + this.options.offset.y;
			}

			if(this.options.fixedLeft){
				var left = this.options.fixedLeft;
			}else{
				var left = ((window.getWidth()/2)-(this.options.initialWidth/2)-this.container.getStyle('border').toInt())+this.options.offset.x;
			}
			
		if (top <= window.getScrollTop()+10){
			top = window.getScrollTop()+10;
		}
		if (left < 0){
			left = 0;
		}

			this.containerEffects.start({
				width: this.options.initialWidth,
				height: this.options.initialHeight,
				top: top,
				left: left,
				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);
			
		}
		
	},
	
	getContent: function(index){
		this.setContentType(this.content[index]);
		var desc = {};
		if(this.options.descClassName){
			this.descriptions.each(function(el,i){
				if(el.hasClass(this.openId)){
					desc = el.clone(true, true);
				}
			},this);
		}

		this.contentToLoad = {
			title: this.content[index].title || '&nbsp;',
			desc: desc,
			number: index+1
		}
	},
	
	resetDiaporama:function () {
		if ((this.options.diaporama == true) && (this.isPlaying == true)) {
			$clear(this.periodicalNext);
			this.playButton.removeClass('MultiBoxPause');
			this.isPlaying = false;
		}
	},
	
	toggleDiaporama:function() {
		if(this.isPlaying == false){
			this.playButton.addClass('MultiBoxPause');
			this.isPlaying = true;
			this.periodicalNext = this.next.periodical(4000, this);
		} else{
			this.resetDiaporama();
		}
	},

	close: function(){
		if(this.options.useOverlay){
			this.overlay.hide();
		}
		if (this.options.showControls){
			this.hideControls();
		}
		this.hideContent();
		this.containerEffects.cancel();
		this.zoomOut.bind(this).delay(500);
		this.options._onClose();
		this.resetDiaporama();
	},
	
	zoomOut: function(){
		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);
	},
	
	load: function(index){
		this.box.addClass('MultiBoxLoading');
		this.getContent(index);
		if(this.type == 'image'){
			var xH = this.contentObj.xH;
			this.contentObj = new Asset.image(this.content[index].hrefReal, {'onload':this.resize.bind(this), 'onerror':this.blankimage.bind(this)});
			this.contentObj.xH = xH;
		}else{
			this.resize();
		}
		this.onLoadMultibox(this.content[index].hrefReal, index+1);
	},
	
//	onLoad:function (url, index){},
	
	blankimage: function () {
		this.content[this.index].hrefCopy = this.site+'css/images/unavailable.png';
		this.index--;
		this.next();
	},
	
	resize: function(){
		if (this.type == 'image')
		{
			tempRatio = this.contentObj.width/this.contentObj.height;
				
			if ((this.contentObj.height+this.contentObj.xH) > (window.getHeight() - (2 * this.container.getStyle('border').toInt()))){
				this.contentObj.height = window.getHeight() - (2 * this.container.getStyle('border').toInt()) - 150 - this.contentObj.xH;
				if (this.contentObj.height <= 0) 
				{
					this.contentObj.height = window.getHeight() - (2 * this.container.getStyle('border').toInt()) - 20 - this.contentObj.xH;
				}
				if (this.contentObj.height <= 0) 
				{
					this.contentObj.height = window.getHeight() - this.contentObj.xH - 20;
				}
				this.contentObj.width = this.contentObj.height * tempRatio;
			}

			if (this.contentObj.width > (window.getWidth()-20))	{
				this.contentObj.width = window.getWidth() - 20;
				this.contentObj.height = this.contentObj.width / tempRatio;
			}
		}
		
		if (this.options.fixedTop){
			var top = this.options.fixedTop;
		}
		else {
			var top = (window.getHeight() - Number(this.contentObj.height) - this.contentObj.xH) / 2 - this.container.getStyle('border').toInt() + window.getScrollTop() + this.options.offset.y;
		}

		if(this.options.fixedLeft){
			var left = this.options.fixedLeft;
		}else{
			var left = (window.getWidth() - this.contentObj.width) / 2 - this.container.getStyle('border').toInt() + this.options.offset.x;
		}

		if (top <= window.getScrollTop()+10){
			top = window.getScrollTop()+10;
		}
		if (left < 0){
			left = 0;
		}
		
		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.timer = this.showContent.bind(this).delay(500);
	},
	
	showContent: function(){
		this.box.removeClass('MultiBoxLoading');
		this.removeContent();

		this.contentContainer = new Element('div').setProperties({id: 'MultiBoxContentContainer'}).setStyles({opacity: 0, width: this.contentObj.width+'px', height: (Number(this.contentObj.height)+this.contentObj.xH)+'px'}).inject(this.box,'inside');
		
		if(this.type == 'image'){
			this.contentObj.inject(this.contentContainer,'inside');
		}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+'?multibox=true',
				frameborder: 0,
				scrolling: 'auto'
			}).inject(this.contentContainer,'inside');
		}else if(this.type == 'htmlelement'){
			var elementContentClone = this.elementContent.clone().setStyle('display','block').inject(this.contentContainer,'inside');
			elementContentClone.setProperties({id: this.elementContentCssId});
			this.contentObj.width = elementContentClone.getStyle('width');
			this.contentObj.height = elementContentClone.getStyle('height');
			
		}else if(this.type == 'req'){//fixes ajax bug (mootools docs code - liam)
			new Request.HTML({
				update: $('MultiBoxContentContainer'),
				autoCancel: true
			}).get(this.contentObj.url);
		}else if(this.type == 'flashVideo'){//fixes ajax bug (mootools docs code - liam)
			new Element('div').setProperties({
				id: 'MultiBoxMediaObject'
			}).inject(this.contentContainer,'inside');

			getflashplayer = '<a href="http://www.macromedia.com/go/getflashplayer">Get the newest Flash Player </a> to see this player. <br /> <a href="http://www.macromedia.com/go/getflashplayer">Téléchargez le lecteur Flash le plus récent</a> pour voir les vidéos.'; 

			$('MultiBoxMediaObject').set('html', getflashplayer);

			plugs = "";
			plugsEmbed = "";
			sEmbed = "";
			flashvarsTxt = "";
			
			if (this.options.sharing) {
				plugs = this.site+'flash/sharing.swf';
				sEmbed = escape("<embed src='"+this.site+"flash/flvplayer.swf' height='400' width='480' allowscriptaccess='always' allowfullscreen='true' flashvars='file=" + (this.contentObj.url));		
				flashvarsTxt = escape("&bufferlength=5&type=video&&date=0&skin="+ encodeURIComponent(this.skin) +"&displaytitle=true&dock=true&description=0&image=0&pluginIds=");
				sharingvars = escape("&link=0&mediaid=0&streamer=0&author=0&title=0");
				if (this.options.tipjar) {
					plugsEmbed = "tipjar";
					sharingvars += escape("&tipjar.currency_code=EUR&tipjar.cancel_return=0&tipjar.item_name=" + (this.utf8title) + "&tipjar.show_pause=true&tipjar.show_complete=true&tipjar.image_url="+encodeURIComponent(this.logopp)+"&tipjar.return_url=0&tipjar.text=Si%20vous%20avez%20aimé%20cette%20vidéo%20pensez%20à%20soutenir%20son%20auteur%20en%20lui%20faisant%20un%20don%20!%20Mille%20Mercis%20!%20If%20you%20liked%20this%20video%2C%20think%20about%20supporting%20its%20author%20by%20giving%20him%20a%20donation%20!%20Many%20thanks%20!&tipjar.business=" + encodeURIComponent(this.email) + "&tipjar.title=Soutenez-nous%20!%20Support%20us%20!");
				}
				
				if (this.hdon) {
					if (plugsEmbed!="") {
						plugsEmbed+=escape("%2C");;
					}
					
					plugsEmbed += "hd";
					sharingvars += escape("&hd.file=" + (this.contentObj.urlHD ));
				}

				flashvarsTxt += plugsEmbed + sharingvars + escape("&plugins=");
				plugsEmbed="";

				if (this.options.tipjar) {
					plugsEmbed = escape("tipjar-1");
				}

				if (this.hdon) {
					if (plugsEmbed!="") {
						plugsEmbed+=escape("%2C");;
					}
					
					plugsEmbed += escape("hd-1");
				}

				flashvarsTxt += plugsEmbed;
				sEmbed += flashvarsTxt + escape("'/>");
			}
			
			if (this.options.tipjar) {
				if (plugs!= "") {
					plugs+=",";
				}
				
				plugs += "tipjar-1";
			}

			if (this.hdon) {
				if (plugs!="") {
					plugs+=",";
				}
				
				plugs += "hd-1";
				var flashvars = {
					'dock':'true',
					'title':this.utf8title,
					'plugins':plugs,
					'skin':this.skin,
					'hd.file':this.contentObj.urlHD,
					'sharing.code':sEmbed,
					'sharing.link':this.contentObj.urlNotRewrited,
					'sharing.fbdesc': this.shortDescription,
					'sharing.fbfile':this.contentObj.url,
					'sharing.fbflashvars':flashvarsTxt, 
					'tipjar.title':'Soutenez-nous ! Support us !',
					'tipjar.text':'Si vous avez aimé cette vidéo pensez à soutenir son auteur en lui faisant un don ! Mille Mercis ! If you liked this video, think about supporting its author by giving him a donation ! Many thanks !',
					'tipjar.show_complete':'true',
					'tipjar.business':this.email,
					'tipjar.show_pause':'true',
					'tipjar.currency_code':'EUR',
					'tipjar.return_url':'',
					'tipjar.cancel_return':'',
					'tipjar.image_url':this.logopp,
					'tipjar.item_name':this.utf8title,
					'file':this.contentObj.url
				};
				
				
			}
			else {
				var flashvars = {
					'dock':'true',
					'plugins':plugs,
					'title':this.utf8title,
					'skin':this.skin,
					'sharing.code':sEmbed,
					'sharing.link':this.contentObj.urlNotRewrited,
					'sharing.fbdesc': this.shortDescription,
					'sharing.fbfile':this.contentObj.url,
					'sharing.fbflashvars':flashvarsTxt, 
					'tipjar.title':'Soutenez-nous ! Support us !',
					'tipjar.text':'Si vous avez aimé cette vidéo pensez à soutenir son auteur en lui faisant un don ! Mille Mercis ! If you liked this video, think about supporting its author by giving him a donation ! Many thanks !',
					'tipjar.show_complete':'true',
					'tipjar.business':this.email,
					'tipjar.show_pause':'true',
					'tipjar.currency_code':'EUR',
					'tipjar.return_url':'',
					'tipjar.cancel_return':'',
					'tipjar.image_url':this.logopp,
					'tipjar.item_name': this.utf8title,
					'file':this.contentObj.url
				};
			}
			
			if (this.autostart) {
				flashvars.autostart = "true";
			}

			var params = {};
			params.wmode = "opaque";
			params.allowfullscreen = "true";
			params.allowscriptaccess = "always";
			var attributes = {};
			attributes.id = "mpl";
			attributes.name = "mpl";
			swfobject.embedSWF(String(this.site+this.options.path+'flvplayer.swf'), "MultiBoxMediaObject", String(this.contentObj.width),String(Number(this.contentObj.height)+this.contentObj.xH), "9.0.0", false, flashvars, params, attributes);

		}else{
			var obj = this.createEmbedObject().inject(this.contentContainer,'inside');
			if(this.str != ''){
				$('MultiBoxMediaObject').set('html',this.str);
			}
		}
		
		this.contentEffects = new Fx.Morph(this.contentContainer, {duration: 500});
		this.contentEffects.start({
			opacity: 1
		});
		
		this.title.set('html',this.contentToLoad.title);
		this.number.set('html',this.contentToLoad.number+' of '+this.content.length);
		if(this.options.descClassName){
			if(this.description.getFirst()){
				this.description.getFirst().destroy();
			}
			this.contentToLoad.desc.inject(this.description,'inside').setStyles({
				display: 'block'
			});
		}
		

		if(this.options.showControls){
			this.timer = this.showControls.bind(this).delay(800);
		}

		if ((this.options.diaporama == true) && (this.isPlaying == true)) {
			this.periodicalNext = this.next.periodical(4000, this);		
		}
	},
	
	hideContent: function(){
		this.box.addClass('MultiBoxLoading');
		this.contentEffects.start({
			opacity: 0
		});
		this.removeContent.bind(this).delay(500);
	},
	
	removeContent: function(){
		if($('MultiBoxMediaObject')){
			$('MultiBoxMediaObject').destroy();
		}
		if($('MultiBoxContentContainer')){
			$('MultiBoxContentContainer').destroy();	
		}
	},
	
	showControls: function(){
		this.clicked = false;
		
		if(this.container.getStyle('height') != 'auto'){
			this.containerDefaults.height = this.container.getStyle('height');
			this.containerDefaults.backgroundColor = this.options.contentColor;
			this.options.recalcTop = true;
			//controls box isnt taken into consideration when positioning the container from the top so correct this
			if(this.options.recalcTop == true){
				if(this.container.getStyle('top').toInt() > this.controls.getStyle('height').toInt()/2){
					this.finalResize = new Fx.Morph(this.container,{duration:400});
					var top=this.container.getStyle('top').toInt()-(this.controls.getStyle('height').toInt()/2);
					if (top <= window.getScrollTop()+10){
						top = window.getScrollTop()+10;
					}
					this.finalResize.start({
						top: top +'px'
					});
				}
			}
		}
		
		this.container.setStyles({
			'height': 'auto'
		});

/*		if(this.contentToLoad.number == 1){
			this.previousButton.addClass('MultiBoxPreviousDisabled');
		}else{
			this.previousButton.removeClass('MultiBoxPreviousDisabled');
		}
		if(this.contentToLoad.number == this.content.length){
			this.nextButton.addClass('MultiBoxNextDisabled');
		}else{
			this.nextButton.removeClass('MultiBoxNextDisabled');
		}*/
		
		this.controlEffects.start({'height': this.controls.getStyle('height')});

	},
	
	hideControls: function(num){
		this.controlEffects.start({'height': 0}).chain(function(){
			this.container.setStyles(this.containerDefaults);
		}.bind(this));
	},
	
	showThumbnails: function(){
		
	},
	
	next: function(){
		if ((this.options.diaporama == true) && (this.isPlaying == true)) {
			$clear(this.periodicalNext);
		}
		if(this.index >= this.content.length-1){
			this.index=0;
		} else {
			this.index++;
		}
			this.openId = this.content[this.index].getProperty('id');
			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);
	},
	
	previous: function(){
		if(this.index == 0){
			this.index = this.content.length-1;
		} else {
			this.index--;
		}
			this.openId = this.content[this.index].getProperty('id');
			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(1000);
	},
	
	createEmbedObject: function(){
		if(this.type == 'flash'){
			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="wmode" value="transparent" />';//better way to embed flash(liam)
  			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 += 'width="'+this.contentObj.width+'" ';
  			this.str += 'height="'+this.contentObj.height+'"></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.site+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.site+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;
	},
	addOverlayIcon:function(el){
		//loop through each instance
		el.each(function(el,i){
			//if link contains an image ad overlay
			if(el.getElement('img')){
				//add position:relative to them so that icon is contained
				el.setStyle('position','relative');
					
				//inject a new div that is the overlay icon
				var overlayIcon = new Element('div').inject(el,'inside');
				overlayIcon.addClass('Overlay');
					
				//if not IE6 as IE6 causes too many issues due to lack of PNG support
				if(Browser.Engine.trident4 != true){
					overlayIcon.setStyle('opacity',0);
					overlayIcon.set('tween',{duration:3000,transition:Fx.Transitions.Expo.easeIn}).tween('opacity',1);
				}
			}
		});
	},
	
	addRollover:function(el){
		el.each(function(el,i){
			//if link contains an image ad overlay
			if(el.getElement('img')){
				//add event listener
				el.addEvents({
					'mouseenter': function(){	
						el.getElement('img').set('tween',{duration:200,transition:Fx.Transitions.linear}).tween('opacity',0.5);
					},
					'mouseleave': function(){
						el.getElement('img').set('tween',{duration:400,transition:Fx.Transitions.linear}).tween('opacity',1);
					}
				});
			}
		});
	},
	
	addChain:function(el){
		//create new array to hold all links with images to chain through
		var chainArray = new Array();
		
		//push link into chainArray if it contains an image
		el.each(function(el,i){
			//detect whether link contains image
			if(el.getElement('img')){
				chainArray.push (el);
			}
		});
		
		//now chain through each item in the new array
		chainArray.each(function(el,i){
			//detect whether link contains image
			if(el.getElement('img')){
				//chain through each multibox link that contains an image
				var HoverMe = new Chain();
			 
				var hoverOn = function(){
					el.getElement('img').set('tween',{duration:200,transition:Fx.Transitions.linear}).tween('opacity',0.5);
				}
					
				var hoverOff = function(){
					el.getElement('img').set('tween',{duration:400,transition:Fx.Transitions.linear}).tween('opacity',1);
				}
					 
				HoverMe.chain(hoverOn);
				HoverMe.chain(hoverOff);

				HoverMe.callChain.delay(2000+(i+1)*1000,HoverMe);
				HoverMe.callChain.delay((i+2)*1000,HoverMe);
			}
		});
	}
});

MultiBox.implement(new Options);
MultiBox.implement(new Events);
MultiBox.implement(new Chain);

