function showAll() {
  for(var i=0; i < arguments.length; i++){
     show( _proxy_jslib_handle(arguments, (i), 0, 0));
  }
  return false;
}

function hideAll() {
	for(var i=0; i < arguments.length; i++){
	   hide( _proxy_jslib_handle(arguments, (i), 0, 0));
	}
	return false;
}

function toggleAll() {
  for(var i=0; i < arguments.length; i++){
	   toggle( _proxy_jslib_handle(arguments, (i), 0, 0));
	}
	return false;
}

function toggleSub(submenu) {
   toggleSub2(submenu,'+','-');
}
function toggleSub2(submenu,show,hide) {
    if ( _proxy_jslib_handle(document, 'getElementById', '', 1, 0)(submenu).style.display == 'none') {
         _proxy_jslib_handle(document, 'getElementById', '', 1, 0)(submenu).style.display = 'block';
         _proxy_jslib_assign('',  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('toggle'+submenu), 'innerHTML', '=', ( hide));
    } else {
         _proxy_jslib_handle(document, 'getElementById', '', 1, 0)(submenu).style.display = 'none';
         _proxy_jslib_assign('',  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)('toggle'+submenu), 'innerHTML', '=', ( show));
    }
}

function disableAll() {
  $$(arguments).each(function(e) {e.disabled = true;});
}

function enableAll() {
  $$(arguments).each(function(e) {e.disabled = false;});
}

function toggleEnabledAll() {
  $$(arguments).each(function(e) {e.disabled = !e.disabled;});
}

/* effects */
function fadeIn(element, duration) {
   var fx = new (Fx.Style)(element, 'opacity',{duration: duration});
   fx.addEvent('onStart', function() { element.setStyle('display','');});
   fx.start(0,1);   
}

function fadeOut(element, duration) {
   var fx = new (Fx.Style)(element, 'opacity', {duration: duration});
   fx.addEvent('onComplete',function() {element.setStyle('display','none');});
   fx.start(1,0);   
}

/* lightspeed helpers */
function linkRemote(controller, action, replaceId) {
   new (Ajax)("/c/" + controller + "/" +  _proxy_jslib_handle(null, 'action', action, 0, 0),
             {method: 'get',update: $(replaceId)}).request();
}

/* lightspeed helpers */
function linkRemoteWithCallback(controller, action, callback) {
   new (Ajax)("/c/" + controller + "/" +  _proxy_jslib_handle(null, 'action', action, 0, 0), {method: 'get',onComplete:callback}).request();
}


function submitRemote(form,options) {
	if ( MooTools.version == "1.11") {
		$(form).send(options);
	} else {
		options.url =  _proxy_jslib_handle(form, 'action', '', 0, 0);
		var req = new (Request.HTML)(options).post($(form));
	}
}

/* end lightspeed helpers */

function autoCompleteSelected(element,tokens) {
	var name = element.id.substring("selectorfor".length + 1);
	var input =  _proxy_jslib_handle(document, 'getElementById', '', 1, 0)(name);
	 _proxy_jslib_assign('', input, 'value', '=', ( eval(_proxy_jslib_proxify_js(("name_to_ids_" + input.id + "['" +  _proxy_jslib_handle(element, 'value', '', 0, 0) + "']"), 0, 0) ))); 
}

function prefillWithDefault(id,defaultValue) {
	var elem = $(id);
	elem.addEvent('focus',function() {if( _proxy_jslib_handle(this, 'value', '', 0, 0) == defaultValue){ _proxy_jslib_assign('', this, 'value', '=', ( ''));}});
	elem.addEvent('blur',function() {if( _proxy_jslib_handle(this, 'value', '', 0, 0) == ''){ _proxy_jslib_assign('', this, 'value', '=', ( defaultValue));}});
}

