_share_tree_load=false;

function show_shares() {
  // $('#list_shares_block').toggle();
  if ($('#list_shares_block').is(':visible')) {
    if (!_share_tree_load) {
      $('#list_shares_tree').load("/get_invite_list", {}, function(data) {
          $('#list_shares_tree').html(data);
          $('#list_shares_tree_ul').treeview();
          _share_tree_load=true;
        });
    }
  }
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

$().ready(function() {
    $('.widget_close_arrow').click(function() {
        id=this.id;
        id=id.substr(0,id.length-12);
        $('#'+id+'_close_arrow').hide();
        $('#'+id+'_open_arrow').show();
        $('#'+id+'_content').slideDown();
        if (id=='sharing_circle_widget') {
          // call show_shares
          show_shares();
        }
      });
    $('.widget_open_arrow').click(function() {
        id=this.id;
        id=id.substr(0,id.length-11);
        $('#'+id+'_close_arrow').show();
        $('#'+id+'_open_arrow').hide();
        $('#'+id+'_content').slideUp();
      });
});
