
var Oakridge = window.Oakridge || {};

Oakridge.Util = (function() {
	
	return {
		addLoadEvent: function(func) {
			var oldonload = window.onload;
			if (typeof window.onload != 'function') {
				window.onload = func;
			}
			else {
				window.onload = function() {
					oldonload();
					func();
				}
			}
		}
	};
})();

Oakridge.Map = (function() {
	
	var mapConfig = {
		element: 'oakridge-map',
		width: '964',
		height: '630',
		version: '9.0.0',
		moviePath: '/wp-content/plugins/store-manager/swf/index.swf',
		xmlPath: '/wp-content/plugins/store-manager/swf/xml/oakridge.xml'
	};
	
	var bannerConfig = {
		element: 'featureflash',
		width: '369',
		height: '222',
		version: '9.0.0',
		moviePath: '/wp-content/plugins/store-manager/swf/Fall_09_tile.swf'
	};
	
	var setupMapSwf = function() {
		if (!document.getElementById(mapConfig.element)) {
			return;
		}
		
		var flashvars = {};
		var params = {};
		var attributes = {};
		
		if (window.location.hash) {
			flashvars['storeName'] = encodeURIComponent(window.location.hash.substr(1));
		}
		
		var movie;
		if (window.baseUrl) {
			movie = window.baseUrl + mapConfig.moviePath;
			flashvars['xmlPath'] = window.baseUrl + mapConfig.xmlPath;
		} else {
			movie = mapConfig.moviePath;
			flashvars['xmlPath'] = mapConfig.xmlPath;
		}

		swfobject.embedSWF(movie, mapConfig.element, mapConfig.width, mapConfig.height, mapConfig.version, '', flashvars, params, attributes);
	};
	
	var setupBannerSwf = function() {
		if (!document.getElementById(bannerConfig.element)) {
			return;
		}
		
		if (window.baseUrl) {
			movie = window.baseUrl + bannerConfig.moviePath;
		} else {
			movie = bannerConfig.moviePath;
		}
		
		swfobject.embedSWF(movie, bannerConfig.element, bannerConfig.width, bannerConfig.height, bannerConfig.version, '', {}, {}, {});
	};
	
	return {
		init: function() {
			setupMapSwf();
			setupBannerSwf();
		}
	};
	
})();

Oakridge.Util.addLoadEvent(Oakridge.Map.init);

