function state(cla,text,href,name){
		var _className = cla;
		var _v = text;
		var _url = href;
		var uid = name;
		var _pobj = $('#onlineStatueList');
		$.ajax({
			type: "GET",
			url: _url,
			success: function(data){
				 if(data == 0){
					 window.location.href = _base_path+'user/logout';
				 }else if(data == 1 || data == 2 || data == 4 || data == 5 || data == 3){
					 _pobj.prev('a').attr('class',_className).text(_v);
					 _pobj.hide();
					 $('#onlineStatueList').empty();
						if(_v!='Invisible')
						$('#onlineStatueList').append('<a onclick="state(\'invisible\',\'Invisible\',\''+_base_path+'user/status/'+uid+'/2\',\''+uid+'\')" class="invisible" name="'+uid+'" title="2" url="'+_base_path+'user/status/'+uid+'/2">Invisible</a>');
						if(_v!='Visible')
						$('#onlineStatueList').append('<a onclick="state(\'visible\',\'Visible\',\''+_base_path+'user/status/'+uid+'/1\',\''+uid+'\')" class="visible" name="'+uid+'" title="1" url="'+_base_path+'user/status/'+uid+'/1">Visible</a>');
						if(_v!='Invisible in Network')
						$('#onlineStatueList').append('<a onclick="state(\'visibleInNet\',\'Invisible in Network\',\''+_base_path+'user/status/'+uid+'/4\',\''+uid+'\')" class="visibleInNet" name="'+uid+'" title="4" url="'+_base_path+'user/status/'+uid+'/4">Invisible in Network</a>');
						if(_v!='Away')
						$('#onlineStatueList').append('<a onclick="state(\'alway\',\'Away\',\''+_base_path+'user/status/'+uid+'/5\',\''+uid+'\')" class="alway" name="'+uid+'" title="5" url="'+_base_path+'user/status/'+uid+'/5">Away</a>');
						if(_v!='Invisible outside Network')
						$('#onlineStatueList').append('<a onclick="state(\'visibleOutNet\',\'Invisible outside Network\',\''+_base_path+'user/status/'+uid+'/3\',\''+uid+'\')" class="visibleOutNet" name="'+uid+'" title="3" url="'+_base_path+'user/status/'+uid+'/3">Invisible outside Network</a>');						
				
					// 
					 webChatstatus(data);
				 
				 
				 }else{
					 //alert('Change Status Error!');
				 }
			}
		});
		return false;
	}
