var descBox = 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: function(){}, _onClose: function(){}, openFromLink: true //relativeToWindow: true }; }, initialize: function(className, options){ this.setOptions(this.getOptions(), options); this.openClosePos = {}; this.timer = 0; this.contentToLoad = {}; this.index = 0; this.opened = false; this.contentObj = {}; this.containerDefaults = {}; this.createArray = []; 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.container = new Element('div').addClass('DescBoxContainer').inject(this.options.container); // this.box1 = new Element('div').addClass('DescBox1').inject(this.container); // this.box2 = new Element('div').addClass('DescBox2').inject(this.box1); /* this.iframe = new Element('iframe').setProperties({ 'id': 'descBoxIframe', 'name': 'descBoxIframe', '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('DescBoxContent').inject(this.container); this.closeButton = new Element('div').addClass('DescBoxClose').inject(this.container).addEvent('click', this.close.bind(this)); this.content = $$('.db'); this.content.each(function(el,i){ el.index = i; el.addEvent('click', function(e){ 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}); /* var _this=this; this.containerEffects.addEvent('onComplete',function(){ if(_this.overlay) _this.overlay.setHeight(); }); */ // this.iframeEffects = new Fx.Morph(this.iframe, {duration: 400, transition: Fx.Transitions.Sine.easeInOut}); this.reset(); }, setContentType: function(link){ 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 = 'ajax'; // } 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; } this.type = 'ajax'; }, reset: function(){ this.container.setStyles({ 'opacity': 0, 'display': 'none' }); this.removeContent(); 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()+64; 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.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){ 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; } 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); (function(){this.overlay.position();}).delay(1500,this); }else{ 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 = 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 || ' ', desc: desc, number: index+1 }; }, close: function(){ if(this.options.overlay){ this.overlay.hide(); } this.hideContent(); this.containerEffects.cancel(); this.zoomOut.bind(this).delay(500); this.options._onClose(); }, 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); }, load: function(index){ this.box.addClass('DescBoxLoading'); this.getContent(index); this.resize(); }, resize: function(){ if(this.tempSRC != this.contentObj.src){ var border = this.container.getStyle('border').toInt()+64; if (this.options.fixedTop) { var top = this.options.fixedTop; } else { var top = ((window.getHeight() / 2) - ((this.container.getSize().y + this.contentObj.xH) / 2) -32 + window.getScrollTop()) + this.options.offset.y; } var left = ((window.getWidth() / 2) - (this.container.getSize().x/2)) + this.options.offset.x; if (top < 0) { top = 0 } 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.iframeEffects.start({ width: Number(this.contentObj.width) + (border*2), height: Number(this.contentObj.height) + this.contentObj.xH + (border*2) }); */ this.timer = this.showContent.bind(this).delay(500); this.tempSRC = this.contentObj.src; } }, showContent: function(){ this.tempSRC = ''; this.box.removeClass('DescBoxLoading'); this.removeContent(); this.contentContainer = new Element('div').setProperties({id: 'DescBoxContentContainer'}).setStyles({opacity: 0}).inject(this.box); var _this=this; new Request.HTML({ method:'get', url:_this.contentObj.url, onSuccess:function(tree,els,html,js){ $('DescBoxContentContainer').set('html',html); $$('#DescBoxContentContainer a').each(function(el){ el.addEvent('click',function(e){ e.stop(); window.open(this.href,'_blank'); return false; }); }); } }).send(); this.contentEffects = new Fx.Morph(this.contentContainer, {duration: 500, transition: Fx.Transitions.linear}); this.contentEffects.start({ opacity: 1 }); }, hideContent: function(){ this.box.addClass('DescBoxLoading'); this.contentEffects.start({ opacity: 0 }); this.removeContent.bind(this).delay(500); }, removeContent: function(){ if($('DescBoxMediaObject')){ $('DescBoxMediaObject').empty(); $('DescBoxMediaObject').destroy(); } if($('DescBoxContentContainer')){ $('DescBoxContentContainer').destroy(); } } }); descBox.implement(new Options); descBox.implement(new Events);