scj.headerMenu = {}
scj.flashOverlay = {};
scj.overlay = {};

scj.OverlayLink = new Class({
	Implements : [Options, Events],
	options: {
		type: 'standard',
		eventTrigger: 'click'
	},
	hardTop: null,
	initialize: function (elem, options) {
		this.setOptions(options);
		var reference = this;
		this.source = elem.getProperty('href') || elem.getProperty('source') || false;
		elem.addEvent(this.options.eventTrigger, function(evt) {
			evt.stop();
			reference.triggerOverlay(evt);
			$$('.accordion').each(function(accordion) {
			    accordion.hide();
			});
			
			var trackVars = this.get('trackVars') ? JSON.decode(this.get('trackVars')) : {};
			var linkName = this.get('text');
    		if (options.type == 'product' || options.type == 'video') {
    		    $extend(trackVars, {'prop2': this.get('text'), 'events': 'event5,event18', 'eVar3': this.get('text'), 'eVar13': 'sem_' + this.get('text')});
    		    linkName = scj.omniture.pageDisplayName + '_' + this.get('text');
    		}
            
    		scj.omniture.trackLink(trackVars, {'linkType': 'o', 'linkName': linkName}, this);
		});
		elem.addEvent('mouseenter', function(e) {
		    this.addClass('over');
		});
		elem.addEvent('mouseout', function(e) {
		    this.removeClass('over');
		});
	},
	triggerOverlay: function (event) {
		$(document.body).addClass(this.options.type);
		var type = this.options.type.indexOf('Overlay') !== -1 ? this.options.type : this.options.type + 'Overlay';
		if (scj.overlay[this.options.type] && scj.overlay[this.options.type].trash) scj.overlay[this.options.type].trash();
		scj.overlay[this.options.type] = new scj[type](this.source, this.options);
	}
});