$(function(){
	//SelectCity(CityData,'citylist','citycode',0);	   
	var pobj = $('#mainNav');
	var obj = pobj.find('span');
	var mType = $.cookie('maiNavShow') || null;
	pobj.isHide = false;
	obj.isHide = false;
	if(mType){
		if(mType == 'text'){
			obj.hide();
			obj.isHide = true;
		}else if(mType == 'img'){
			obj.show();
			obj.isHide = false;
		}else{
			pobj.hide();
			pobj.isHide = true;
		}
	}
	$('#navImgShow').click(function(){
		if(pobj.isHide){
			pobj.show();
			pobj.isHide = false;
			$.cookie('maiNavShow','img',{expires: 90});
		}
		if(obj.isHide){
			obj.slideDown('fast');
			obj.isHide = false;
			$.cookie('maiNavShow','img',{expires: 90});
		}
		return false;
	});
	$('#navTextShow').click(function(){
		if(pobj.isHide){
			obj.hide();
			pobj.show();
			pobj.isHide = false;
			$.cookie('maiNavShow','text',{expires: 90});
		}
		if(!obj.isHide){
			obj.slideUp('fast');
			obj.isHide = true;
			$.cookie('maiNavShow','text',{expires: 90});
		}
		return false;
	});
	$('#navHide').click(function(){
		$('#mainNav').hide();
		$.cookie('maiNavShow','hidden',{expires: 90});
		pobj.isHide = true;
		return false;
	});
	
	$('#onlineStatue').hover(function(){
		$('#onlineStatueList').show();
	},function(){
		$('#onlineStatueList').hide();
	}).children('a').eq(0).click(function(){
		return false;
	});
	//userStatu
	$('#onlineStatueList a').click(function(){
		var _className = $(this).attr('class');
		var _v = $(this).text();
		var _url = $(this).attr('href');
		var uid = $(this).attr('name');
		var _pobj = $(this).parent('#onlineStatueList');
		var _tt = $(this);
		$.ajax({
			type: "GET",
			url: _url,
			success: function(data){
				 if(data == 0){
					 window.location.href = _base_path+'user/logout';
				 }else if(data == 1 || data==2 ||  data == 4 || data == 5 || data == 3){
					 _pobj.prev('a').attr('class',_className).text(_v);
					 _pobj.hide();
					 $('#onlineStatueList').empty();
						if(_v!='Invisible')
						$('#onlineStatueList').append('<a onclick="state(\'invisible\',\'Invisible\',\''+_base_path+'user/status/'+uid+'/2\',\''+uid+'\')" class="invisible" name="'+uid+'" title="2" url="'+_base_path+'user/status/'+uid+'/2">Invisible</a>');
						if(_v!='Visible')
						$('#onlineStatueList').append('<a onclick="state(\'visible\',\'Visible\',\''+_base_path+'user/status/'+uid+'/1\',\''+uid+'\')" class="visible" name="'+uid+'" title="1" url="'+_base_path+'user/status/'+uid+'/1">Visible</a>');
						if(_v!='Invisible in Network')
						$('#onlineStatueList').append('<a onclick="state(\'visibleInNet\',\'Invisible in Network\',\''+_base_path+'user/status/'+uid+'/4\',\''+uid+'\')" class="visibleInNet" name="'+uid+'" title="4" url="'+_base_path+'user/status/'+uid+'/4">Invisible in Network</a>');
						if(_v!='Away')
						$('#onlineStatueList').append('<a onclick="state(\'alway\',\'Away\',\''+_base_path+'user/status/'+uid+'/5\',\''+uid+'\')" class="alway" name="'+uid+'" title="5" url="'+_base_path+'user/status/'+uid+'/5">Away</a>');
						if(_v!='Invisible outside Network')
						$('#onlineStatueList').append('<a onclick="state(\'visibleOutNet\',\'Invisible outside Network\',\''+_base_path+'user/status/'+uid+'/3\',\''+uid+'\')" class="visibleOutNet" name="'+uid+'" title="3" url="'+_base_path+'user/status/'+uid+'/3">Invisible outside Network</a>');						
				 }else{
					 alert('Change Status Error!');
				 }
			}
		});
		return false;
	});
	// delete message
	$('a.msgDel,.delete,.del a').click(function(){
		showDelDg('Delete',$(this).attr('href'));
		return false;
	});
//	 sideNav
	$('a.havaSubNav').sideNavSlide();
	$("input.error").focus(function(){$(this).removeClass('error');});
	//comment edit  
	$('.commEdit').commentEdit();
	
	//video player btn
	$(".play_btn").click(function(){
		$(this).parent().find("img").parent().click();
		$(this).hide();
	});
	
	//hide statue_messages
	setTimeout(function(){$("div.status").fadeOut();},5000);
});
function de_rank(obj){
	var _url = $(obj).attr('href');
	var _pj = $(obj).parent('li').prev('li');
	if(_url.slice(-1) == 2){
		_pj = _pj.prev('li');
	}
	$.ajax({
		type: "GET",
		url: _url,
		success: function(data){
			if(data == 0){
				alert("unrank error.");
			}else{
				_pj.nextAll('li').remove();
				_pj.after(data);
			}
		}
	});
}
//delete dialog
function showDelDg(tit,url){
	$("#dialog").dialog({
		bgiframe: true,
		autoOpen: false,
		width:360,
		modal: true,
		buttons: {
			Cancel: function(){
				$(this).dialog("close");
			},
			'Delete it': function(){
				 location.href = url;
			}
		},
		title: tit
	});
	$("#dialog").dialog("open");
}
/*------------stopBubble-------------*/
function stopDefault(e){
	if(e && e.preventDefault){
		e.preventDefault;
	}else{
		window.event.returnValue = false;
		return false;
	}
}
function stopBubble(e){
	if(e && e.stopPropagation){
		e.stopPropagation();	
	}else{
		window.event.cancelBubble = true;	
	}	
}
function parseJSON(data){
	if ((data.substring(0, 1) != '{') && (data.substring(0, 1) != '[')) {
	  return { status: 0, data: data.length ? data : 'Unspecified error' };
	}
	  return eval('(' + data + ');');
}
$.fn.sideNavSlide = function(){
	this.each(function(){
		$(this).click(function(){
			var _nobj = $(this).next('.sideSubNav');
			if(_nobj.is(':hidden')){
				_nobj.slideDown();
			}else{
				_nobj.slideUp();
			}
			return false;
		})
	});
};
/*
 * @autocomplete 
 */
