function getGlobal(str){
	var r = null;
	switch(str)
	{
		case "friends":
			try {
				r = myFriendsJSON.friends;
			} catch (e){
				r = null;
			}
			break;
		case "teamId":
			r = jQuery('#global').metadata().teamId;
			break;
		case "numvlist":
			r = jQuery('#global').metadata().numvlist;
			break;
		case "sportId":
			r = jQuery('#global').metadata().sportId;
			break;
		case "sportName":
			r = jQuery('#global').metadata().sportName;
			break;				
		case "venueId":
			r = jQuery('#global').metadata().venueId;
			break;
		case "uid":
			r = jQuery('#global').metadata().uid;
			break;
		case "sessionId":
			r = jQuery('#session').metadata().sessionId;
			break;
		case "editPersonalizationMessage":
			r = '<a href="http://espn.go.com/personalization/" name="&amp;lpos=passport&amp;lid=personalizationcorner"><img alt="Add" src="http://a.espncdn.com/i/travel/passport/09/plus.gif"/></a><a href="http://espn.go.com/personalization/" name="&amp;lpos=passport&amp;lid=personalizationcorner">Edit My Teams &#187;</a>';
			break;
		case "personalizationMessage":
			r = '<a href="http://espn.go.com/personalization/" name="&amp;lpos=passport&amp;lid=personalizationcorner"><img alt="Add" src="http://a.espncdn.com/i/travel/passport/09/plus.gif"/></a><a href="http://espn.go.com/personalization/" name="&amp;lpos=passport&amp;lid=personalizationcorner">Add your favorite teams in the Personalization Corner &#187;</a>';
			break;
		case "thickbox-loading":
			r = "http://a.espncdn.com/i/travel/passport/09/loadingAnimation.gif";
			break;
		case "navigate-message":
			r = 'Changes to your Passport have been stored, but will not be reflected\n in your Passport until you save.Are you sure you want to navigate away from this page?\n\nPress OK to exit, or Cancel to continue editing.';
			break;
		case "delete-message":
			r = 'Are you sure you want to delete this visit?';
			break;
		case "avatar-url":
			r = 'http://avatars.espn.go.com/avatars';
			break;
	}
	return r;
}

imgLoader = new Image();// preload image
imgLoader.src = getGlobal('thickbox-loading');