scj.PageOverlay = new Class({
	Implements : [Options, Events],
	options: {
		topOffset: 150,
		fadeContentIn: true,
		targetHeight: 200,
		overlay_bg_opacity: 0.6
	},
	presets : {
		CONTAINER_ID: 'wrapper',
		OVERLAY_BG_CLASSNAME : 'glade_dark_bg overlay',
		CONTENT_OUTER_CONTAINER_CLASSNAME : 'glade_ol_contain overlay',
		CONTENT_INNER_CONTAINER_CLASSNAME : 'glade_ol_content',
		CLOSE_BUTTON_CLASSNAME : 'glade_ol_close',
		LOADING_IMG_CLASSNAME : 'glade_loading',
		LOADING_IMG_URL : 'img/overlay/loadingImg.gif'
	},
	initialize: function (source, options) {
		this.setOptions(options);
		if ($defined(options.source)) {
			this.source = source;
		}
		this.build();
	},
	build: function() {
		var body = document.body;
		this.overlayHolder = $(this.presets.CONTAINER_ID) || body;
		this.overlayBG = new Element('div', {'class': this.presets.OVERLAY_BG_CLASSNAME});
		if (Browser.Engine.name=='trident' && Browser.Engine.version==4) { $$('select').setStyles({'visibility': 'hidden'}); }
        
		this.overlayBGEffect = new Fx.Morph(this.overlayBG, {duration: 400});			
		if (this.source) {
			this.overlayBGEffect.addEvent('onComplete', this.loadContent.bind(this));
		}
		if (window.Browser.Platform.mac && window.Browser.Engine.gecko) {
		    this.hider = {'visibility': 'hidden'};
		    this.showme = {'visibility': 'visible'};
		} else {
		    this.hider = {'opacity': 0}
		    this.showme = {'opacity': 1};
		}
		
		this.overlayBGEffect.set(this.hider);
		this.overlayBG.addEvent('click', this.trash.bind(this));
		this.overlayHolder.adopt(this.overlayBG);
		
		this.overlayContainer= new Element('div', {'class': this.presets.CONTENT_OUTER_CONTAINER_CLASSNAME});
		this.overlayContainerFadeEffect = new Fx.Morph(this.overlayContainer, {duration: 'short'});	
		this.overlayContainerFadeEffect.set(this.hider);
		this.overlayHolder.adopt(this.overlayContainer);

		this.closeButton = new Element('div', {'class': this.presets.CLOSE_BUTTON_CLASSNAME});
		this.closeButton.addEvent('click', this.trash.bind(this));
		this.overlayContainer.adopt(this.closeButton);
		this.overlayContent= new Element('div', {'class': this.presets.CONTENT_INNER_CONTAINER_CLASSNAME});
		if (this.options.eventTrigger == 'mouseenter' || this.options.type == 'scentCollection') {
			var ref = this;
			this.overlayContent.addEvent('mouseleave', function() {
				ref.destroy();
			});
		}
		this.overlayContainer.adopt(this.overlayContent);
		
		if (this.doPosition() == true) {
			window.addEvent('resize', this.doPosition.bind(this));	
		}
		
		if (window.Browser.Platform.name == 'win') {
		    this.overlayBGEffect.start({'opacity': this.options.overlay_bg_opacity});
		} else {
		    this.overlayBG.setStyles(this.showme);
		    this.loadContent();
		}
	},
	createSwf: function() {
		this.swfObject = new SWFObject(this.source + scj.randomize(), this.options.swfId, this.options.swfWidth, this.options.swfHeight, '9', '');
		var so = this.swfObject;
		so.addParam('menu', 'false');
		so.addParam("quality", "best");
		so.addParam("wmode", this.options.swfWmode);
		so.addParam("scale", "noscale");
		so.addParam("allowScriptAccess", "always");
		if (this.options.flashVars) {
			so.addParam("flashVars", this.options.flashVars);
			if (this.options.flashVars.indexOf('berbatov') !== -1) {this.overlayContainer.addClass('videoSwf2');}
			else if (this.options.flashVars.indexOf('.swf') !== -1) {this.overlayContainer.addClass('videoSwf');}
		}
		so.write(this.overlayContent);
	},
	loadContent: function () {
		if (this.source.indexOf('.swf') !== -1) {
			this.handleLoadContent();
			this.createSwf();
		} else if (this.source.indexOf('#') == 0){
			var hashValue = this.source.split('#')[1];
			this.overlayContent.adopt($(hashValue).clone());
			sIFR.activate(scj.fonts.Dakota);
			sIFR.replace(scj.fonts.Dakota, {
				selector: '.' + this.presets.CONTENT_INNER_CONTAINER_CLASSNAME + ' .overlayContent h1',
				wmode: 'transparent',
				preventWrap: 'true',
				css: [
	      			'.sIFR-root {cursor: pointer; font-size: 18px; color:#000;}'
	      		]
			});
			this.handleLoadContent();
		} else {
			this.overlayContent.load(this.source);
			this.handleLoadContent();
		}
		
	},
	handleLoadContent : function () {
		this.fadeOverlay();
	},
	fadeOverlay: function() {
		if (!this.options.fadeContentIn || window.Browser.trident4 || (window.Browser.Platform.name !== 'mac')) {
			this.overlayContainerFadeEffect.set(this.showme);	
		} else {
    		this.overlayBG.setStyle('background-image', 'none');
			this.overlayContainer.setStyles(this.showme);
		}
		$(document.body).addClass(this.options.type);
	},
	trash: function() {
		this.overlayContainer.innerHTML = ' removing ';
		window.removeEvent('resize', this.doPosition.bind(this));
		if ($$('.accordion').length > 0) {
		    $$('.accordion').each(function(accordion) {
		        accordion.show();
		    });
		}
		$(document.body).removeClass(this.options.type);
		this.overlayBG.dispose();
		this.overlayContainer.dispose();
		if (scj.overlay[this.options.type]) delete scj.overlay[this.options.type];
		if (Browser.Engine.name=='trident' && Browser.Engine.version==4) { $$('select').setStyles({'visibility': 'visible'}); }
	},
	doPosition : function () {
		var ww = window.getWidth()
		var wh = window.getHeight();
		var sos = window.getScrollTop();
		var bh = $(this.presets.CONTAINER_ID).getCoordinates().height;
		var bw = $(this.presets.CONTAINER_ID).getCoordinates().width;
		
		var contTarg = this.options.targetWidth ? this.options.targetWidth : this.overlayContent.getCoordinates().width;
		var bgTarg = '1000px';
		var contHeight = this.options.targetHeight ? this.options.targetHeight : 'auto';
		var contLeft = (bw/2) - (contTarg/2);
		if (this.options.leftOffset || this.options.leftOffset == '') {
			contLeft = this.options.leftOffset;
		}
		
		if (this.hardTop == null) {
			if (sos <= this.options.topOffset) {
				this.hardTop = (sos + this.options.topOffset) + 'px'; 
			} else {
				this.hardTop = ((wh - this.options.topOffset) < (this.options.targetHeight + this.options.topOffset)) ? sos + 'px' : (sos + this.options.topOffset) + 'px';			
			}	
		}
		
		this.overlayBG.setStyles({height: bh +'px', width: bgTarg, position: 'absolute', top: '0', left: '0', 'background-position' : 'center ' + (sos + this.options.topOffset + 50) + 'px'});
		this.overlayContainer.setStyles({position: 'absolute', top: this.hardTop, left: contLeft, width: contTarg, height: contHeight});
		return true;
	},
	destroy: function () {
		this.trash();
	}	
});

