

function Framework() {
	
	this.min_flash_version		= '9.0.115';
	this.expressInstall_swf		= '/portal/media/swf/expressInstall.swf';
	this.videoSWFs				= [];
	
	//init the framework
	this.init();
}

// General _____________________________________________________________________

/**
 * The init function is called in the constructor.
 */
Framework.prototype.init = function () {
	
	//omni more info click track
	$(".highlight .btn_info").click(function() {
		omniLinkCall(this, this.id);
	});
	
	
	// IE6 background image cache fix
	try {
		document.execCommand("BackgroundImageCache", false, true);
	} 
	catch (err) {
		// fail silently
	}
	
	
	
	/*$('#header_search').bind('submit', function() {
		var intSearchTerm = $('.searchField').val().toLowerCase();
		setOmniValues(this, 'o', 'intSearch', 'intSearchTerms=' + intSearchTerm + ',predSearchSel=', 'intSearchTerms=' + intSearchTerm, 'searches', 0, ';noProdSearch');
	});*/
		
	// Load any components reliant on third-party data sources
	//this.loadExternalModules();
	
	// Preload rollovers for cart & more info buttons
	this.preloadRollovers();
	
	
	// Fake hover for menu elements in IE
	if ($.browser.msie) {
		Framework.prototype.fakeHover('#menu li', 'drop');
	}
	
	$("#header_search .submitsd").mouseover(function () {
		$(this).removeClass("submitsd").addClass("submitsd_on");
	}).mouseout(function () {
		$(this).removeClass("submitsd_on").addClass("submitsd");
	});
	
	

	$(document).unload(function () {
		// Unbind event listeners
		$('*').unbind();
	});
	
	// Make new window links open in new tab or maximized browser
	$('a.new-window').click(function(){
		//window.open(this.href);
		//return false;
	});
	
	//EP if config exists
	if (typeof EP_config=="object") {
		this.embedSWF({
			minFlashVersion: '10.0.0.0',
			swf: EP_config.swf,
			container: 'editorialPodContainer',
			width: EP_config.width,
			height: EP_config.height,
			flashvars: EP_config.flashvars,
			params: EP_config.params, 
			attributes: EP_config.attributes
		});
	}
	
};

/**
 * Returns the value of a name/value pair in the query string
 * @param {Object} variable
 * @return The value of the specified variable
 */
Framework.prototype.getQueryVariable = function (variable) {
	
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	
	for (var i = 0; i < vars.length; i++) {
		var pair = vars[i].split('=');
		if (pair[0] === variable) {
			return pair[1];
		}
	}
	
};






// Browser Testing _____________________________________________________________

/**
 * 
 */
Framework.prototype.ie6 = function () {
	return ($.browser.msie && $.browser.version < 7);
};

/**
 * 
 */
Framework.prototype.opera8 = function () {
	return ($.browser.opera && $.browser.version < 9);
};

/**
 * Test the user's browser so that certain features are not displayed for 
 * browsers that do not support them
 */
Framework.prototype.oldBrowser = function () {
	return (this.ie6() || this.opera8());
};

// Lazy Loading ________________________________________________________________

/**
 * Once the page has loaded, checks the config object for the presence of an 
 * array, "externalModules". If found, the module is loaded via AJAX
 * @param {Boolean} replaceContent - Whether to replace content container (passed through to loadModule())
 */
Framework.prototype.loadExternalModules = function (replaceContent) {
	
	var scope = this;
	var replace = replaceContent || false;
	
	$(document).ready(function () {
		if (typeof(config) !== 'undefined' && typeof(config.externalModules) !== 'undefined') {
			var i = 0;
			var size = config.externalModules.length;
			for (i = 0; i < size; i++) {
				if(config.externalModules[i].dataSource !== null && config.externalModules[i].dataSource !== '') {
					scope.loadModule(config.externalModules[i].elementID, config.externalModules[i].dataSource, config.externalModules[i].callback, replace);
				}
			}
		}
		//correct computed style width of search form for Chrome
		$.browser.chrome = /chrome/.test(navigator.userAgent.toLowerCase());
		if ($.browser.chrome) {
			var header_search_width_total = 0;
			var footer_search_width_total = 0;
			$('#header_search').children().each(function(i) {
				header_search_width_total += $(this).outerWidth();
			});
			$('#footer_search').children().each(function(i) {
				footer_search_width_total += $(this).outerWidth();
			});
			$('#header_search').width(header_search_width_total);
			$('#footer_search').width(footer_search_width_total);
		}
	});
	
};



// Browser-Specific Work-Arounds _______________________________________________

/**
 * Simulates :hover event for all elements in IE by adding a 'hover' class when
 * the element is moused over by the user. This method should ONLY be called by 
 * IE7 and lower!
 * 
 * Optionally specify a class to join into the fakeHover class since IE6 can't handle chained class selectors in CSS
 * Whether or not a joinClass was provided, it always adds the plain fakeHover class for backwards compability with existing CSS
 * 
 */
 
Framework.prototype.fakeHover = function (selection, joinClass) {
	$(selection).hover(
		function () {
			if (joinClass && $(this).hasClass(joinClass)) {
				$(this).addClass(joinClass+'_fakeHover');	
			}
			$(this).addClass('fakeHover');
		}, 
		function () {
			if (joinClass && $(this).hasClass(joinClass)) {
				$(this).removeClass(joinClass+'_fakeHover');
			}
			$(this).removeClass('fakeHover');
		}
	);
};



Framework.prototype.linksExternal = function(){
    if (document.getElementsByTagName) {
        var anchors = document.getElementsByTagName("a");
        for (var i = 0; i < anchors.length; i++) {
            var anchor = anchors[i];
            if (anchor.getAttribute('href') && anchor.className == 'external new-window') {
                anchor.target = "_blank";
            }
        }
    }
};

// script initiates on page load. 
Framework.prototype.addEvent = function(obj, type, fn){
    if (obj.addEventListener) {
        obj.addEventListener(type, fn, false);
        this.EventCache.add(obj, type, fn);
    }
    else 
        if (obj.attachEvent) {
            obj["e" + type + fn] = fn;
            obj[type + fn] = function(){
                obj["e" + type + fn](window.event);
            }
            obj.attachEvent("on" + type, obj[type + fn]);
            this.EventCache.add(obj, type, fn);
        }
        else {
            obj["on" + type] = obj["e" + type + fn];
        }
};

Framework.prototype.EventCache = function(){
    var listEvents = [];
    return {
        listEvents: listEvents,
        add: function(node, sEventName, fHandler){
            listEvents.push(arguments);
        },
        flush: function(){
            var i, item;
            for (i = listEvents.length - 1; i >= 0; i = i - 1) {
                item = listEvents[i];
                if (item[0].removeEventListener) {
                    item[0].removeEventListener(item[1], item[2], item[3]);
                };
                if (item[1].substring(0, 2) != "on") {
                    item[1] = "on" + item[1];
                };
                if (item[0].detachEvent) {
                    item[0].detachEvent(item[1], item[2]);
                };
                item[0][item[1]] = null;
            };
                    }
    };
}();

// Self-Instantiation __________________________________________________________

var Ellermann = {};
Ellermann.framework = new Framework();
Ellermann.framework.addEvent(window, 'unload', Ellermann.framework.EventCache.flush);
Ellermann.framework.addEvent(window, "load", Ellermann.framework.linksExternal);

