/*
 * 
 * 	Short term solution for loading the older nikeos nav without loading the entire nikeos js
 * 
 */

// GLOBAL NIKEOS NAMESPACE

/* NIKEOS */
if (!window.NIKEOS) var NIKEOS = {};
/*
SET THE SITE MODE
*/
if (location.host.match(/inside-staging/i) || location.host.match(/(env\d*)-brand/i) || location.host.match(/(ecn\d*)-www/i) || location.host.match(/dev/i))
NIKEOS.site_mode = 'staging';
else if (location.host.match(/nike\.com/i))
NIKEOS.site_mode = 'prod';
else if (location.host.match(/^[^\.]*$/i))
NIKEOS.site_mode = 'localhost';
else
NIKEOS.site_mode = 'dev';
NIKEOS.protocol = (location.protocol == 'https:') ? 'https://' : 'http://';
NIKEOS.currentURL = escape(location.href);
NIKEOS.BASE = {
localhost : NIKEOS.protocol + location.host,
dev : NIKEOS.protocol + (NIKEOS.siteHost || 'nike-dev4.ny.rga.com'),
staging : NIKEOS.protocol + (NIKEOS.siteHost || 'ecn10-www.nike.com'),
prod : NIKEOS.protocol + 'www.nike.com'
};
NIKEOS.setDev = function(url) {
NIKEOS.BASE.dev = NIKEOS.protocol + url;
};
/* End NIKEOS */




/* EVENT BRIDGE -- eventbridge.js */
// EventBridge 
// v1.5
// 2009.04.22
if (!window.EventBridge) var EventBridge = new function(){
	if (!document.getElementById) return;
	
	var channel = "external";
	this.setChannel = function(name){
		channel = name;
	};
	this.getChannel = function(){
		return channel;
	};
	
	/*
	 * debugMode is used to send messages to a specifically named textarea/form.  
	 * If you would like to turn on debugging, call EventBridge.setMode("debug")
	 * and copy and paste the html below into your document
	 * <form name="eventbridge_debug_form">
			<textarea rows="20" cols="75" name="eventbridge_debug_txt" style="width:620"></textarea>
		</form>
	 */
	var mode = "normal";
	this.setMode = function(m){
		mode = m;
	};
	this.getMode = function(){
		return mode;
	};
	
	// Get a valid reference to Flash Object
	this.getFlash = function(movieName){
		if (navigator.appName.indexOf("Microsoft") != -1)
			return window[movieName];
		else
			return document[movieName];
	};
	
	var listeners = {};
	
	this.listeners = listeners;
	
	this.dispatchEvent = function(evtObj){
		
		// debug call
		var prefix = "dispatchEvent ";
		this.debug(prefix + "TYPE : " + evtObj.type + " DATA : " + evtObj.data);
		
		var type = evtObj.type;
		if (!listeners[type]) return;
		for (var i in listeners[type]) {
			for (var j = 0, l = listeners[type][i].length; j < l; j++) {
				var target = listeners[type][i][j].target;
				var func = listeners[type][i][j].func;
				if (typeof target[func] == 'function')
					target[func](evtObj);
			}
		}
	};
	
	this.addListener = function(type, target, func){
		listeners[type] = listeners[type] || {};
		listeners[type][target] = listeners[type][target] || [];
		
		// debug call
		var prefix = "addListener : ";
		this.debug(prefix + "TYPE : " + type + " - TARGET : " + target + " FUNCTION : " + func);
		
		listeners[type][target].push({
			target: this.getFlash(target) || target,	// flash || DOM listener
			func: func
		});
	};
	
	// changed register to add just keeping backwards compatibility
	this.registerListener = this.addListener;
	
	this.removeListener = function(type, target, func){
		
		// debug call
		var prefix = "removeListener ";
		this.debug(prefix + "TYPE : " + type + " - TARGET : " + target + " FUNCTION : " + func);
		
		// get qualified reference
		var brain = this.getFlash(target) || target;
		
		// find match and remove
		for (var i = 0, l = listeners[type][target].length; i < l; i++) {
			if (listeners[type][target][i].target.id == target && listeners[type][target][i].func == func)
				listeners[type][target].splice(i, 1);
		}
	};
	
	this.hasListener = function(type, target, func){
		var brain = this.getFlash(target) || target;
		if (func) {
			for (var i = 0, l = listeners[type][target].length; i < l; i++) {
				var listener = listeners[type][target][i];
				if ((listener.target.id == brain.id || listener.target == target) && listener.func == func){
					this.debug("hasListener TYPE : " + type + " TARGET : " + target + " FUNCTION : " + func);
					return true;
				}
			}
			this.debug("hasListener false");
			return false;
		}
		else {
			var exists = !!listeners[type][target];
			this.debug("hasListener : " + exists);
			return exists;
		}
	};
	
	this.removeAllListeners = function(){
		listeners = {};
	};
	
	this.removeAllListenersForType = function(type){
		listeners[type]={};
	};
	
	this.debug = function(msg){
		if (document.eventbridge_debug_form && mode == "debug") {
			document.eventbridge_debug_form.eventbridge_debug_txt.value += (msg + "\n");
		}
	};
};
/* END EVENT BRIDGE */