$.fn.autocomplete = function(options){
	var defaults={
		url: _base_path+'autocomplete/mail/',
		chars: 1,
		width: 450,
		height: 150,
		top: null,
		left: null,
		time: 400,
		sroll: false
	};
	var ops = $.extend(defaults,options);
	var pop = $('<div id="autocomplete"></div>');
	var results = $('<ul id="results"></ul>');
	var doneUsers = {};
	var curPos;
	if(ops.top != null){pop.css('top',ops.top);}
	if(ops.left != null){pop.css('left',ops.left)}
	$(this).after(pop).parent().css('position','relative');
	pop.css({'width':ops.width+'px'}).hide().append(results);
	if(ops.sroll){
		pop.css({'height':ops.height+'px','overflow':'auto'});
	}
	function quest(q,elem){
		var w = $.trim(q.substr(q.lastIndexOf(',')+1,q.length));
		if(w.length >= ops.chars){
			curPos = null;
			$.ajax({
				type: 'GET',
				url: ops.url+w,
				cache: false,
				success: function(data){
					jdata = parseJSON(data);
					if(jdata.length > 0){
						loadDone(elem);
						var str = '';
						if(jdata.length > 10){
							results.css({overflow:'auto',height:'240px'});
						}else{
							results.css({overflow:'hidden',height:'auto'});
						}
						for(var j = 0; j < jdata.length;j++){
							if(! doneUsers[jdata[j]]){
								str += '<li>'+jdata[j]+'</li>';
							}
						}
						results.html(str);
						updataePos(results.children('li').eq(0))
						results.children('li').mouseover(function(){
							updataePos($(this));
						}).click(function(){
							addValue($(this).text(),elem);
						})
						if(results.children('li').size() > 0){
							pop.show();
						}else{
							pop.hide();
						}
					}else{
						pop.hide();
					}
				}
			});	
		}
	}
	$(document).click(function(){
		pop.hide();
	});
	pop.click(function(){stopBubble();});
	function loadDone(elem){
		doneUsers = {};
		var dones = elem.val().split(',');
		for(var i = 0; i < dones.length; i++){
			doneUsers[$.trim(dones[i])] = true;
		}
	}
	function updataePos(elem){
		curPos = elem;
		results.children('li').removeClass('popPos');
		curPos.addClass('popPos');
	}
	function addValue(v,elem){
		var defaultValue = elem.val();
		var tmp = '';
		if(defaultValue.indexOf(',') >= 0){
			tmp = defaultValue.substr(0,defaultValue.lastIndexOf(',')+1)+v;
		}else{
			tmp = v;
		}
		elem.val(tmp);
		results.html('');
		pop.hide();
	}
	return $(this).each(function(){
		$(this).attr('autocomplete','off');
		var outKey = [9,13,38,40];
		$(this).bind('keyup',function(e){
			var newVal = $(this).val();
			switch (e.keyCode) {
			    case 16: // shift
			    case 17: // ctrl
			    case 18: // alt
			    case 20: // caps lock
			    case 33: // page up
			    case 34: // page down
			    case 35: // end
			    case 36: // home
			    case 37: // left arrow
			    case 38: // up arrow
			    case 39: // right arrow
			    case 40: // down arrow
			      		return true;
			
			    case 9:  // tab
			    case 13: // enter
			    case 27: // esc
			     		 return true;
			    default: //all other keys
				    if(newVal.length >= ops.chars){
						quest(newVal,$(this));	
					}else{
						pop.hide();
					}
			}	
		}).bind('keydown',function(e){
			if(e.keyCode == 9 || e.keyCode == 13){
				if(curPos){
					loadDone($(this));
					var tv = curPos.text();
					if(!doneUsers[tv]){
						addValue(tv,$(this));	
					}
				}
				stopDefault(e);
				return false;
			}else if(e.keyCode == 38){
				if(curPos.prev().length > 0){
					return updataePos(curPos.prev());	
				}
				return false;
			}else if(e.keyCode == 40){
				if(curPos.next().length > 0){
					return updataePos(curPos.next());
				}
				return false;
			}
		});
	});
};
/*-----------------follow-----------------*/
$.fn.follow = function(){
	$("#editDialog").dialog({
		bgiframe: true,
		autoOpen: false,
		width:420,
		modal: true,
		title: 'Please wait...'
	});
	this.each(function(){
		$(this).click(function(){
			$("#editDgCt").html('<div class="loading"></div>');
			$("#editDialog").dialog('open');
			var _url = $(this).attr('href') + '/ajax';
			$.ajax({
				type: "GET",
				url: _url,
				cache: true,
				success: function(data){
					$('#editDgCt').html(data);
				}
			});
			return false;
		});
	});
}
/*-----------calendar--------------*/
$.fn.calendar = function(act){
	this.each(function(){
		$(this).click(function(){
			var _url = $(this).attr('href') + '/ajax';
			if(act){
				_url = _url + '/' + act;
			}
			$.ajax({
				type: "GET",
				url: _url,
				cache: true,
				success: function(data){
					$('#calendar_block').html(data);
				}
			});
			return false;
		});
	});
};
$.fn.calendarTask = function(options){
		var defaults={
			pobj: '#calendarTask',
			cobj: '#calendarTaskCt',
			close: '#calendarTaskClose',
			pobjHide: true
		};
		var ops = $.extend(defaults,options);
		var isHide = true;
		var _load = $('<div class="loading"></div>');
		function change(url){
			$.ajax({
				type: "GET",
				url: url,
				cache: true,
				success: function(data){
					$(ops.cobj).html(data);
				}
			});
		}
		this.each(function(){
			$(this).click(function(){
				var _url = $(this).attr('href');
				if(ops.pobjHide){
					var _pos = $(this).position();
					if(_pos.left>400) $(ops.pobj).css({top:_pos.top+18+'px',left:(_pos.left-200)+'px'});
					else $(ops.pobj).css({top:_pos.top+18+'px',left:_pos.left+18+'px'});
				}
				if(ops.pobjHide && isHide){
					$(ops.pobj).show();
					isHide = false;
				}else{
					$(ops.cobj).html(_load);
				}
				change(_url);
				return false;
			});
		});
		$(ops.close).click(function(){
			$(ops.cobj).html(_load);
			$(ops.pobj).hide();
			isHide = true;
		});
		$(document).click(function(){
			$(ops.cobj).html(_load);
			$(ops.pobj).hide();
			isHide = true;
		});
		$(ops.pobj).click(function(e){
			stopBubble(e);
		});
};
/*------------------------------------
	jQuery cookie
@options like { expires: 7, path: '/', domain: 'jquery.com', secure: true }
---------------------------------*/
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { 
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); 
        }
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else {
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
/*------------------------------------
 	Comment;
----------------------------------------*/
function showAllComment(obj){
	var _url = $(obj).attr('href');
	var _ot = $(obj).parents('ul').next('div.feed_comment');
	 $.ajax({
		type: 'POST',
		url: _url,
		success: function(data){
			$(_ot).html(data);
		}
	});
}
function delFeedComment(obj,pos){
	var _url = $(obj).attr('href');
	var _remove = $(obj).parents('div.feed_comment_list');
	var _cout = $('#c_'+pos);
	var _nc = _cout.text();
	$.ajax({
		type: "GET",
		url: _url,
		success: function(dat){
			if(dat == 1){
				$(_remove).remove();
				--_nc;
				_cout.text(_nc);
			}else{
				alert('Delete failed.')
			}
		},
		error: function(XMLHttpRequest, textStatus, errorThrown){
			alert(errorThrown);
		}
	});
}
(function($){
	$.fn.newcomment = function(obj){
		var _submit = $('<button class="fsubmit">Comment</button>');
		var _url = '';
		var _pobj = null;
		this.each(function(){
			$(this).focus(function(){
				var pos = $('#c_'+$(this).attr('rel'));
				var count = pos.text();
				_url = $(this).prev('input.form-text').val();
				if(_pobj !== null){
					_pobj.css('height','19px').val('');
				}
				$(this).css('height','38px').after(_submit);
				_pobj = $(this);
				$(this).next('button').click(function(event){
					stopBubble(event);
					var _val = $(this).prev('input').val();
					var _this = $(this);
					if(_val.length > 0){
						 $.ajax({
							type: 'POST',
							url: _url,
							data: 'comment=' + _val,
							success: function(data){
								if(data == 0){
									alert('Content can not be empty!');
								}else if(data == 1){
									alert('Content is too long!');
								}else if(data == -1){
									alert('Operation failed!');
								}else{
									$(_this).prev('input').css('height','19px').val('');
									$(_this).remove();
									$(_pobj).parents('div.feed_comment_new').prev('div.feed_comment').html(data);
									++count;
									pos.text(count);
								}
							},
							error: function(XMLHttpRequest, textStatus, errorThrown){
								alert(errorThrown);
							}
						});
					}else{
						return false;
					}
				});
			}).click(function(e){
				stopBubble(e);
				return false;
			});
			$(document).click(function(){
				_submit.prev('input').css('height','19px').val('');
				_submit.remove();
			})
		});
	};
	// comment edit by ajax
	$.fn.commentEdit = function(eleobj){
		var _cform = $('<div id="editCommForm"><textarea class="form-textarea" id="fcommFct"></textarea><button id="fcommButton" class="fsubmit" style="margin:5px;">Comment</button></div>');
		this.each(function(){
			$(this).click(function(){
				var _url = $(this).attr('href');
				
				if(typeof eleobj != 'undefined'){
					var _target = $(this).prev(eleobj);
				}else{
					var _target = $(this).prev('ul').children('li.commentCt');
				}
				var _this = this;
				$(this).after(_cform);
				$(this).hide();
				_target.hide();
				$('#fcommFct').val(_target.html());
				$('#fcommButton').click(function(){
					var _value = $('#fcommFct').val();
					if(_value.length > 0 && _value.length < 300){
						$.ajax({
							type: 'POST',
							url: _url,
							data: 'comment=' + _value,
							success: function(data){
								if(data == 0){
									alert('Content can not be empty!');
								}else if(data == 1){
									alert('Content is too long!');
								}else if(data == -1){
									alert('Operation failed!');
								}else{
									_target.html(_value).show();
									$(_this).show();
									_cform.remove();
								}
							}
						});
					}else{
						alert('Content length must be within the 0-300.');
					}
				});
				_cform.click(function(e){
					stopBubble(e);
				});
				$(document).click(function(){
					_cform.remove();
					_target.show();
					$(_this).show();
				});
				return false;
			});
		});
	};
	//image view
	$.fn.imgView = function(options){
		var defaults = {
				pos: 'center',
				ajax: false
			};
		var ops = $.extend(defaults,options);
		var imgBox = $('<div id="imgbox"><div id="imgBox_wrap"></div></div>');
		var _close = $('<div id="imgboxClose"><a href="#close">Close</a></a>');
		var _isIn = false;
		function getPageScroll(){
			var yScroll;
			if (self.pageYOffset) {
				yScroll = self.pageYOffset;
			} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
				yScroll = document.documentElement.scrollTop;
			} else if (document.body) {// all other Explorers
				yScroll = document.body.scrollTop;
			}
			return yScroll;
		}
		function posCent(elem){
			var _bw = $('body').width();
			var _bh = $('body').height();
			var _tw = $(elem).width();
			var _th = $(elem).height();
			var _yscroll =  getPageScroll();
			var _top = parseInt((_bh - _th ) / 2) + _yscroll - 30;
			var _left = parseInt((_bw - _tw) / 2);
			if(_top < 0){ _top = 0;}
			if(_left < 0){_left = 0;}
			var arrayPos = new Array(_top,_left);
			return arrayPos;
		}
		/*-------------------------------
	 	check Img loader
	 -------------------------------*/
		function addListener(element, type, expression, bubbling)
		{
		  bubbling = bubbling || false;
		  if(window.addEventListener)	{ // Standard
		    element.addEventListener(type, expression, bubbling);
		    return true;
		  } else if(window.attachEvent) { // IE
		    element.attachEvent('on' + type, expression);
		    return true;
		  } else return false;
		}
		var ImageLoader = function(url){
		  this.url = url;
		  this.image = null;
		  this.loadEvent = null;
		};
		ImageLoader.prototype = {
		  load:function(){
		    this.image = document.createElement('img');
		    var url = this.url;
		    var image = this.image;
		    var loadEvent = this.loadEvent;
		    addListener(this.image, 'load', function(e){
		      if(loadEvent != null){
		        loadEvent(url, image);
		      }
		    }, false);
		    this.image.src = this.url;
		  },
		  getImage:function(){
		    return this.image;
		  }
		};
		this.each(function(e){
			$(this).click(function(event){
				stopBubble(event);
				var _src = $(this).attr('href');
				if(_isIn){
					return false;
				}else{
					$('body').append(imgBox);
				}
				imgBox.click(function(e){stopBubble(e);});
				var loader = new ImageLoader($(this).attr('href'));
				loader.loadEvent = function(url,_img){
					var w = _img.width;
					var h = _img.height;
					imgBox.css({width:w+'px',height:h+30+'px'});
					$('#imgBox_wrap').html(_img).after(_close);
					_isIn = true;
					var _arrayPos = posCent(imgBox);
					imgBox.css({top:_arrayPos[0]+'px',left:_arrayPos[1]+'px'});
				};
				loader.load();
				$(_close).click(function(){
					imgBox.remove();
					_isIn = false;
				});
				$(imgBox).click(function(){
					$(this).remove();
					_isIn = false;
				});
				return false;
			});
		});
	};
})(jQuery);
function getToday(){
	var _td = new Date();
	var _d = _td.getDate();
	var _m = _td.getMonth();
	var _y = _td.getFullYear();
	switch(_m){
		case 0: _m = 'January';
		break;
		case 1: _m = 'February';
		break;
		case 2: _m = 'March';
		break;
		case 3: _m = 'April';
		break;
		case 4: _m = 'May';
		break;
		case 5: _m = 'June';
		break;
		case 6: _m = 'July';
		break;
		case 7: _m = 'Aguest';
		break;
		case 8: _m = 'September';
		break;
		case 9: _m = 'October';
		break;
		case 10: _m = 'November';
		break;
		default: _m = 'December';
	}
	return (_m + ' ' + _d + ', ' + _y);
}
/*----------------------------
 * get updates by ajax
 ------------------------------*/