function windowToThickbox(){
	jQuery('html, body').animate({scrollTop:0}, 'fast');
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function getTimestamp(){
	var d = new Date();
	return d.getTime();
}
	
function log(txt,h){
	try { 
		if ( h != null ){
			console.log('/*** '+h+' */')
		}
		console.log(txt);
	} catch (e) {
		//die
	}
}

function is_session_user(md){
	var r = false;

	if ( md != null ){
		md = md.toLowerCase();
		var session_usr = '';
		if ( getSessionUserName() != null ){
			session_usr = getSessionUserName().toLowerCase();
			if ( md == session_usr ){
				r = true;
			}
		}
	}
	return r;
}

/* thickbox js */

function tb_show(caption, url, imageGroup, metaData) {//function called when the user clicks on a thickbox link

	//alert(metaData.id);
	
	try {
		if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
			jQuery("body","html").css({height: "100%", width: "100%"});
			jQuery("html").css("overflow","hidden");
			if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
				jQuery("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
				jQuery("#TB_overlay").click(tb_remove);
			}
		}else{//all others
			if(document.getElementById("TB_overlay") === null){
				jQuery("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
				/*jQuery("#TB_overlay").click(tb_remove);*/ // matt- this is the click shadow
			}
		}
		
		if(tb_detectMacXFF()){
			jQuery("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
		}else{
			jQuery("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
		}
		
		if(caption===null||caption=='This is a comment'||caption=='null'){caption="";}
		
		if ( caption == '' && is_session_user(metaData.user) ){
			caption = 'Add a comment...';
		}
		
		jQuery("body").append("<div id='TB_load'><img src='"+imgLoader.src+"' /></div>");//add loader to the page
		jQuery('#TB_load').show();//show loader
		
		var baseURL;
	   if(url.indexOf("?")!==-1){ //ff there is a query string involved
			baseURL = url.substr(0, url.indexOf("?"));
	   }else{ 
	   		baseURL = url;
	   }
	   
	   //var urlString = /\.jpgjQuery|\.jpegjQuery|\.pngjQuery|\.gifjQuery|\.bmpjQuery/;
	   //var urlType = baseURL.toLowerCase().match(urlString);
		//if(urlType == '.jpg' || urlType == '.jpeg' || urlType == '.png' || urlType == '.gif' || urlType == '.bmp'){//code to show images
		if ( url.indexOf('.jpg') > 0 || url.indexOf('.jpeg') > 0 || url.indexOf('.gif') > 0 || url.indexOf('.bmp') > 0 || url.indexOf('.png') > 0 ){
		
			jQuery('#TB_window').addClass('overlay');
		
			TB_PrevCaption = "";
			TB_PrevURL = "";
			TB_PrevHTML = "";
			TB_NextCaption = "";
			TB_NextURL = "";
			TB_NextHTML = "";
			TB_imageCount = "";
			TB_FoundURL = false;
			if(imageGroup){
				
				TB_TempArray = jQuery("a[rel="+imageGroup+"]").get();
				//TB_TempArray = jQuery("a.uploaded-a");
				for (TB_Counter = 0; ((TB_Counter < TB_TempArray.length) && (TB_NextHTML === "")); TB_Counter++) {
					//var urlTypeTemp = TB_TempArray[TB_Counter].href.toLowerCase().match(urlString);
						if (!(TB_TempArray[TB_Counter].href == url)) {						
							if (TB_FoundURL) {
								TB_NextMD = jQuery(TB_TempArray[TB_Counter]).metadata();
								TB_NextCaption = TB_TempArray[TB_Counter].title;
								TB_NextURL = TB_TempArray[TB_Counter].href;
								TB_NextHTML = "<span id='TB_next'><a href='#'><img alt='Next' src='http://a.espncdn.com/i/travel/passport/09/btn_next2.gif'/></a>&nbsp;&nbsp;</span>";
							} else {
								TB_PrevMD = jQuery(TB_TempArray[TB_Counter]).metadata();
								TB_PrevCaption = TB_TempArray[TB_Counter].title;
								TB_PrevURL = TB_TempArray[TB_Counter].href;
								TB_PrevHTML = "<span id='TB_prev'>&nbsp;&nbsp;<a href='#'><img alt='Next' src='http://a.espncdn.com/i/travel/passport/09/btn_prev2.gif'/></a></span>";
							}
						} else {
							TB_FoundURL = true;
							TB_imageCount = "<span style=\"padding: 7px;\">" + (TB_Counter + 1) +" of "+ (TB_TempArray.length) + "</span>";
						}
				}
			}
			

			imgPreloader = new Image();
			imgPreloader.onload = function(){
			imgPreloader.onload = null;
				
			// Resizing large images - orginal by Christian Montoya edited by me.
			var pagesize = tb_getPageSize();
			var x = pagesize[0] - 150;
			var y = pagesize[1] - 150;
			var imageWidth = imgPreloader.width;
			var imageHeight = imgPreloader.height;
			if (imageWidth > x) {
				imageHeight = imageHeight * (x / imageWidth); 
				imageWidth = x; 
				if (imageHeight > y) { 
					imageWidth = imageWidth * (y / imageHeight); 
					imageHeight = y; 
				}
			} else if (imageHeight > y) { 
				imageWidth = imageWidth * (y / imageHeight); 
				imageHeight = y; 
				if (imageWidth > x) { 
					imageHeight = imageHeight * (x / imageWidth); 
					imageWidth = x;
				}
			}
			// End Resizing
			
			TB_WIDTH = imageWidth + 30;
			TB_HEIGHT = imageHeight + 60;
			var TB_SeperateHTML = '&nbsp;|&nbsp;';
			if ( TB_NextHTML == '' && TB_TempArray.length > 1 ){
				TB_NextHTML = '<img alt="Next" src="http://a.espncdn.com/i/travel/passport/09/btn_next1.gif"/>';
			} else if ( TB_PrevHTML == '' && TB_TempArray.length > 1 ){
				TB_PrevHTML = '<img alt="Next" src="http://a.espncdn.com/i/travel/passport/09/btn_prev1.gif"/>';
			}
			
			// metaData info
			TB_TitleHTML = '';
			TB_title_class = ' ';
			TB_comme_class = ' ';
			if ( is_session_user(metaData.user) ){
				TB_title_class = 'editable-photo {type: \'title\', id: '+metaData.id+'}';
				TB_comme_class = 'editable-photo {type: \'comment\', id: '+metaData.id+'}';
			}
			if ( metaData.title && metaData.title != 'null' && metaData.title != 'Foo title' ){
				TB_TitleHTML = "<h2 style=\"margin-bottom: 0;\"><span class=\""+TB_title_class+"\">"+metaData.title+"</span></h2>";
			} else if ( is_session_user(metaData.user) ){
				TB_TitleHTML = "<h2 style=\"margin-bottom: 0;\"><span class=\""+TB_title_class+"\">Add a title...</span></h2>";
			}
			
			// delete code -- hackish
			TB_deleteHTML = '';
			if ( is_session_user(metaData.user) && metaData.id && imageGroup != 'globalGallery' ){
				// @removed until we can figure out a solution w community
				TB_deleteHTML = "&nbsp;&nbsp;|&nbsp;&nbsp;<span style=\"font-style: normal; color: #555;\"><a href=\"#\" class=\"del quickdel-photo {id: "+metaData.id+"}\">Delete</a></span>";
			}
			
			TB_userCreditHTML = ''
			if ( metaData.link && metaData.user ){
				TB_userCreditHTML = '<div style="float: right; font-style: italic; margin-top: 7px; font-size: 11px;">by <a href="'+metaData.link+'">'+metaData.user+'</a>'+TB_deleteHTML+'</div>';
			}
			
			jQuery("#TB_window").append("<div class=\"close\">"+TB_TitleHTML+"<a onclick=\"tb_remove(); return false;\" href=\"#\"><img src=\"http://a.espncdn.com/passport/dev/close.jpg\" style=\"right: -21px;\" alt=\"close\"/></a></div><img id='TB_Image' src='"+url+"' width='"+imageWidth+"' height='"+imageHeight+"' alt='"+caption+"'/>" + TB_userCreditHTML + "<div id='TB_caption' style='padding-top: 0px;'><span id='photo-caption' class=\""+TB_comme_class+"\">"+caption+"</span><div id='TB_secondLine'>" + TB_PrevHTML + TB_imageCount + TB_NextHTML + "</div></div>");
			
			//jQuery("#TB_closeWindowButton").click(tb_remove);
			
			if (!(TB_PrevHTML === "")) {
				function goPrev(){
					if(jQuery(document).unbind("click",goPrev)){jQuery(document).unbind("click",goPrev);}
					jQuery("#TB_window").remove();
					jQuery("body").append("<div id='TB_window' class='overlay'></div>");
					tb_show(TB_PrevCaption, TB_PrevURL, imageGroup, TB_PrevMD);
					return false;	
				}
				jQuery("#TB_prev").click(goPrev);
			}
			
			if (!(TB_NextHTML === "")) {		
				function goNext(){
					jQuery("#TB_window").remove();
					jQuery("body").append("<div id='TB_window' class='overlay'></div>");
					tb_show(TB_NextCaption, TB_NextURL, imageGroup, TB_NextMD);
					return false;	
				}
				jQuery("#TB_next").click(goNext);
				
			}

			document.onkeydown = function(e){ 	
				if (e == null) { // ie
					keycode = event.keyCode;
				} else { // mozilla
					keycode = e.which;
				}
				if(keycode == 27){ // close
					tb_remove(); 
				} else if(keycode == 37){ // display previous image
					if(jQuery('span#TB_prev').length > 0){
						document.onkeydown = "";
						goPrev();
					}
				} else if(keycode == 39){ // display next image
					if(jQuery('span#TB_next').length > 0){
						document.onkeydown = "";
						goNext();
					}
				}	
			};
			
			tb_position();
			jQuery("#TB_load").hide();
			//jQuery("#TB_ImageOff").click(tb_remove);
			jQuery("#TB_window").css({display:"block"}); //for safari using css instead of show
			windowToThickbox();
			};
			
			imgPreloader.src = url;
		}else{//code to show html
			
			var queryString = url.replace(/^[^\?]+\??/,'');
			var params = tb_parseQuery( queryString );

			TB_WIDTH = (params['width']*1) + 30 || 685; //defaults to 630 if no paramaters were added to URL
			TB_HEIGHT = (params['height']*1) + 40 || 460; //defaults to 440 if no paramaters were added to URL
			//TB_HEIGHT = ''
			ajaxContentW = TB_WIDTH - 30;
			ajaxContentH = TB_HEIGHT - 45;
			//ajaxContentH = TB_HEIGHT;
			
			if(url.indexOf('TB_iframe') != -1){// either iframe or ajax window		
					urlNoQuery = url.split('TB_');
					jQuery("#TB_iframeContent").remove();
					if(params['modal'] != "true"){//iframe no modal
						jQuery("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton' title='Close'>close</a> or Esc Key</div></div><iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='tb_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;' > </iframe>");
					}else{//iframe modal
					jQuery("#TB_overlay").unbind();
						jQuery("#TB_window").append("<iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='tb_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;'> </iframe>");
					}
			}else{// not an iframe, ajax
					if(jQuery("#TB_window").css("display") != "block"){
						if(params['modal'] != "true"){//ajax no modal
							/*jQuery("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton'>close</a> or Esc Key</div></div><div id='TB_ajaxContent' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px'></div>");*/
							/*jQuery("#TB_window").append("<div id='TB_ajaxContent' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px'></div>");*/
							/*jQuery("#TB_window").append("<div id='TB_ajaxContent' style='width:"+ajaxContentW+"px;'></div>");*/
							jQuery("#TB_window").append("<div id='TB_ajaxContent'></div>");
						}else{//ajax modal
							jQuery("#TB_overlay").unbind();
							jQuery("#TB_window").append("<div id='TB_ajaxContent' class='TB_modal' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;'></div>");	
						}
					}else{//this means the window is already up, we are just loading new content via ajax
						jQuery("#TB_ajaxContent")[0].style.width = ajaxContentW +"px";
						jQuery("#TB_ajaxContent")[0].style.height = ajaxContentH +"px";
						jQuery("#TB_ajaxContent")[0].scrollTop = 0;
						jQuery("#TB_ajaxWindowTitle").html(caption);
					}
			}
					
			jQuery("#TB_closeWindowButton").click(tb_remove);
			
				if(url.indexOf('TB_inline') != -1){	
					jQuery("#TB_ajaxContent").append(jQuery('#' + params['inlineId']).children());
					jQuery("#TB_window").unload(function () {
						jQuery('#' + params['inlineId']).append( jQuery("#TB_ajaxContent").children() ); // move elements back when you're finished
					});
					tb_position();
					jQuery("#TB_load").hide();
					jQuery("#TB_window").css({display:"block"}); 
					jQuery("#TB_window").css("z-index", "1000010"); 
				}else if(url.indexOf('TB_iframe') != -1){
					tb_position();
					if(jQuery.browser.safari){//safari needs help because it will not fire iframe onload
						jQuery("#TB_load").hide();
						jQuery("#TB_window").css({display:"block"});
					}
				}else{
					jQuery("#TB_ajaxContent").load(url += "&_=" + (new Date().getTime()),function(){//to do a post change this load method
						tb_position();
						jQuery("#TB_load").hide();
						tb_init("#TB_ajaxContent a.thickbox");
						jQuery("#TB_window").css({display:"block"});
					});
				}
			
		}

		// dont pass in params - modal
		//if(!params['modal']){
			document.onkeyup = function(e){ 	
				if (e == null) { // ie
					keycode = event.keyCode;
				} else { // mozilla
					keycode = e.which;
				}
				if(keycode == 27){ // close
					tb_remove();
				}	
			};
		//}
		
	} catch(e) {
		//nothing here
	}
}

//helper functions below
function tb_showIframe(){
	jQuery("#TB_load").hide();
	jQuery("#TB_window").css({display:"block"});
}

function tb_remove() {
	var c = true;
	if ( jQuery('.cal-ft li').length > 0 ){
	 	c = confirm(getGlobal('navigate-message'));
	}
 	if ( c ){
		jQuery("#TB_imageOff").unbind("click");
		jQuery("#TB_closeWindowButton").unbind("click");
		jQuery("#TB_window").fadeOut("fast",function(){jQuery('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
		jQuery("#TB_load").hide();
		if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
			jQuery("body","html").css({height: "auto", width: "auto"});
			jQuery("html").css("overflow","");
		}
		document.onkeydown = "";
		document.onkeyup = "";
	}
	return false;
}

function force_tb_remove(){
	jQuery("#TB_imageOff").unbind("click");
	jQuery("#TB_closeWindowButton").unbind("click");
	jQuery("#TB_window").fadeOut("fast",function(){jQuery('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
	jQuery("#TB_load").hide();
	if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
		jQuery("body","html").css({height: "auto", width: "auto"});
		jQuery("html").css("overflow","");
	}
	document.onkeydown = "";
	document.onkeyup = "";
	return false;
}

function tb_position() {
jQuery("#TB_window").css({marginLeft: '-' + parseInt((TB_WIDTH / 2),10) + 'px', width: TB_WIDTH + 'px'});
	if ( !(jQuery.browser.msie && jQuery.browser.version < 7)) { // take away IE6
		jQuery("#TB_window").css({marginTop: '-' + parseInt((TB_HEIGHT / 2),10) + 'px'});
	}
}

function tb_parseQuery ( query ) {
   var Params = {};
   if ( ! query ) {return Params;}// return empty object
   var Pairs = query.split(/[;&]/);
   for ( var i = 0; i < Pairs.length; i++ ) {
      var KeyVal = Pairs[i].split('=');
      if ( ! KeyVal || KeyVal.length != 2 ) {continue;}
      var key = unescape( KeyVal[0] );
      var val = unescape( KeyVal[1] );
      val = val.replace(/\+/g, ' ');
      Params[key] = val;
   }
   return Params;
}

function tb_getPageSize(){
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
	arrayPageSize = [w,h];
	return arrayPageSize;
}

function tb_detectMacXFF() {
  var userAgent = navigator.userAgent.toLowerCase();
  if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
    return true;
  }
}

function tb_init(domChunk){

	jQuery(domChunk).click(
		function(){
			var t = this.title || this.name || null;
			var a = this.href || this.alt;
			var g = this.rel || false;
			var md = jQuery(this).metadata();
			tb_show(t,a,g,md);
			this.blur();
			return false;
		}
	);
}

/* end thickbox js */

/* init links! */

function bindEditDeleteLinks(){

	/* bind add */
	//if ( jQuery('a.passport.thickbox').length > 0 ){
	jQuery('a.passport.thickbox').unbind(); // should be able to remove unbinds, since its live.
	tb_init('a.passport.thickbox');
	//}

	/* bind edit */
	jQuery('a.edit.thickbox').unbind();
	tb_init('a.edit.thickbox');

	/* bind to delete */
	jQuery('a.quick-del').die();
	jQuery('a.quick-del').live("click", function(){
		var c = confirm(getGlobal('delete-message'));
		if ( c ){
			var thisObj = jQuery(this);
			var uniqueId = thisObj.metadata().eventId;
			var redir = thisObj.metadata().redirect;
			dataObj = {eventId: uniqueId};
			if ( uniqueId == null || uniqueId == -1 ){
				var oldUniqueId = uniqueId;
				uniqueId = thisObj.metadata().venueId;
				dataObj.venueId = uniqueId;
				dataObj.eventId = oldUniqueId;
			}
			// theres better ways to do this, like specify an parent item to handle, but for now whatever
			if ( thisObj.parent('span').length == 1 ){ // unsaved items [add pg]
				thisObj = thisObj.parent();
			} else if ( thisObj.parent().parent('tr').length > 0 ){
				thisObj = thisObj.parent().parent('tr'); // events, venues
				thisObj.addClass('deleting');
			} else if ( redir == null ){
				thisObj = thisObj.parent('div').parent('div').parent('div.news-cont'); // activity, others
				thisObj.addClass('deleting');
			}
			
			jQuery.getJSON('/travel/passport/api/save/delete',
				dataObj,
				function(json){
					if ( !json.error ){
						if ( redir != null ){
							window.location = redir;
						} else {
							thisObj.removeClass('deleting');
							thisObj.remove();
							if ( jQuery('div.unsaved').length == 1 ){ // unsaved items

								if ( jQuery('div.unsaved').children('div').children('div').children('span').length == 0 ){
									jQuery('div.unsaved').hide('fast');
								}
							} else if ( thisObj.attr('tagName') == 'TR' ){ // resort tables
								jQuery('div#passport-content table.stamp-cont').tablesorter({widgets: ['zebra']});
							}
						}
					} else {
						alert('There was an error proccessing your request. Please try again.');
						thisObj.removeClass('deleting');
					}
				}
			);
		}
		return false;
	});
	
	jQuery('a.quick-save').live('click', function(){
		var thisObj = jQuery(this);
		var uniqueId = thisObj.metadata().eventId;
		var template = 'event';
		dataObj = {};
		if ( uniqueId == null || uniqueId == -1 ){
			dataObj.venueIds = thisObj.metadata().venueId+'~';
			var lnk = 'venue?vid='+thisObj.metadata().venueId;
			template = 'venue';
		} else {
			dataObj.eventIds = uniqueId+'~';
			var lnk = 'event?eid='+uniqueId;
		}
		var txt = thisObj.metadata().name;
		
		jQuery.getJSON('/travel/passport/api/save/updatestatus',
			dataObj,
			function(json){
				if ( !json.error ){
					if ( jQuery('div.unsaved').length == 1 ){ // unsaved items
						thisObj.parent('span').remove();
						if ( jQuery('div.unsaved').children('div').children('div').children('span').length == 0 ){
							jQuery('div.unsaved').hide('fast');
						}
						if ( txt != null ){
							jQuery('div#moredetails').html(' - <a href="/travel/passport/'+lnk+'">'+txt+'</a> - <a href="add/modal?'+template+'Id='+uniqueId+'" class="passport thickbox">Edit</a> | <a href="#" class="quick-del {'+template+'Id:'+uniqueId+'}">Delete</a><br/>');
							jQuery('div#moredetails').show();
							bindEditDeleteLinks();
							jQuery('div.updated').show('fast');
						}
					}
				}
			}
		);
		
		return false;
		
	});
	
	jQuery('a.quick-addf').live('click', function(){
		var thisObj = jQuery(this);
		thisObj.hide('slow');
		var opt = 1;
		if ( jQuery(thisObj.parent('li')).length > 0 ){
			var parentObj = jQuery(thisObj.parent('li'));
			parentObj.hide('fast');
			opt = 0;
		}
		var friendId = thisObj.metadata().userId;
		dataObj = {friendId: friendId};
		jQuery.getJSON('/travel/passport/api/save/addfriend',
			dataObj,
			function(json){
				if ( !json.error ){
					if (opt==0){
						jQuery(thisObj.parent('li')).html('<a href="#" class="quick-remf {userId: '+friendId+'}">Remove Friend</a>');
						parentObj.show('slow');
					} else if ( opt == 1 ){
						thisObj.toggleClass('quick-remf');
						thisObj.toggleClass('quick-addf');
						thisObj.html('Remove Friend');
					}
				}
			}
		);
		thisObj.show('slow');
		return false;
	});
	
	jQuery('a.quick-remf').live('click', function(){
		var thisObj = jQuery(this);
		thisObj.hide('slow');
		var opt = 1;
		if ( jQuery(thisObj.parent('li')).length > 0 ){
			var parentObj = jQuery(thisObj.parent('li'));
			parentObj.hide('fast');
			opt = 0;
		}
		var friendId = thisObj.metadata().userId;
		dataObj = {friendId: friendId};
		jQuery.getJSON('/travel/passport/api/save/removefriend',
			dataObj,
			function(json){
				if ( !json.error ){
					if ( opt == 0 ){
						jQuery(thisObj.parent('li')).html('<a href="#" class="quick-addf {userId: '+friendId+'}">Add Friend</a>');
						parentObj.show('slow');
					} else if ( opt == 1 ){
						thisObj.toggleClass('quick-remf');
						thisObj.toggleClass('quick-addf');
						thisObj.html('Add Friend');
					}
				}
			}
		);
		thisObj.show('slow');
		return false;
	});

}

// not going to do this on every page.

jQuery(
	function(){
		/*
		var wl = window.location+'';
		if ( wl.indexOf('/add') == -1 ){
			jQuery.getScript('/travel/passport/add/modal.js');
		}*/
		bindEditDeleteLinks();
		
	}
);

/* cant get this to work with jQ.live */
/* but this should work outside of dom load */
jQuery(window).bind('load', function() {
	jQuery('img.profile-img').each(function() {				
		if((typeof this.naturalWidth != "undefined" &&				
			this.naturalWidth == 0 ) 				
			|| this.readyState == 'uninitialized' ) {				
			var srcBad = jQuery(this).attr('src');
			if ( srcBad.indexOf('/90/') > -1 ){
				jQuery(this).attr('src','http://avatars.espn.go.com/assets/espn_images/33/90/b6692ea5df920cad691c20319a6fffd7a4a766b8/silo_dude.jpg');
			} else if ( srcBad.indexOf('/48/') > -1 ){
				jQuery(this).attr('src','http://avatars.espn.go.com/assets/espn_images/33/48/b6692ea5df920cad691c20319a6fffd7a4a766b8/silo_dude.jpg');
			}
		}				
	});			
});