scj.productOverlay = new Class({
	Extends: scj.PageOverlay,
	presets : {
		CONTAINER_ID: 'wrapper',
		OVERLAY_BG_CLASSNAME : 'glade_light_bg overlay',
		CONTENT_OUTER_CONTAINER_CLASSNAME : 'glade_ol_contain product overlay',
		CONTENT_INNER_CONTAINER_CLASSNAME : 'glade_ol_content',
		CLOSE_BUTTON_CLASSNAME : 'glade_ol_close',
		LOADING_IMG_CLASSNAME : 'glade_loading',
		LOADING_IMG_URL : 'img/overlay/loadingImg_bk.gif'
	},
	options : {
		type: 'productOverlay',
		topOffset: 150,
		fadeContentIn: false,
		targetHeight: 555,
		targetWidth: 770,
		overlay_bg_opacity: 0.6,
		swfWidth: 770,
		swfHeight: 525,
		swfWmode: 'transparent',
		swfId: 'productOverlay'
	}
});

scj.flashOverlay = new Class({
	Extends: scj.PageOverlay,
	presets : {
		CONTAINER_ID: 'wrapper',
		OVERLAY_BG_CLASSNAME : 'glade_light_bg overlay',
		CONTENT_OUTER_CONTAINER_CLASSNAME : 'glade_ol_contain overlay',
		CONTENT_INNER_CONTAINER_CLASSNAME : 'glade_ol_content',
		CLOSE_BUTTON_CLASSNAME : 'glade_ol_close',
		LOADING_IMG_CLASSNAME : 'glade_loading',
		LOADING_IMG_URL : 'img/overlay/loadingImg_bk.gif'
	},
	options : {
		type: 'flashOverlay',
		topOffset: 150,
		fadeContentIn: false,
		targetHeight: 400,
		swfWidth: 320,
		swfHeight: 350,
		swfWmode: 'transparent',
		overlay_bg_opacity: 0.6
	}
});