function user_updates(uid,tp){
	var _url = _base_path+'user/updates/'+uid+'/'+tp;
	var _load = '<div class="loading"></div>';
	$('#updates_ajax_cont').html(_load);
	$.ajax({
		type: "GET",
		url: _url,
		dataType: 'html',
		success: function(data){
			$('#updates_ajax_cont').html(data);
		}
	});
}
function group_updates(gid,tp){
	var _url = _base_path+'group/updates/'+gid+'/'+tp;
	var _load = '<div class="loading"></div>';
	$('#updates_ajax_cont').html(_load);
	$.ajax({
		type: "GET",
		url: _url,
		dataType: 'html',
		success: function(data){
			$('#updates_ajax_cont').html(data);
		}
	});
}
function loadYoutube(id,w,h){
	//alert(id.href);
	var _url = _base_path+'user/welcome/loadYoutube';
	var _load = '<div class="loading"></div>';
	$(id).html(_load);
	$.ajax({
		type: "POST",
		url: _url,
		data:{u:id.href,w:w,h:h},
		dataType: 'html',
		success: function(data){
			$(id).parent().html(data);
		}
	});
	return false;
}

function webcam_invite_add_member(id) {
    $(id).change(function() {
        if ($(this).val() > 0) {
            var selected = $(id + " option:selected");
            var members = $("#edit-members");
            if (members.val().indexOf(selected.text() + ",") == -1) {
                members.val(members.val() + selected.text() + ",");
            }
            selected.remove();
            $(this).val(0);
        }
    });
}

function webcam_invite_bind_form(base_url) {
    webcam_invite_add_member("#edit-contacts");
    webcam_invite_add_member("#edit-groupmembers");

    $("#edit-groups").change(function() {
        if ($(this).val() > 0) {
            var url = base_url + "webcam/invite/ajax/groupmembers/" + $(this).val();
            var selected = $("#edit-groups option:selected");
            $.getJSON(url, function(json) {
                $("#edit-groupmembers > option").each(function(index, old_option) {
                    if ($(old_option).val() > 0) $(old_option).remove();
                });

                $.each(json, function(index, element) {
                    var new_option = $("<option>");
                    new_option.val(index);
                    new_option.text(element);
                    $("#edit-groupmembers").append(new_option);
                });
            });
        }
    });
}