/* 
	NAVIGATION -- navigation.js 
	updated 10.09.08
*/
var navListener = new Object();
navListener.defaultSearchText = " ";
navListener.nullSearchText = "";

//console.log("check");

navListener.openURL = function(event){
	var target = "_self";
	if (event.data.target != "") {
		target = event.data.target;
	}
	window.open(event.data.href, target);
};


navListener.searchFocus = function(event) {
	navListener.navInput = document.getElementById('nav_input');

	setTimeout("navListener.navInput.focus()",25); 
	setTimeout("setCaretTo(navListener.navInput, 1000)");
};

navListener.searchOpen = function(event) {
	//console.log("search open");
	navListener.navInput = document.getElementById('nav_input');
	navListener.navForm = document.getElementById('nav_input_form');
	navListener.navForm.style.visibility='visible';
	navListener.navInput.style.visibility='visible';
	setTimeout("navListener.navInput.value = navListener.defaultSearchText",25); 
	setTimeout("navListener.navInput.select()",25); 
	setTimeout("navListener.navInput.value = navListener.nullSearchText",26); 
	setTimeout("setCaretTo(navListener.navInput, 1000)", 27);
};

navListener.searchClose = function(event) {
	//console.log("search close");
	setTimeout("navListener.navInput.value = navListener.nullSearchText",2); 
	setTimeout("navListener.navInput.blur()",3);
	setTimeout("navListener.navInput.style.visibility='hidden'",4); 
};

function search() {
	EventBridge.dispatchEvent({type:'moduleCall',data:encodeURIComponent(document.getElementById('nav_input').value)});
};

EventBridge.addListener("url", navListener, "openURL");
EventBridge.addListener("search", navListener, "openURL");
EventBridge.addListener("searchopen", navListener, "searchOpen");
EventBridge.addListener("searchclose", navListener, "searchClose");
EventBridge.addListener("searchfocus", navListener, "searchFocus");
EventBridge.addListener("callsearch", navListener, "callSearch");
EventBridge.addListener("lockup", navListener, "lockupActive");
EventBridge.addListener("nav", navListener, "navActive");

navListener.flashTest = function(event) { 
	alert("flash working");
};

navListener.lockupActive = function(event) {
	EventBridge.dispatchEvent({type:'navCall',data:'close'});
};

navListener.navActive = function(event) {
	EventBridge.dispatchEvent({type:'lockupCall',data:'close'});
};

navListener.flashAlert = function(event) {
	alert(event.data);
};

navListener.callSearch = function(event) {
	if (document.getElementById('nav_input').value != "") {
		search();
	}
};

function setCaretTo(obj, pos) { 
    if(obj.createTextRange) { 
        var range = obj.createTextRange(); 
        range.move("character", pos); 
        range.select(); 
    } else if(obj.selectionStart) { 
        obj.focus(); 
        obj.setSelectionRange(pos, pos); 
    } 
}; 

/*For Login Update*/
EventBridge.addListener("updateNavProfile", navListener, "updateNavProfile");
EventBridge.addListener("logoutCookies", navListener, "logoutCookies");
EventBridge.addListener("logoutSocial", navListener, "logoutSocial");

var navProfileObj;
var navProfileCalled = false;

function setNavProfile(obj) {
	navListener.navProfileObj = obj;
	navListener.navProfileCalled = true;
	EventBridge.dispatchEvent({type:'setNavProfile', data: obj});
};