function multiCompleteSelect(element,tokens) {
	var parent = $(element.parentNode); // apply moo prototypes
	var inputName = element.id.substring("selectorfor".length + 1);
	var input = $(element);
	
	// when we add one of these guys, 
	if (!$(inputName +  _proxy_jslib_handle(input, 'value', '', 0, 0))){
	
		var span = new (Element)("span",{'class':'added-username','id' : inputName +  _proxy_jslib_handle(input, 'value', '', 0, 0)});
		var hidden = new (Element)("input", {
					'type':'hidden',
					'value':  _proxy_jslib_handle(eval(_proxy_jslib_proxify_js(("name_to_ids_" + inputName), 0, 0) ), ( _proxy_jslib_handle(input, 'value', '', 0, 0)), 0, 0),
					'name' : 'ids[]'

 });	
		var anchor = new (Element)('a',{'events' : {
													// this happens when someone clicks on the remove links
											  		'click': function() {
											  			var toKill = $(this.parentNode)
											  			fx = new (Fx.Style)(toKill,'opacity',{ duration: 500, transition: Fx.Transitions.Quart.easeIn});		
											  			fx.addEvent('onComplete', function() {toKill.remove();});
											  			fx.start(1,0);
											  		 }
									  		      },
									   'href':'javascript:void(0);',
									   'class':'remove'

 }
							      ).adopt(new (Element)('img', { 'border':'0','src':'/img/Remove.png'}));			
		span.setHTML( _proxy_jslib_handle(element, 'value', '', 0, 0));
		span.adopt(hidden);
		span.adopt(anchor);
		span.injectBefore(input);
		 _proxy_jslib_assign('', input, 'value', '=', (''));
	}
  
}

function initAjaxAutocomplete(id,tokens,onSelectCallback) {
	var selector = $$('#' + id);
	if ( selector != null){
		selector.addEvent('focus',function() {
			var selectorName = id.substring("selectorfor-".length);
			var namesToIds = eval(_proxy_jslib_proxify_js(('name_to_ids_' + selectorName), 0, 0) );
			
			if (namesToIds == null){
			   if(MooTools.version == "1.11") {
   				new (XHR)({
   				   async: true, 
   					method: 'get',
   					onRequest: function() {
   				      $(selectorName + "-throbber").setStyle('display','inline');
   				   },
   				   onSuccess: function(response) {
   				      var json = Json.evaluate(response);
   				      eval(_proxy_jslib_proxify_js(('name_to_ids_' + selectorName + "= json.nameToIds"), 0, 0) );
   				      initAutocomplete(id,json.list,onSelectCallback);
   				      $(selectorName + "-throbber").setStyle('display','none');
   				   }
   				}).send("/ajax/friend-data", null);
			   } else {
			      new (Request.JSON)({
			         url: '/ajax/friend-data',
			         method: 'get',
                  onRequest: function() {
                     $(selectorName + "-throbber").setStyle('display','inline');
                  },
                  onSuccess: function(json) {
                     eval(_proxy_jslib_proxify_js(('name_to_ids_' + selectorName + "= json.nameToIds"), 0, 0) );
                     initAutocomplete(id,json.list,onSelectCallback);
                     $(selectorName + "-throbber").setStyle('display','none');
                  }
			      }).send();
			   }
			}
		});
	}
}

function initAutocomplete(id,tokens,onSelectCallback) {
	onSelectCallback = onSelectCallback|| autoCompleteSelected;
	
	var el = $$('#' + id);
	
	var completer = new (Autocompleter.Local)(el[0], tokens, {
		'delay': 100,
		'maxChoices':500,
		'filterTokens': function() {
			var regex = new (RegExp)('^' + this.queryValue.escapeRegExp(), 'i');
			return this.tokens.filter(function(token) {
				return (regex.test(token[0]) || regex.test(token[1]));
			});
		},
		'injectChoice': function(choice) {
		    var name = (choice[0].length > 20)? choice[0].substring(0,10) + "..." : choice[0];
		    var un  = null;
		    if ( choice.length > 1){
		     	un = (choice[1].length > 20)? choice[1].substring(0,10) + "..." : choice[1];
		    }
			var el = new (Element)('li');
			
			if(MooTools.version == '1.11') {
			   el.setHTML(this.markQueryValue(name));
			} else {
			   el.set('text', this.markQueryValue(name));
			}
			
			if ( un != null) {
			   var newEle = new (Element)('span', {'class': 'username'});
			   if(MooTools.version == '1.11') {
			      newEle.setHTML('&lt;' + this.markQueryValue(un) + '&gt;');
	         } else {
	            newEle.set('text', '&lt;' + this.markQueryValue(un) + '&gt;');
	         }
			   el.adopt(newEle);
			}
			el.inputValue = choice[0];
			this.addChoiceEvents(el).injectInside(this.choices);
		},
		'onSelect' : onSelectCallback

 });
}



