scj.headerMenu = {}
scj.flashOverlay = {};
scj.overlay = {};

function BlankObject() {
}

function setOptions(obj, options) {

    if (obj.options == undefined) {
        obj.options = new BlankObject();
    }

    for (key in options) {
        obj.options[key] = options[key];
    }

    return obj;
}

scj.OverlayLink = {
    options: {
        type: 'standard',
        eventTrigger: 'click'
    },
    hardTop: null,
    initialize: function (elem, options) {
        this.triggerOverlay = scj.OverlayLink.triggerOverlay;
        setOptions(this, options);
        var reference = this;
        this.source = options["source"];
        $(elem).click(function (evt) {

            reference.triggerOverlay(evt);

            var type = this.attributes["type"].value;
            var trackVars = this.attributes["trackVars"] ? jQuery.parseJSON(this.attributes["trackVars"].value.replace(/'/g, "\"")) : {};
            var linkName = this.text;
            if (type == "product" || type == "video") {
                jQuery.extend(trackVars, { "prop2": this.text, "events": "event5,event18", "eVar3": this.text, "eVar13": "sem_" + this.text });
                linkName = scj.omniture.pageDisplayName + "_" + this.text;
            }

            scj.omniture.trackLink(trackVars, { "linkType": "o", "linkName": linkName }, this);
            return false;
        });
    },
    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.PageOverlay.initialize(this.source, this.options, scj[type]);
    }
};


scj.productOverlay = {
	
	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: 50,
		fadeContentIn: false,
		targetHeight: 555,
		targetWidth: 770,
		overlay_bg_opacity: 0.6,
		swfWidth: 770,
		swfHeight: 525,
		swfWmode: 'transparent',
		swfId: 'productOverlay'
	}
};

scj.findAScentOverlay = {

    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: 'headerOverlay',
        topOffset: 65,
        leftOffset: 690,
        fadeContentIn: false,
        targetHeight: 350,
        overlay_bg_opacity: 0.1,
        swfWidth: 293,
        swfHeight: 850,
        swfId: 'findScent',
        swfWmode: 'transparent'
    }
};


scj.videoOverlay = {

    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'
    }
};



scj.PageOverlay = {

    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, presets) {
        this.build = scj.PageOverlay.build;
        this.createSwf = scj.PageOverlay.createSwf;
        this.loadContent = scj.PageOverlay.loadContent;
        this.handleLoadContent = scj.PageOverlay.handleLoadContent;
        this.fadeOverlay = scj.PageOverlay.fadeOverlay;
        this.trash = scj.PageOverlay.trash;
        this.destroy = scj.PageOverlay.destroy;
        this.doPosition = scj.PageOverlay.doPosition;
        this.options = presets.options;
        this.presets = presets.presets;
        setOptions(this, options);

        this.source = source;

        this.build();
        return this;
    },
    build: function () {

        this.hider = { 'visibility': 'hidden' };
        this.showme = { 'visibility': 'visible' };


        this.overlayHolder = $(this.presets.CONTAINER_ID).get(0) || body;


        this.overlayBG = document.createElement('div');
        $(this.overlayBG).addClass(this.presets.OVERLAY_BG_CLASSNAME);
        this.overlayHolder.appendChild(this.overlayBG);
        this.overlayContainer = document.createElement('div');
        $(this.overlayContainer).addClass(this.presets.CONTENT_OUTER_CONTAINER_CLASSNAME);
        this.overlayHolder.appendChild(this.overlayContainer);

        this.closeButton = document.createElement('div');
        $(this.closeButton).addClass(this.presets.CLOSE_BUTTON_CLASSNAME);
        $(this.overlayBG).bind('click', function () {
            for (key in scj.overlay) {
                scj.overlay[key].trash();
            }
        });
        this.overlayContainer.appendChild(this.closeButton);

        this.overlayContent = document.createElement('div');
        $(this.overlayContent).addClass(this.presets.CONTENT_INNER_CONTAINER_CLASSNAME);

        this.overlayContainer.appendChild(this.overlayContent);

        if (this.options.eventTrigger == 'mouseenter' || this.options.type == 'scentCollection') {
            $(this.overlayContent).bind('mouseleave', function () {
                for (key in scj.overlay) {
                    scj.overlay[key].trash();
                }
            });
        }

        if (this.doPosition() == true) {
            $(window).bind('resize', function () {
                for (key in scj.overlay) {
                    scj.overlay[key].doPosition();
                }
            });
        }

        $(this.overlayBG).css(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 () {

        $(this.overlayBG).css('background-image', 'none');
        $(this.overlayBG).css('opacity', this.options.overlay_bg_opacity);
        $(this.overlayContainer).css(this.showme);
        $(document.body).addClass(this.options.type);

    },
    trash: function () {
        this.overlayContainer.innerHTML = ' removing ';
        $(window).unbind('resize');


        $(document.body).removeClass(this.options.type);

        this.overlayHolder.removeChild(this.overlayContainer);
        this.overlayHolder.removeChild(this.overlayBG);
        if (scj.overlay[this.options.type]) delete scj.overlay[this.options.type];
    },
    doPosition: function () {
        var ww = $(window).width();
        var wh = $(window).height();
        var sos = $(window).scrollTop();
        var bh = $(this.presets.CONTAINER_ID).height();
        var bw = $(this.presets.CONTAINER_ID).width();

        var contTarg = this.options.targetWidth ? this.options.targetWidth : $(this.overlayContent).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).css({ 'height': bh + 'px', 'width': bgTarg, 'position': 'absolute', 'top': '0', 'left': '0', 'background-position': 'center ' + (sos + this.options.topOffset + 50) + 'px' });
        $(this.overlayContainer).css({ 'position': 'absolute', 'top': this.hardTop, 'left': contLeft, 'width': contTarg, 'height': contHeight });
        return true;
    },
    destroy: function () {
        this.trash();
    }
};




//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.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'
//	}
//});