navListener.updateNavProfile = function(event) {
	if ((navProfileCalled == false) && (navProfileObj != undefined)) {
		setNavProfile(navListener.navProfileObj);
	}
}

navListener.logoutCookies = function(event) {
	NIKEOS.ME.clearSocialCookies();
	if(typeof nikeplus != "undefined")
		nikeplus.user.logout();
}

//Logout for social-enabled sites (add type="logoutSocial" to nav.xml)
//Clears social cookies, logs user out of UPM and refreshes page.
// UPDATED BY AKQA 1st July 2010 to use services proxy
navListener.logoutSocial = function(event){
	NIKEOS.ME.clearSocialCookies();
	var profileServiceUrl = document.location.protocol+"//"+document.location.hostname+'/services/profileService';
	var callback = function(data){
		//console.log(data);
		location.reload(true);
	}
	//var request = { url:profileServiceUrl, method:'POST', post_data:'action=logout', callback: function(data){ location.reload(true) } };
	
	var proxyParams = {
		url: profileServiceUrl + "?action=logout",
		meth: 'POST',
		contenttype: null,
		callback: callback,
		onready: function(data) {
			if (data) {
				//data = '(' + data.replace(/\\n|\\r/g, '') + ')';
				//callback(eval(data));  // JSON.parse doesn't work with responses from the proxy!?
				callback();
			}
		}
	};

	nf.fw.services.proxy.open(proxyParams);
	
}
/*End Login Update*/

/* END NAVIGATION */

/* me.nike.com COOKIE */

if (!NIKEOS.ME) NIKEOS.ME = {};

/**
 * setCookie
 * sets the "me.nike.com" cookie
 * @param {object} obj : hash of profile name/values
 */
NIKEOS.ME.setCookie = function(obj){
	var str = '';
	var counter = 0;
	for(i in obj){
		if(counter!=0){ str += '&'; } else { counter++; }
		str += i + '=' + obj[i];
	}
	NIKEOS.ME.data = obj;
	var date = new Date();
	date.setTime(date.getTime() + (5 * 60 * 1000));
	JQ.cookie('me.nike.com',Base64.encode(str),{path:'/',expires:date});
}

/** getCookie
 * gets hash from "me.nike.com" cookie
 * @return {object} obj : hash of profile name/values
 */
NIKEOS.ME.getCookie = function(){
	if(JQ.cookie('me.nike.com')){
		var str = Base64.decode(JQ.cookie('me.nike.com'));
		var arr = str.split('&');
		var obj = {};
		for(var i = 0;i<arr.length;i++){
			obj[arr[i].split('=')[0]] = arr[i].split('=')[1];
		}
		return obj;
	} else { return false; }
}

/** addToCookie
 * add hash to "me.nike.com" cookie (OVERWRITES)
 * @param {object} params : hash of name/values to add
 * @return {object} obj : hash of profile name/values
 */
NIKEOS.ME.addToCookie = function(params){
	if(JQ.cookie('me.nike.com')){
		var str = Base64.decode(JQ.cookie('me.nike.com'));
		var arr = str.split('&');
		var obj = {};
		for(var i = 0;i<arr.length;i++){
			obj[arr[i].split('=')[0]] = arr[i].split('=')[1];
		}
		for(var j in params){
			obj[j] = params[j];
		}
		NIKEOS.ME.setCookie(obj);
		return obj;
	} else { NIKEOS.ME.setCookie(params); }
}

/** removeFromCookie
 * remove array of keys from "me.nike.com" cookie
 * @param {array} params : array of keys to delete
 * @return {object} obj : hash of profile name/values
 */
NIKEOS.ME.removeFromCookie = function(toDelete){
	if(JQ.cookie('me.nike.com')){
		var str = Base64.decode(JQ.cookie('me.nike.com'));
		var arr = str.split('&');
		var obj = {};
		for(var i = 0;i<arr.length;i++){
			obj[arr[i].split('=')[0]] = arr[i].split('=')[1];
		}
		for(var j = 0;j<toDelete.length;j++){
			delete obj[toDelete[j]];
		}
		NIKEOS.ME.setCookie(obj);
		return obj;
	} else { return false; }	
}