/* multi friend selector stuff */

var numAdded = 0;
var max = 0;

function toggleFriend(link,memberId) {
	var elem = $(link);
	if (elem.getParent().hasClass('added')){
		removeFriend(elem,memberId);
	} else {
		addFriend(elem,memberId);
	}
	var addedFriendsLink = $E("a","added-friends");
	addedFriendsLink.setHTML(addedFriendsLink.getProperty('title') + ' (' + numAdded + '/' + max + ')');
}

function clearFriends(form) {
	var inputs = $$('.friend-id');
	for(var i = 0 ; i < inputs.length; i++){
		 _proxy_jslib_handle(inputs, (i), 0, 0).remove();
	}
	return false;
}

function removeFriend(link,memberId) {
	$E('#friend-element-' + memberId).toggleClass('added');
	$E('#toggler-' + memberId).toggleClass('added');
	$E('#input-' + memberId).remove();
	var removed = $E('#toggler-' + memberId);
	$E('#not-added').adopt(removed);
	numAdded--;
	
}
function addFriend(link,memberId) {
	if ( numAdded < max ){
		$E('#friend-element-' + memberId).toggleClass('added');
		$E('#toggler-' + memberId).toggleClass('added');
		numAdded++;
		var ul = link.getParent();
		var added = $E('#toggler-' + memberId);
		added.remove();
		
		$E('#already-added').adopt(added);
		link.adopt(new (Element)('input',
					  		      {'type' : 'hidden', 
					  		      'name' :"ids[]", 
					  		      'class' : 'friend-id',
					  		      'value' : memberId, 
					  		      'id' : "input-" + memberId

 }));
	}
}

function selectTopFriends(selectorId) {
    var top = $$('#'+selectorId+" a.top").each(function(element,idx) {
        var memberId = $(element).getParent().id.substring("friend-element-".length);
        toggleFriend(element,memberId);
    });
   ;
}

function select(element,containerId,toEnable,toDisable) {
	$E('.current',containerId).toggleClass('current');	 
	$(element).getParent().toggleClass('current');
	
	$(toEnable).setStyle('display','');
	for(var i=0; i < toDisable.length; i++){
		$( _proxy_jslib_handle(toDisable, (i), 0, 0)).setStyle('display','none');
	}

}

/* rating tag stuff */
function enhanceAppRatingTags() {
   $$(".app-rating").each(function(element) {
      element.rating = element.getAttribute("rating");
      element.formToken = element.getAttribute("FormToken");
      element.originalRating = element.rating;
      setRatingImage(element, element.getAttribute("friend") == "Y", element.rating);
      //alert("appId=" + element.appId);
      if (element.getAttribute("appId") != null) {
         element.appId = element.getAttribute("appId");
         element.addEvents({
            "mouseleave": function(event) {
               element.rating = element.savingRating == null ? element.originalRating : element.savingRating;
               setRatingImage(element, false, element.rating);
            },
            "mousemove": function(event) {
               var star = calculateStar(new (Event)(event));
               setRatingImage(element, true, star);
            },
            "click": function(event) {
                        var star = calculateStar(new (Event)(event));
                        new (Json.Remote)("/c/apps/save_rating?AppId=" + element.appId + "&NewRatingNum=" + star + "&FormToken=" + element.formToken,
                                {onComplete: function(response) {
                                                if(response.data.result=="Saved") {
                                                   element.originalRating = element.rating = star;
                                                   //open the review box
                                                   openReviewLightBox("review"+element.appId);
                                                } else {
                                                   element.rating = element.originalRating;
                                                }
                                                element.savingRating = null;
                                                setRatingImage(element, false, star);
                                             } 
                                }).send();
               element.savingRating = element.rating = star;
               setRatingImage(element, true, star);
            }
         });
      }
   }); 
}
                                                   