scj.scentCollectionOverlay = new Class({
	Extends: scj.PageOverlay,
	presets : {
		CONTAINER_ID: 'wrapper',
		OVERLAY_BG_CLASSNAME : 'glade_light_bg overlay',
		CONTENT_OUTER_CONTAINER_CLASSNAME : 'glade_ol_contain headerSwf',
		CONTENT_INNER_CONTAINER_CLASSNAME : 'glade_ol_content header',
		CLOSE_BUTTON_CLASSNAME : 'glade_ol_close',
		LOADING_IMG_CLASSNAME : 'glade_loading',
		LOADING_IMG_URL : 'img/overlay/loadingImg_bk.gif'
	},
	options : {
		type: 'headerOverlay',
		topOffset: 0,
		leftOffset: '',
		fadeContentIn: false,
		targetHeight: 400,
		targetWidth: 400,
		overlay_bg_opacity: 0.6,
		swfWidth: 320,
		swfHeight: 350,
		swfId: 'scentCollectionsSelector',
		swfWmode: 'transparent'
	}
});

scj.findAScentOverlay = new Class({
	Extends: scj.PageOverlay,
	presets : {
		CONTAINER_ID: 'wrapper',
		OVERLAY_BG_CLASSNAME : 'glade_light_bg overlay',
		CONTENT_OUTER_CONTAINER_CLASSNAME : 'glade_ol_contain headerFindAScentSwf',
		CONTENT_INNER_CONTAINER_CLASSNAME : 'glade_ol_content header',
		CLOSE_BUTTON_CLASSNAME : 'glade_ol_close',
		LOADING_IMG_CLASSNAME : 'glade_loading',
		LOADING_IMG_URL : 'img/overlay/loadingImg_bk.gif'
	},
	options : {
		type: 'headerOverlay',
		topOffset: 72,
		leftOffset: 690,
		fadeContentIn: false,
		targetHeight: 350,
		overlay_bg_opacity: 0.1,
		swfWidth: 293,
		swfHeight: 850,
		swfId: 'findScent',
		swfWmode: 'transparent'
	}
});

scj.scentOverlay = new Class({
	Extends: scj.PageOverlay,
	presets : {
		CONTAINER_ID: 'wrapper',
		OVERLAY_BG_CLASSNAME : 'glade_light_bg overlay',
		CONTENT_OUTER_CONTAINER_CLASSNAME : 'glade_ol_contain scent_overlay',
		CONTENT_INNER_CONTAINER_CLASSNAME : 'glade_ol_content',
		CLOSE_BUTTON_CLASSNAME : 'glade_ol_close',
		LOADING_IMG_CLASSNAME : 'glade_loading',
		LOADING_IMG_URL : 'img/overlay/loadingImg_bk.gif'
	},
	options : {
		type: 'articleOverlay',
		topOffset: 100,
		leftOffset: 92,
		fadeContentIn: false,
		targetHeight: 475,
		targetWidth: 825,
		overlay_bg_opacity: 0.6,
		swfWidth: 825,
		swfHeight: 475,
		swfId: 'scentOverlay',
		swfWmode: 'transparent'
	}
});

scj.videoOverlay = new Class({
	Extends: scj.PageOverlay,
	presets : {
		CONTAINER_ID: 'wrapper',
		OVERLAY_BG_CLASSNAME : 'glade_light_bg overlay',
		CONTENT_OUTER_CONTAINER_CLASSNAME : 'glade_ol_contain videoOverlay',
		CONTENT_INNER_CONTAINER_CLASSNAME : 'glade_ol_content',
		CLOSE_BUTTON_CLASSNAME : 'glade_ol_close',
		LOADING_IMG_CLASSNAME : 'glade_loading',
		LOADING_IMG_URL : 'img/overlay/loadingImg_bk.gif'
	},
	options : {
		type: 'videoOverlay',
		topOffset: 100,
		fadeContentIn: false,
		targetWidth: 680,
		targetHeight: 550,
		overlay_bg_opacity: 0.6,
		swfWidth: 680,
		swfHeight: 550,
		swfId: 'videoOverlay',
		swfWmode: 'transparent'
	}
});