/** clearSocialCookies
 * remove me.nike.com and st.nike.com cookies on logout.
 */
NIKEOS.ME.clearSocialCookies = function(){
	if(JQ.cookie){
		JQ.cookie('me.nike.com', null, {path:'/'});
		JQ.cookie('st.nike.com', null, {path:'/'});
	} else {
		NIKEOS.log('JQ.cookie not available');
	}
}
/** verifyCookie
 * make sure that id.nike.com matches me.nike.com
 * if it doesn't, clearSocialCookies
 */
NIKEOS.ME.verifyCookie = function(){
	if(JQ.cookie){
		if(JQ.cookie('me.nike.com') && JQ.cookie('id.nike.com')){
			var id_id = Base64.decode(JQ.cookie('id.nike.com')).split(':')[0];
			var me_id = NIKEOS.ME.getCookie().id;
			if (id_id != me_id){
				NIKEOS.ME.clearSocialCookies();
				return false;
			} else {
				return true;
			}
		} return false;
	}
	NIKEOS.log('JQ.cookie not available');
}

/** updateNav
 * set nav profile tab to have updated screenName, profileImage, messageCount
 */
NIKEOS.ME.setMessageCount = function(){
	if(JQ.cookie){
		if(JQ.cookie('me.nike.com')){
			var messageCount = NIKEOS.ME.getCookie().messageCount;
			if(typeof(messageCount)!='undefined'){
				setNavProfile({'messageCount':messageCount});
			}
		}
	}
}
/* END me.nike.com COOKIE */

/* SWFjax Controller */
NIKEOS.AjaxController = function(options){
	var self = this;
	self.setup = JQ.extend(true,{
		f4a : {
			swf_src : '/nikeos/global/swf/f4a/f4a.swf',
			js_src : '/nikeos/global/js/f4a_js.js',
			div_id : 'f4a_nikeflashcontent'
		}
	}, options);
	self.metadata = {
		ready : false,
		queue : []
	}
	self.init = function(){
		var f4a_js=document.createElement('script');
		f4a_js.src=self.setup.f4a.js_src;
		f4a_js.onload=f4aSwf;
		f4a_js.onreadystatechange=function(){
			if(f4a_js.readyState == 'loaded' || f4a_js.readyState == 'complete'){
				f4aSwf();
			}
		};
		var f4a_div=document.createElement('div');
		f4a_div.id=self.setup.f4a.div_id;f4a_div.style.height="1px";f4a_div.style.width="1px";f4a_div.style.marginTop="-1px";f4a_div.style.marginLeft="-1px";f4a_div.style.backgroundColor="transparent";
		var bodyInterval = window.setInterval(function(){
			if(!document.body){}else{ 
				//DOM in the f4a crossdomain ajax javascript and div.
				document.body.appendChild(f4a_div);
				document.body.appendChild(f4a_js);
				window.clearInterval(bodyInterval);
			};
		}, 50)

		function f4aSwf(){
			var f4aInterval = window.setInterval(function(){
				if(typeof(f4a_js_flash)=='undefined'){
				}
				else{
					f4a = new f4a_js_flash({'id':'f4a_nike','swfname':'f4a.swf','swfuri':self.setup.f4a.swf_src});
					f4a.createSwfObject(function(){
						self.metadata.ready = true;
						self.unloadQueue();
					});
					window.clearInterval(f4aInterval);
				};
			}, 50)
		}
	}
	self.request = function(request_obj, cb){
		if(self.metadata.ready == true){
			self.fire(request_obj, cb);
		} else {
			var req = [ request_obj, cb ];
			self.metadata.queue.push(req);
		}
	}
	self.fire = function(data, cb){
		this.url = data['url'] || '';
		this.method = data['method'] || 'POST';
		this.data = data['post_data'] || {};
		this.contenttype = data['contenttype'] || null;
		var cb = cb || function(){ return; };
		this.req = {'url':this.url,'meth':this.method,'contenttype':this.contenttype,'data':this.data,'onready':function(data){ cb(data); }};
		f4a.open(this.req);
	}
	self.unloadQueue = function(){
		if(self.metadata.queue[0]){
			for(var i = 0; i < self.metadata.queue.length; i++){
				self.fire(self.metadata.queue[i][0], self.metadata.queue[i][1]);
			}
		}
	}
	self.test = function(){
		console.log('testing');
		var data = {};
		data['url'] = '/services/profileService?action=getprofile';
		data['method'] = 'POST';
		data['post_data'] = 'test=12';
		var fn = function(o){ alert(o) };
		self.request(data, fn);
	}
	self.init();
}