function calculateStar(event) {
   var target = $(event.target);
   return Math.ceil((event.client.x - target.getLeft())/(target.getCoordinates().width/5));
}

function setRatingImage(imgElement, friend, rating) {
   var stars = rating === undefined ? 0 : Math.round(rating);
    _proxy_jslib_handle(imgElement, 'setAttribute', '', 1, 0)("src", "/img/" + (friend ? "Orange" : "Red") + "Stars" + stars + ".png");
}
/* end rating tag stuff */

/* app icon zoom stuff */
function enhanceMyApplications() {
   var div = $("my-applications");
   var drawer = div.getElement(".drawer");
   var slide = new (Fx.Slide)(drawer);
   slide.hide();
   var toggle = div.getElement("a.toggle");
   toggle.addEvent("click", function(event) {
      if (div.hasClass("expand")) {
         {var _proxy_jslib_with_objs= [] ;with (_proxy_jslib_with_objs[_proxy_jslib_with_objs.length]= (new (Event)(event))) {
            div.removeClass("expand");
            slide.stop();
            slide.slideOut();
            stop();
         }; _proxy_jslib_with_objs.length-- ;}
      } else {
         {var _proxy_jslib_with_objs= [] ;with (_proxy_jslib_with_objs[_proxy_jslib_with_objs.length]= (new (Event)(event))) {
            div.addClass("expand");
            slide.stop();
            slide.slideIn();
            stop();
         }; _proxy_jslib_with_objs.length-- ;}
      }
   });
}
/* end app icon zoom stuff */

/* app review stuff */
var reviewlightbox;

function enhanceAppReviews() {
	$$(".app_review_form").each(
		function(element) {
        	element.addEvents({
           	 		"submit": function(event) {
                        new (Event)(event).stop();
                        this.send({
                        	onComplete: function(response) {
		    					if (typeof(reviewlightbox) != "undefined")  _proxy_jslib_handle(reviewlightbox, 'close', '', 1, 0)();
		    				}
		    			})

 }
  				})

 }
  	)

}

function openReviewLightBox(id) {
   if (typeof(reviewlightbox) != "undefined")  _proxy_jslib_handle(reviewlightbox, 'close', '', 1, 0)();
   reviewlightbox = new (LightBox)(id,{'valign':'top'});
    _proxy_jslib_handle(reviewlightbox, 'open', '', 1, 0)();
   reviewlightbox.element.getElement('textarea').focus();
}

/* end app review stuff */

/* app tooltip stuff */
function enhanceAppLinks() {
   var container = $("top-rated-applications")
   container.responses = new (Object)();
   var memberId = container.getAttribute("memberId");
   //alert("memberId=" + memberId);
   var tooltip = $("app-tool-tip");
   var body = $E("body");
   //alert(body.id); 
   tooltip.injectTop( _proxy_jslib_handle(null, 'body', body, 0, 0));
   $$(".app-link").each(function(element) {
      element.addEvents({
         "mouseenter" : function(event) {
            var appId = element.getAttribute("appId");
            var data =  _proxy_jslib_handle(topRatedApplicationsToolTipData, (appId), 0, 0);
            setupTooltip(tooltip, data);
            showAppTooltip(tooltip, element);
         }, 
         "mouseleave" : function(event) {
            hideTooltip(tooltip);
         } 
      });
   });
   tooltip.addEvents({
      "mouseenter" : function(event) {
         if (tooltip.fx != undefined) {
            tooltip.fx.stop();
         }
         if (tooltip.getStyle("opacity") > 0.5) {
            tooltip.setStyle("opacity", "1");
         } else {
            tooltip.setStyle("opacity", "0");
         }
      }, 
      "mouseleave" : function(event) {
         hideTooltip(tooltip);
      } 
   });
};

