$(document).ready(function(){
	
	// Minibrowser
	if (parent.Sbrowse) {
		//parent.Sbrowse.fancy.setPicFancy();
	}else{
		//Extension
		var $link = $('a#pic_edit', document);
		if ($link.length) {
			
			// to refresh image with
			var tmp = new Date();
			tmp = "?" + tmp.getTime()
			var locImage = $link.find('img');
			
			var user_id = $link.attr("user_id");
			var group_id = $link.attr('group_id');
			if (group_id != undefined) {
				$link.children(':first').css("height", "125px");
				$link.attr("href", "/groups/edit/pic/" + group_id + "/").fancybox({
					'frameWidth': 350,
					'frameHeight': 340,
					'callbackOnClose': function(){
						locImage.attr("src", locImage.attr("src") + tmp);
					}
				});
			}
			else if(user_id != undefined){// group_id is not defined, so ensure the userid is the admin
				
				// If extension has checked authority to edit the image, set fancy box.
				if($link.attr("href") != undefined){
					$link.fancybox({
					'frameWidth': 350,
					'frameHeight': 340,
					'callbackOnClose': function(){
						locImage.attr("src", locImage.attr("src") + tmp);
						}	
					});
				}
			}
		}
	}
	
	
	//------------------- collapse side boxes -------------------
	// Minibrowser
	if (parent.Sbrowse) {
		$(".side_box").each(function(){
			var $sideBox = $(this).find(".friends_box");
			var ch_len = $sideBox.children(".side_profile_pic").length;
			if(ch_len<9){
				if(ch_len<5){
					$sideBox.css("height","50px");
				}else{
					$sideBox.css("height","100px");
				}
			}
		});
	// Extension
	}else{
		$(".side_box", $(document)).each(function(){
			var $sideBox = $(this).find(".friends_box");
			var ch_len = $sideBox.children(".side_profile_pic").length;
			if(ch_len<9){
				if(ch_len<5){
					$sideBox.css("height","50px");
				}else{
					$sideBox.css("height","100px");
				}
			}
		});
	}
});