/* BASE 64 Encoding/Decoding */

var Base64 = {

    // private property
    _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

    // public method for encoding
    encode : function (input) {
        var output = "";
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
        var i = 0;

        input = Base64._utf8_encode(input);

        while (i < input.length) {

            chr1 = input.charCodeAt(i++);
            chr2 = input.charCodeAt(i++);
            chr3 = input.charCodeAt(i++);

            enc1 = chr1 >> 2;
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
            enc4 = chr3 & 63;

            if (isNaN(chr2)) {
                enc3 = enc4 = 64;
            } else if (isNaN(chr3)) {
                enc4 = 64;
            }

            output = output +
            this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
            this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

        }

        return output;
    },

    // public method for decoding
    decode : function (input) {
        var output = "";
        var chr1, chr2, chr3;
        var enc1, enc2, enc3, enc4;
        var i = 0;

        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

        while (i < input.length) {

            enc1 = this._keyStr.indexOf(input.charAt(i++));
            enc2 = this._keyStr.indexOf(input.charAt(i++));
            enc3 = this._keyStr.indexOf(input.charAt(i++));
            enc4 = this._keyStr.indexOf(input.charAt(i++));

            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;

            output = output + String.fromCharCode(chr1);

            if (enc3 != 64) {
                output = output + String.fromCharCode(chr2);
            }
            if (enc4 != 64) {
                output = output + String.fromCharCode(chr3);
            }

        }

        output = Base64._utf8_decode(output);

        return output;

    },

    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }
};

/* END BASE 64 Encoding/Decoding */

/* ARTICLE SHARE -- articleShare.js */
function articleShare(site, popUpUrl, title, description) {
    var repQ = /\?/;
    var encQ = '%3f';
    popUpUrl = popUpUrl.replace(repQ, encQ);

    switch (site) {
    case "digg":
        postPopUp('http://digg.com/remote-submit?phase=2&url=' + popUpUrl, 'digg', 'toolbar=0,status=0,height=450,width=650,scrollbars=yes,resizable=yes');
        break;
    case "delicious":
        postPopUp('http://del.icio.us/post?url=' + popUpUrl + '&title=' + title, 'delicious', 'toolbar=0,status=0,height=450,width=650,scrollbars=yes,resizable=yes');
        break;
    case "facebook":
        postPopUp('http://www.facebook.com/sharer.php?u=' + popUpUrl + '&t=' + title, 'facebook', 'toolbar=0,status=0,height=436,width=646,scrollbars=yes,resizable=yes');
        break;
    case "stumble":
        postPopUp('http://www.stumbleupon.com/submit?url=' + popUpUrl + '&title=' + title, 'stumble', 'toolbar=0,status=0,height=450,width=770,scrollbars=yes,resizable=yes');
        break;
    case "newsvine":
        postPopUp('http://www.newsvine.com/_tools/seed&save?u=' + popUpUrl + '&h=' + title, 'newsvine', 'toolbar=0,status=0,height=500,width=1000,scrollbars=yes,resizable=yes');
        break;
    };
};

/* ENABLEMENT -- enablement.js */

var enablementListener = {};
var http_request;

enablementListener.fileSave = function(event) {
    //window.open(event.data.url, event.data.target);
    window.open(event.data.url, "_self");
};

enablementListener.blogPrint = function(event) {
    //alert("opening print window");
    window.open(event.data.url, "_blank");
};

enablementListener.blogShare = function(event) {
    //alert("article enablement share: sn name: " + event.data.sn + ", url: " + event.data.url + ", title: " + event.data.title);
    articleShare(event.data.sn, event.data.url, event.data.title, event.data.title);
};