function setupTooltip(tooltip, response) {
   tooltip.getElement("h1").setHTML(response.appName);
   setRatingImage(tooltip.getElement(".friends-rating"), true, response.friendRating);
   setRatingImage(tooltip.getElement(".bebo-rating"), false, response.beboRating);
   var label = tooltip.getElement("label#recently-added-label");
   var ul = tooltip.getElement("ul#recently-added");
   ul.empty();
   var recentlyAdded = response.recentlyAdded;
   if (recentlyAdded.length > 0) {
      label.setStyle("display", "block");      
      ul.setStyle("display", "block");      
      for(var i = 0; i < recentlyAdded.length; i+=1) {
         var one =  _proxy_jslib_handle(recentlyAdded, (i), 0, 0);
         var li = new (Element)("li");
         li.injectInside(ul);
         var a = new (Element)("a", {"href":"?MemberId=" + one.memberId}); //E4T
         a.setText(one.displayName);
         a.injectTop(li);
         //alert(ul.innerHTML);
      }
   } else {
      label.setStyle("display", "none");      
      ul.setStyle("display", "none");      
   }
}

function showAppTooltip(tooltip, element) {
   var c = element.getCoordinates();
   var left = (c.left + c.right) / 2 - 27;
   var correctedLeft = Math.min(left, window.getWidth() - 265);
   tooltip.setStyle("left", correctedLeft);
   tooltip.setStyle("background-position", (left - correctedLeft - 247) + "px bottom");
   tooltip.setStyle("bottom", window.getHeight() - element.getElement("img").getTop() - 7);
   tooltip.setStyles({display: 'block',opacity: 0});
   if (tooltip.fx != undefined) {
      tooltip.fx.stop();
   }
   tooltip.fx = new (Fx.Style)(tooltip, 'opacity', {transition: Fx.Transitions.Cubic.easeIn, duration: 300, onComplete : function(event) {tooltip.fx=undefined;}} ).start(1);
}

function hideTooltip(tooltip) {
   if (tooltip.fx != undefined) {
      tooltip.fx.stop();
   }
   tooltip.fx = new (Fx.Style)(tooltip, 'opacity', {transition: Fx.Transitions.Cubic.easeOut, duration: 800, onComplete : function(event) {tooltip.setStyle("display", "none"); tooltip.fx=undefined;}}).start(0);
}
/* end app tooltip stuff */


/* add-app page: kickAnApp */
function updateKickAnApp(form, appId, kickMyAppId) {
   memberSelect = form.MemberToAddApp;
   selectedMember =  _proxy_jslib_handle( _proxy_jslib_handle(memberSelect.options, (memberSelect.selectedIndex), 0, 0), 'value', '', 0, 0);
   if (selectedMember != "") {
       memberArray = selectedMember.split("_");
       memberId = memberArray[0];
       typeCd = memberArray[1];
       linkRemote('apps','kick_an_app?mid='+memberId+'&aid='+appId, kickMyAppId); 
   }
} 
/* add-app page: kickAnApp */

/* drop down */
function closeDropDowns(id) {
	$$('.drop-down-options').each(function(elem) {elem.style.display = 'none';});
	$('content').removeEvent('click',closeDropDowns);
}
function dropDownSelected(id) {
	toggle(id);
	 _proxy_jslib_handle(null, 'setTimeout', setTimeout, 1, 0)("$('content').addEvent('click',closeDropDowns)",100);
}
/* end drop down  */

/*lightbox*/
var LightBox = new (Class)({
  initialize: function(element) {
    this.params = arguments[1];
    if (arguments[1] == null){
        this.params = {};
    }
    
    if ($type(element) == 'element') {
      this.element = element;
    } else {
      this.element = $(element);
    }

    //init element
    this.element.setStyle('z-index', '9999');
    this.element.setStyle('position', 'absolute');
    this.element.setStyle('background-color', 'white');
    this.element.injectInside( _proxy_jslib_handle(document, 'body', '', 0, 0));

    //init background
    if (!$defined($('lightbox_bg'))) { 
      margin = 8;
      this.bg = new (Element)('div');
      this.bg.setStyle('id', 'lightbox_bg');
      this.bg.injectAfter(this.element);
      this.bg.setStyle('z-index', '9998');
      this.bg.setStyle('background-color', 'black');
      this.bg.setStyle('position', 'absolute');
    }

     _proxy_jslib_handle(this, 'close', '', 1, 0)();
  }
});

LightBox.implement({
	open: function() {
	  //display
	  this.element.setStyle('display', 'block');
	  this.element.setOpacity(1);
	
	  //hide all ads
	  $$('div.advertisement').each(function(ad, index) {
	     ad.setOpacity(0);
	  });
	
	  var eleSize = {};
	  
	  if(MooTools.version == '1.11') {
	     eleSize = this.element.getSize().size;
	  } else { // version >= 1.2
	     eleSize = this.element.getSize();
	  }
	  
	  //center
	  elementLeft = parseInt(window.getWidth()/2 - eleSize.x/2);
	  if (this.params.valign == 'top'){
	      elementTop = 80;
	  } else {
	      elementTop = parseInt(window.getHeight()/2 - eleSize.y/2);
	      elementTop = elementTop<80? 80 : elementTop;
	  } 
	  
	 if(MooTools.version == '1.11') {
		this.element.setStyle('left', elementLeft);
		this.element.setStyle('top', elementTop);
		this.element.setStyle('position', 'fixed');
		
		//show and center bg
		this.bg.setStyle('display', 'block');
		this.bg.setStyle('top', elementTop - margin);
		this.bg.setStyle('left', elementLeft - margin);
		this.bg.setStyle('width', eleSize.x + margin * 2);
		this.bg.setStyle('height', eleSize.y + margin * 2);
		this.bg.setStyle('position', 'fixed');
		this.bg.setOpacity(0.4);
	 } else { // version >= 1.2
	    this.element.set('styles', {
	       'left': elementLeft,
	       'top': elementTop,
          'position': 'fixed'

 });
	    
	    this.bg.set('styles', {
	       'display': 'block',
	       'position': 'fixed',
	       'top': elementTop - margin,
	       'left': elementLeft - margin,
	       'width': eleSize.x + margin * 2,
	       'height': eleSize.y + margin * 2,
	       'opacity': 0.4

 });
	 }
	  
	  //show and position close button
	  this.visible = true;
	}
});

LightBox.implement({
  close: function() {
    this.bg.setOpacity(0);
    this.bg.setStyle('display', 'none');
    this.element.setOpacity(0);
    this.element.setStyle('display', 'none');
    this.visible = false;

    //show ads again
    $$('div.advertisement').each(function(ad, index) {
          ad.setOpacity(1);
       });

  }
});

LightBox.implement({
    destroy: function() {
        this.element.remove();
    }
});

LightBox.implement({
  toggle: function() {
    if (!this.visible) {
       _proxy_jslib_handle(this, 'open', '', 1, 0)();
    } else {
       _proxy_jslib_handle(this, 'close', '', 1, 0)();
    }
  }
});
/* end lightbox */


/* photoselector */
//(to be used with sn:photo-selector tag)
var activePhotoSelector;

var PhotoSelector = new (Class)({
  initialize: function(id, member_id, select, deselect, url, size) {
    this.id = id; //id of photo_selector div
    this.member_id = member_id;
    this.select_callback = select;
    this.deselect_callback = deselect;
    //this.remote_url = '/c/photo_selector/'
    this.base_url = url;//'/c/photo_selector/'; // //
    this.size = size;
    //make div a lightbox
    this.lightbox = new (LightBox)('selector' + this.id, {'valign':'top'});
     _proxy_jslib_assign('', this, 'content', '=', ( $('content' + this.id)));
    this.tip = $('tip' + this.id);
    this.add_link = $('add' + this.id);
    this.remove_link = $('remove' + this.id);
    this.photo = $('photo' + this.id);
    this.active = false;
  }
});