enablementListener.blogEmail = function(event) {
    //alert("blog email");
    http_request = null;
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            // set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
        }
    } else if (window.ActiveXObject) { // IE
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch(e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch(e) {}
        }
    }
    if (http_request != null) {
        var parameters = "?recipient=" + event.data.to + "&sender=" + event.data.from + "&message=" + event.data.message + "&language=" + event.data.language + "&country=" + event.data.country + "&link=" + event.data.link + "&title=" + event.data.title + "&brandName=" + event.data.brandName;
        var url = "http://cs.ny.rga.com/reboot/sendmailProxy.jsp";
        var urlParam = url + parameters;
        http_request.onreadystatechange = alertContents;
        http_request.open('GET', urlParam, true);
        http_request.send(null);
    } else {
        alert('Cannot create XMLHTTP instance');
        return false;
    }
};

function alertContents() {
    if (xmlhttp.readyState == 4) {
        // 4 = "loaded"
        if (xmlhttp.status == 200) {
            // 200 = OK
            // ...our code here...
        }
    } else {
        alert("Problem retrieving XML data");
    }
}
EventBridge.addListener("blogprint", enablementListener, "blogPrint");
EventBridge.addListener("blogshare", enablementListener, "blogShare");
EventBridge.addListener("blogemail", enablementListener, "blogEmail");
EventBridge.addListener("filesave", enablementListener, "fileSave");

/* END ENABLEMENT */



function postPopUp(url, name, params) {
    var win = window.open(url, name, params);
};

/* END ARTICLE SHARE */


(function() {

	var injectFlash,
		swooshNav,
		mainNav,
		commerceNav,
		innerXHTML;
	
	//	from nikeos.global.js
	innerXHTML = function (obj, encode) {	
		// It is an option to pass innerXHTML() a string indicating an id attribute
		if (typeof obj == "string") {
			obj = document.getElementById(obj);
		};
		
		var open = '';
		var content = '';
		var close = '';
		var tagname = obj.nodeName.toLowerCase();
		var emptytag = (obj.nodeName.match(/area|base|basefont|br|col|frame|hr|img|input|isindex|link|meta|param/i)) ? true : false; 
		
		// Write open tag
		open = '<'+tagname;
		for (var i=0; i<obj.attributes.length; i++) {
			if (obj.attributes[i].specified && obj.attributes[i].value != "null")
			open += ' '+obj.attributes[i].name.toLowerCase()+'="'+obj.attributes[i].value+'"';
		}
		open += (emptytag) ? ' />' : '>';
		
		if (!emptytag) {
			// Write tag content
			for (var i=0; i<obj.childNodes.length; i++) {
				var node = obj.childNodes[i];
				if (node.nodeType==3)
					content += node.data;
				else if (node.nodeType==1)
					content += innerXHTML(obj.childNodes[i], false);
				else
					content += " ";
			}
		
			// Write closing tag
			close = '</'+tagname+'>';
		}
		
		// URI encode the content if desired
		return (typeof(encode)=="undefined" || encode==true) ? encodeURIComponent(open+content+close) : open+content+close;
	}

	
	injectFLash = function(id, swf, width, height, vars) {
		
		var flashAttributes,
			flashParams,
			flashVars;


		flashParams = {
			name: id,
			quality: "best",
			scale: "noscale",
			menu: "false",
			wmode: "transparent",
			allowScriptAccess: "always",
			salign: "tl"
		};
	
		flashVars = {
			id: id,
			locale: nf.gv.locale,
			currentUrl: location.href,
			fontPath: "/nikeos/global/modules/nav/v1/font/fontlibrary.swf",
			stylePath: "/nikewomen/global/xml/style.xml",
			locale: nf.gv.locale
		};
		
		swfobject.embedSWF(swf, id, width, height, "9", flashParams.bgColor, $.extend(flashVars, vars), flashParams);
		
	};

	window.setMenuArea = function(id, width, height) {
		$("#" + id).width(width+'px');
		$("#" + id).height(height+'px');
	};


	jQuery(function() {	

		swooshNav = {
			siteXML: innerXHTML("site", true)
		}	
		
		injectFLash("nav-module-top", "/nikeos/global/modules/nav/v1/swf/nav-module-top-1-2.swf", 257, 61, swooshNav);

		mainNav = {
			currentNav : site_data.nav_current,
			navXML: innerXHTML("nav", true)
		}	
		
		injectFLash("nav-module-left", "/nikewomen/assets/nikeos/swf/nav/nav-module-menu-2.swf", 102, 500, mainNav);
	
	});


})();