PhotoSelector.implement({
  loading: function() {
     _proxy_jslib_handle(this, 'content', '', 0, 0).setHTML('<img src="/img/throbber_default.gif" /> Loading...');
  }
});

PhotoSelector.implement({
  open: function() {
    if (!activePhotoSelector) {
	  activePhotoSelector = this;
	   _proxy_jslib_handle(this.lightbox, 'open', '', 1, 0)();
	  this.active = true;
      this.render();
	}
  }
});

PhotoSelector.implement({
  render: function() {
    this.loading();
  	 _proxy_jslib_assign('', this.tip, 'innerHTML', '=', ( 'First, pick an album to open:'));
	//show albums
	url = this.base_url + 'show_albums?MemberId=' + this.member_id + '&no_layout=1';
	new (Ajax)(url, {onComplete:function(transport) {  _proxy_jslib_handle(activePhotoSelector, 'content', '', 0, 0).setHTML(transport); }}).request();
  }
});

PhotoSelector.implement({
  select_album: function(album_id) {
  	this.album_id = album_id;
    this.loading();
    this.tip.setHTML('Now select a photo to use (<a href="javascript:activePhotoSelector.render();">back</a>)');
    //show photos
 	url = this.base_url + 'show_photos?MemberId=' + this.member_id + '&AlbumId=' + this.album_id + '&Size=' + this.size + '&no_layout=1';
  	new (Ajax)(url, {onComplete:function(transport) {  _proxy_jslib_handle(activePhotoSelector, 'content', '', 0, 0).setHTML(transport); }}).request();
  }
});

PhotoSelector.implement({
  select_photo: function(photo_id, file_url) {
  	this.photo_id = photo_id;
  	//swap the add/remove
  	this.add_link.setStyle('display', 'none');
  	this.remove_link.setStyle('display', 'inline');
  	//insert the image
  	this.photo.setHTML('<img src="' + file_url + '"/>');
    //call the callback
    eval (_proxy_jslib_proxify_js((this.select_callback + '(photo_id, file_url);'), 0, 0) );
     _proxy_jslib_handle(this, 'close', '', 1, 0)();
  }
});

PhotoSelector.implement({
  deselect_photo: function() {
  	this.photo_id = null;
  	//swap the add/remove
  	this.remove_link.setStyle('display', 'none');
  	this.add_link.setStyle('display', 'inline');
  	//remove image
  	this.photo.setHTML('');
  	eval (_proxy_jslib_proxify_js((this.deselect_callback + '();'), 0, 0) );
     _proxy_jslib_handle(this, 'close', '', 1, 0)();
  }
});

PhotoSelector.implement({
  close: function() {
  	activePhotoSelector = null;
  	this.active = false;
  	 _proxy_jslib_handle(this.lightbox, 'close', '', 1, 0)();
  }
});

//default photoselect callback
function wee(photo_id, file_url) {
  alert('selected photo: ' + photo_id);
}
/* end photoselector */

/* dialog */
function showDialog(id) {
   closeDialog();
   var orig = $(id + "-orig");
   // cloning protects agains mock ajax permanently messing with 
   // the original contents of the box.
   var cloned = orig.clone();
   var form = $E('form',cloned);
   if ( form != null) {
      form.id = form.id.substring(0,form.id.length - "-orig".length);
   }
   cloned.id = id;
   cloned.injectAfter(orig);
   
   window.dialogBox = new (LightBox)(id,{'valign':'top'});
    _proxy_jslib_handle(window.dialogBox, 'open', '', 1, 0)();
}

function submitDialog(formId) {
   var form = $(formId);
   //IE does not find the element to submit (a cloned form) in the
   //previous line, the hack below fixes that problem
   if (form.id=="") { //damn IE!
      var formArray =  _proxy_jslib_handle(document, 'getElementsByTagName', '', 1, 0)('form');
      for (i=0; i<formArray.length; i++) {
         if ( _proxy_jslib_handle(formArray, (i), 0, 0).id==formId) {
            form =  _proxy_jslib_handle(formArray, (i), 0, 0);
            break;
         }
      }
   }
   form.submit();
}

function closeDialog() {
   if ( window.dialogBox != null) {
       _proxy_jslib_handle(window.dialogBox, 'close', '', 1, 0)();
      window.dialogBox.destroy();
      window.dialogBox = null;
   }
}

/* app tracking */
function initFocusTracker(appId) {
   var heartbeat =  _proxy_jslib_handle(window, 'setInterval', '', 1, 0)('heartbeat(\''+appId+'\')', 60000);
   var intervalSet = true;
   $(window).addEvent('focus', function() {canvasFocus(appId); if (!intervalSet) {heartbeat =  _proxy_jslib_handle(window, 'setInterval', '', 1, 0)('heartbeat(\''+appId+'\')', 60000); intervalSet = true;}});
   $(window).addEvent('blur', function() {canvasBlur(appId); window.clearInterval(heartbeat); intervalSet = false;});
   $(window).addEvent('unload', function() {canvasBlur(appId);});
}

function canvasBlur(appId) {
   new (Ajax)("/c/apps/canvas_blur?AppId="+appId, {method: 'get'}).request();
}

function canvasFocus(appId) {
   new (Ajax)("/c/apps/canvas_focus?AppId="+appId, {method: 'get'}).request();
}

function heartbeat(appId) {
   new (Ajax)("/c/apps/canvas_heartbeat?AppId="+appId, {method: 'get'}).request();
}

function recordNotificationClick(appIdNotif,sourceCd,sourceId,hasNotifApp,appUsernameLink) {
   new (Ajax)("/c/app_request/record_notification_click?AppIdNotif="+appIdNotif+"&SourceCd="+sourceCd+"&SourceId="+sourceId+"&AppUsernameLink="+appUsernameLink+"&HasNotifApp="+hasNotifApp, {method: 'get', async:false}).request();
}

function recordInvitationClick(appIdInvite,sourceCd,sourceId,hasInviteApp,appUsernameLink) {
   new (Ajax)("/c/app_request/record_invitation_click?AppIdInvite="+appIdInvite+"&SourceCd="+sourceCd+"&SourceId="+sourceId+"&AppUsernameLink="+appUsernameLink+"&HasInviteApp="+hasInviteApp, {method: 'get', async:false}).request();
}

function trackAppSourceInstall(appId,sourceCd,sourceId) {
   if (window.Ajax) {   
      new (Ajax)("/c/app_request/track_app_source_install?AppId="+appId+"&SourceCd=" + sourceCd+"&SourceId="+sourceId, {method: 'get',async:false}).request();
   } else {
      new (Request)({method:'get', url: '/c/app_request/track_app_source_install'}).send("AppId="+appId+"&SourceCd="+sourceCd+"&SourceId="+sourceId);  
   }
}

function recordNotificationView() {
   new (Ajax)("/c/app_request/record_notification_view", {method: 'get'}).request();
}

function recordInvitationView() {
   new (Ajax)("/c/app_request/record_invitation_view", {method: 'get'}).request();
}

function trackAppCanvasView(appId,sourceCd) {
   if (window.Ajax) {
      new (Ajax)("/c/app_request/track_app_canvas_view?AppId="+appId+"&SourceCd="+sourceCd, {method: 'get'}).request();
   } else {
      new (Request)({method:'get', url: '/c/app_request/track_app_canvas_view'}).send("AppId="+appId+"&SourceCd="+sourceCd);
   }
}

function trackAppByUsername(appUsername,sourceCd,sourceId) {
   if (window.Ajax) {
      new (Ajax)("/c/app_request/track_app_by_username?AppUsername="+appUsername+"&SourceCd="+sourceCd+"&SourceId="+sourceId, {method: 'get',async:false}).request();
   } else {
      new (Request)({method:'get', async:false, url: '/c/app_request/track_app_by_username'}).send("AppUsername="+appUsername+"&SourceCd="+sourceCd+"&SourceId="+sourceId);
   }
}
/* app tracking */     ;
_proxy_jslib_flush_write_buffers() ;